Skip to content

Commit a52b7c6

Browse files
committed
Another MIR test for inlining drops
1 parent 997fe7d commit a52b7c6

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
- // MIR for `half_needs_drop` before Inline
2+
+ // MIR for `half_needs_drop` after Inline
3+
4+
fn half_needs_drop(_1: String) -> () {
5+
debug s => _1;
6+
let mut _0: ();
7+
let _2: Pair<bool, std::string::String>;
8+
let mut _3: std::string::String;
9+
+ let mut _4: *mut Pair<bool, std::string::String>;
10+
+ let mut _5: ();
11+
scope 1 {
12+
debug _x => _2;
13+
}
14+
+ scope 2 (inlined drop_in_place::<Pair<bool, String>> - shim(Some(Pair<bool, String>))) {
15+
+ }
16+
17+
bb0: {
18+
StorageLive(_2);
19+
StorageLive(_3);
20+
_3 = move _1;
21+
_2 = Pair::<bool, String>(const true, move _3);
22+
StorageDead(_3);
23+
_0 = const ();
24+
- drop(_2) -> [return: bb1, unwind unreachable];
25+
+ _4 = &raw mut _2;
26+
+ drop(((*_4).1: std::string::String)) -> [return: bb1, unwind unreachable];
27+
}
28+
29+
bb1: {
30+
StorageDead(_2);
31+
return;
32+
}
33+
}
34+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
- // MIR for `half_needs_drop` before Inline
2+
+ // MIR for `half_needs_drop` after Inline
3+
4+
fn half_needs_drop(_1: String) -> () {
5+
debug s => _1;
6+
let mut _0: ();
7+
let _2: Pair<bool, std::string::String>;
8+
let mut _3: std::string::String;
9+
+ let mut _4: *mut Pair<bool, std::string::String>;
10+
+ let mut _5: ();
11+
scope 1 {
12+
debug _x => _2;
13+
}
14+
+ scope 2 (inlined drop_in_place::<Pair<bool, String>> - shim(Some(Pair<bool, String>))) {
15+
+ }
16+
17+
bb0: {
18+
StorageLive(_2);
19+
StorageLive(_3);
20+
_3 = move _1;
21+
_2 = Pair::<bool, String>(const true, move _3);
22+
StorageDead(_3);
23+
_0 = const ();
24+
- drop(_2) -> [return: bb1, unwind: bb2];
25+
+ _4 = &raw mut _2;
26+
+ drop(((*_4).1: std::string::String)) -> [return: bb2, unwind: bb1];
27+
}
28+
29+
- bb1: {
30+
- StorageDead(_2);
31+
- return;
32+
+ bb1 (cleanup): {
33+
+ resume;
34+
}
35+
36+
- bb2 (cleanup): {
37+
- resume;
38+
+ bb2: {
39+
+ StorageDead(_2);
40+
+ return;
41+
}
42+
}
43+

tests/mir-opt/inline/inline_drops.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
2+
#![crate_type = "lib"]
3+
4+
struct Pair<T, U>(T, U);
5+
6+
// EMIT_MIR inline_drops.half_needs_drop.Inline.diff
7+
pub fn half_needs_drop(s: String) {
8+
// CHECK-LABEL: fn half_needs_drop(_1: String)
9+
// CHECK: inlined drop_in_place::<Pair<bool, String>>
10+
// CHECK: _2 = Pair::<bool, String>({{.+}})
11+
// CHECK-NOT: drop
12+
// CHECK: drop((_2.1: std::string::String))
13+
// CHECK-NOT: drop
14+
let _x = Pair(true, s);
15+
}

0 commit comments

Comments
 (0)