Skip to content

Commit 38bf660

Browse files
committed
FileCheck box_expr.rs
This check is made `needs-unwind`, as the panic=abort case is a strictly simpler version.
1 parent f65eb1f commit 38bf660

File tree

4 files changed

+104
-145
lines changed

4 files changed

+104
-145
lines changed

tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir

Lines changed: 0 additions & 71 deletions
This file was deleted.

tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
- // MIR for `main` before ElaborateDrops
2+
+ // MIR for `main` after ElaborateDrops
3+
4+
fn main() -> () {
5+
let mut _0: ();
6+
let _1: std::boxed::Box<S>;
7+
let mut _2: usize;
8+
let mut _3: usize;
9+
let mut _4: *mut u8;
10+
let mut _5: std::boxed::Box<S>;
11+
let _6: ();
12+
let mut _7: std::boxed::Box<S>;
13+
+ let mut _8: &mut std::boxed::Box<S>;
14+
+ let mut _9: ();
15+
scope 1 {
16+
debug x => _1;
17+
}
18+
scope 2 {
19+
}
20+
21+
bb0: {
22+
StorageLive(_1);
23+
_2 = SizeOf(S);
24+
_3 = AlignOf(S);
25+
_4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue];
26+
}
27+
28+
bb1: {
29+
StorageLive(_5);
30+
_5 = ShallowInitBox(move _4, S);
31+
(*_5) = S::new() -> [return: bb2, unwind: bb8];
32+
}
33+
34+
bb2: {
35+
_1 = move _5;
36+
- drop(_5) -> [return: bb3, unwind continue];
37+
+ goto -> bb3;
38+
}
39+
40+
bb3: {
41+
StorageDead(_5);
42+
StorageLive(_6);
43+
StorageLive(_7);
44+
_7 = move _1;
45+
_6 = std::mem::drop::<Box<S>>(move _7) -> [return: bb4, unwind: bb6];
46+
}
47+
48+
bb4: {
49+
StorageDead(_7);
50+
StorageDead(_6);
51+
_0 = const ();
52+
- drop(_1) -> [return: bb5, unwind continue];
53+
+ goto -> bb5;
54+
}
55+
56+
bb5: {
57+
StorageDead(_1);
58+
return;
59+
}
60+
61+
bb6 (cleanup): {
62+
- drop(_7) -> [return: bb7, unwind terminate(cleanup)];
63+
+ goto -> bb7;
64+
}
65+
66+
bb7 (cleanup): {
67+
- drop(_1) -> [return: bb9, unwind terminate(cleanup)];
68+
+ goto -> bb9;
69+
}
70+
71+
bb8 (cleanup): {
72+
- drop(_5) -> [return: bb9, unwind terminate(cleanup)];
73+
+ goto -> bb11;
74+
}
75+
76+
bb9 (cleanup): {
77+
resume;
78+
+ }
79+
+
80+
+ bb10 (cleanup): {
81+
+ _8 = &mut _5;
82+
+ _9 = <Box<S> as Drop>::drop(move _8) -> [return: bb9, unwind terminate(cleanup)];
83+
+ }
84+
+
85+
+ bb11 (cleanup): {
86+
+ goto -> bb10;
87+
}
88+
}
89+

tests/mir-opt/box_expr.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
// skip-filecheck
2-
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
1+
// unit-test: ElaborateDrops
2+
// needs-unwind
33

44
#![feature(rustc_attrs, stmt_expr_attributes)]
55

6-
// EMIT_MIR box_expr.main.ElaborateDrops.before.mir
6+
// EMIT_MIR box_expr.main.ElaborateDrops.diff
77
fn main() {
8+
// CHECK-LABEL: fn main(
9+
// CHECK: [[box:_.*]] = ShallowInitBox(
10+
// CHECK: [[ptr:_.*]] = ((([[box]].0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>).0: *const S);
11+
// CHECK: (*[[ptr]]) = S::new() -> [return: [[ret:bb.*]], unwind: [[unwind:bb.*]]];
12+
// CHECK: [[ret]]: {
13+
// CHECK: [[box2:_.*]] = move [[box]];
14+
// CHECK: [[box3:_.*]] = move [[box2]];
15+
// CHECK: std::mem::drop::<Box<S>>(move [[box3]])
16+
// CHECK: [[unwind]] (cleanup): {
17+
// CHECK: [[boxref:_.*]] = &mut [[box]];
18+
// CHECK: <Box<S> as Drop>::drop(move [[boxref]])
19+
820
let x = #[rustc_box]
921
Box::new(S::new());
1022
drop(x);

0 commit comments

Comments
 (0)