Skip to content

Commit 608d306

Browse files
committed
Fortify test.
1 parent 0c0f27a commit 608d306

8 files changed

+873
-28
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
- // MIR for `move_from_inner` before ElaborateDrops
2+
+ // MIR for `move_from_inner` after ElaborateDrops
3+
4+
fn move_from_inner() -> () {
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: S;
13+
+ let mut _8: &mut std::boxed::Box<S>;
14+
+ let mut _9: ();
15+
+ let mut _10: &mut std::boxed::Box<S>;
16+
+ let mut _11: ();
17+
+ let mut _12: *const S;
18+
+ let mut _13: &mut std::boxed::Box<S>;
19+
+ let mut _14: ();
20+
+ let mut _15: *const S;
21+
+ let mut _16: &mut std::boxed::Box<S>;
22+
+ let mut _17: ();
23+
+ let mut _18: *const S;
24+
scope 1 {
25+
debug x => _1;
26+
}
27+
28+
bb0: {
29+
StorageLive(_1);
30+
_2 = SizeOf(S);
31+
_3 = AlignOf(S);
32+
_4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue];
33+
}
34+
35+
bb1: {
36+
StorageLive(_5);
37+
_5 = ShallowInitBox(move _4, S);
38+
(*_5) = S::new() -> [return: bb2, unwind: bb8];
39+
}
40+
41+
bb2: {
42+
_1 = move _5;
43+
- drop(_5) -> [return: bb3, unwind continue];
44+
+ goto -> bb3;
45+
}
46+
47+
bb3: {
48+
StorageDead(_5);
49+
StorageLive(_6);
50+
StorageLive(_7);
51+
_7 = move (*_1);
52+
_6 = std::mem::drop::<S>(move _7) -> [return: bb4, unwind: bb6];
53+
}
54+
55+
bb4: {
56+
StorageDead(_7);
57+
StorageDead(_6);
58+
_0 = const ();
59+
- drop(_1) -> [return: bb5, unwind continue];
60+
+ goto -> bb14;
61+
}
62+
63+
bb5: {
64+
StorageDead(_1);
65+
return;
66+
}
67+
68+
bb6 (cleanup): {
69+
- drop(_7) -> [return: bb7, unwind terminate(cleanup)];
70+
+ goto -> bb7;
71+
}
72+
73+
bb7 (cleanup): {
74+
- drop(_1) -> [return: bb9, unwind terminate(cleanup)];
75+
+ goto -> bb17;
76+
}
77+
78+
bb8 (cleanup): {
79+
- drop(_5) -> [return: bb9, unwind terminate(cleanup)];
80+
+ goto -> bb20;
81+
}
82+
83+
bb9 (cleanup): {
84+
resume;
85+
+ }
86+
+
87+
+ bb10: {
88+
+ goto -> bb5;
89+
+ }
90+
+
91+
+ bb11: {
92+
+ _8 = &mut _1;
93+
+ _9 = <Box<S> as Drop>::drop(move _8) -> [return: bb10, unwind: bb9];
94+
+ }
95+
+
96+
+ bb12 (cleanup): {
97+
+ _10 = &mut _1;
98+
+ _11 = <Box<S> as Drop>::drop(move _10) -> [return: bb9, unwind terminate(cleanup)];
99+
+ }
100+
+
101+
+ bb13: {
102+
+ goto -> bb11;
103+
+ }
104+
+
105+
+ bb14: {
106+
+ _12 = copy ((_1.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
107+
+ goto -> bb13;
108+
+ }
109+
+
110+
+ bb15 (cleanup): {
111+
+ _13 = &mut _1;
112+
+ _14 = <Box<S> as Drop>::drop(move _13) -> [return: bb9, unwind terminate(cleanup)];
113+
+ }
114+
+
115+
+ bb16 (cleanup): {
116+
+ goto -> bb15;
117+
+ }
118+
+
119+
+ bb17 (cleanup): {
120+
+ _15 = copy ((_1.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
121+
+ goto -> bb16;
122+
+ }
123+
+
124+
+ bb18 (cleanup): {
125+
+ _16 = &mut _5;
126+
+ _17 = <Box<S> as Drop>::drop(move _16) -> [return: bb9, unwind terminate(cleanup)];
127+
+ }
128+
+
129+
+ bb19 (cleanup): {
130+
+ goto -> bb18;
131+
+ }
132+
+
133+
+ bb20 (cleanup): {
134+
+ _18 = copy ((_5.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
135+
+ goto -> bb19;
136+
}
137+
}
138+

tests/mir-opt/box_expr.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33

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

6+
// EMIT_MIR box_expr.move_from_inner.ElaborateDrops.diff
7+
fn move_from_inner() {
8+
// CHECK-LABEL: fn move_from_inner(
9+
// CHECK: debug x => [[x:_.*]];
10+
// CHECK: [[box:_.*]] = ShallowInitBox(
11+
// CHECK: [[ptr:_.*]] = copy (([[box]].0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
12+
// CHECK: (*[[ptr]]) = S::new() -> [return: [[ret:bb.*]], unwind: [[unwind:bb.*]]];
13+
// CHECK: [[ret]]: {
14+
// CHECK: [[x]] = move [[box]];
15+
// CHECK: [[ptr:_.*]] = copy (([[x]].0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
16+
// CHECK: [[inner:_.*]] = move (*[[ptr]]);
17+
// CHECK: std::mem::drop::<S>(move [[inner]]) -> [return: [[ret2:bb.*]], unwind: [[unwind2:bb.*]]];
18+
// CHECK: [[ret2]]: {
19+
// CHECK: [[boxptr:_.*]] = &mut [[x]];
20+
// CHECK: <Box<S> as Drop>::drop(move [[boxptr]]) -> [return: [[ret3:bb.*]], unwind: [[unwind3:bb.*]]];
21+
// CHECK: [[unwind2]] (cleanup): {
22+
// CHECK: [[boxptr3:_.*]] = &mut [[x]];
23+
// CHECK: <Box<S> as Drop>::drop(move [[boxptr3]])
24+
// CHECK: [[unwind3]] (cleanup): {
25+
// CHECK: resume;
26+
// CHECK: [[unwind]] (cleanup): {
27+
// CHECK: [[boxptr2:_.*]] = &mut [[box]];
28+
// CHECK: <Box<S> as Drop>::drop(move [[boxptr2]])
29+
30+
let x = std::boxed::box_new(S::new());
31+
drop(*x);
32+
}
33+
634
// EMIT_MIR box_expr.main.ElaborateDrops.diff
735
fn main() {
836
// CHECK-LABEL: fn main(
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
- // MIR for `move_out_by_subslice` before ElaborateDrops
2+
+ // MIR for `move_out_by_subslice` after ElaborateDrops
3+
4+
fn move_out_by_subslice() -> () {
5+
let mut _0: ();
6+
let _1: [std::boxed::Box<i32>; 3];
7+
let mut _2: std::boxed::Box<i32>;
8+
let mut _3: usize;
9+
let mut _4: usize;
10+
let mut _5: *mut u8;
11+
let mut _6: std::boxed::Box<i32>;
12+
let mut _7: std::boxed::Box<i32>;
13+
let mut _8: usize;
14+
let mut _9: usize;
15+
let mut _10: *mut u8;
16+
let mut _11: std::boxed::Box<i32>;
17+
let mut _12: std::boxed::Box<i32>;
18+
let mut _13: usize;
19+
let mut _14: usize;
20+
let mut _15: *mut u8;
21+
let mut _16: std::boxed::Box<i32>;
22+
scope 1 {
23+
debug a => _1;
24+
let _17: [std::boxed::Box<i32>; 2];
25+
scope 2 {
26+
debug _y => _17;
27+
}
28+
}
29+
30+
bb0: {
31+
StorageLive(_1);
32+
StorageLive(_2);
33+
_3 = SizeOf(i32);
34+
_4 = AlignOf(i32);
35+
_5 = alloc::alloc::exchange_malloc(move _3, move _4) -> [return: bb1, unwind continue];
36+
}
37+
38+
bb1: {
39+
StorageLive(_6);
40+
_6 = ShallowInitBox(move _5, i32);
41+
(*_6) = const 1_i32;
42+
_2 = move _6;
43+
- drop(_6) -> [return: bb2, unwind: bb15];
44+
+ goto -> bb2;
45+
}
46+
47+
bb2: {
48+
StorageDead(_6);
49+
StorageLive(_7);
50+
_8 = SizeOf(i32);
51+
_9 = AlignOf(i32);
52+
_10 = alloc::alloc::exchange_malloc(move _8, move _9) -> [return: bb3, unwind: bb15];
53+
}
54+
55+
bb3: {
56+
StorageLive(_11);
57+
_11 = ShallowInitBox(move _10, i32);
58+
(*_11) = const 2_i32;
59+
_7 = move _11;
60+
- drop(_11) -> [return: bb4, unwind: bb14];
61+
+ goto -> bb4;
62+
}
63+
64+
bb4: {
65+
StorageDead(_11);
66+
StorageLive(_12);
67+
_13 = SizeOf(i32);
68+
_14 = AlignOf(i32);
69+
_15 = alloc::alloc::exchange_malloc(move _13, move _14) -> [return: bb5, unwind: bb14];
70+
}
71+
72+
bb5: {
73+
StorageLive(_16);
74+
_16 = ShallowInitBox(move _15, i32);
75+
(*_16) = const 3_i32;
76+
_12 = move _16;
77+
- drop(_16) -> [return: bb6, unwind: bb13];
78+
+ goto -> bb6;
79+
}
80+
81+
bb6: {
82+
StorageDead(_16);
83+
_1 = [move _2, move _7, move _12];
84+
- drop(_12) -> [return: bb7, unwind: bb14];
85+
+ goto -> bb7;
86+
}
87+
88+
bb7: {
89+
StorageDead(_12);
90+
- drop(_7) -> [return: bb8, unwind: bb15];
91+
+ goto -> bb8;
92+
}
93+
94+
bb8: {
95+
StorageDead(_7);
96+
- drop(_2) -> [return: bb9, unwind continue];
97+
+ goto -> bb9;
98+
}
99+
100+
bb9: {
101+
StorageDead(_2);
102+
PlaceMention(_1);
103+
StorageLive(_17);
104+
_17 = move _1[0..2];
105+
_0 = const ();
106+
drop(_17) -> [return: bb10, unwind: bb12];
107+
}
108+
109+
bb10: {
110+
StorageDead(_17);
111+
- drop(_1) -> [return: bb11, unwind continue];
112+
+ goto -> bb23;
113+
}
114+
115+
bb11: {
116+
StorageDead(_1);
117+
return;
118+
}
119+
120+
bb12 (cleanup): {
121+
- drop(_1) -> [return: bb16, unwind terminate(cleanup)];
122+
+ goto -> bb26;
123+
}
124+
125+
bb13 (cleanup): {
126+
- drop(_12) -> [return: bb14, unwind terminate(cleanup)];
127+
+ goto -> bb14;
128+
}
129+
130+
bb14 (cleanup): {
131+
drop(_7) -> [return: bb15, unwind terminate(cleanup)];
132+
}
133+
134+
bb15 (cleanup): {
135+
drop(_2) -> [return: bb16, unwind terminate(cleanup)];
136+
}
137+
138+
bb16 (cleanup): {
139+
resume;
140+
+ }
141+
+
142+
+ bb17: {
143+
+ goto -> bb11;
144+
+ }
145+
+
146+
+ bb18 (cleanup): {
147+
+ goto -> bb16;
148+
+ }
149+
+
150+
+ bb19 (cleanup): {
151+
+ goto -> bb18;
152+
+ }
153+
+
154+
+ bb20 (cleanup): {
155+
+ drop(_1[2..3]) -> [return: bb19, unwind terminate(cleanup)];
156+
+ }
157+
+
158+
+ bb21: {
159+
+ goto -> bb17;
160+
+ }
161+
+
162+
+ bb22: {
163+
+ goto -> bb21;
164+
+ }
165+
+
166+
+ bb23: {
167+
+ drop(_1[2..3]) -> [return: bb22, unwind: bb19];
168+
+ }
169+
+
170+
+ bb24 (cleanup): {
171+
+ goto -> bb16;
172+
+ }
173+
+
174+
+ bb25 (cleanup): {
175+
+ goto -> bb24;
176+
+ }
177+
+
178+
+ bb26 (cleanup): {
179+
+ drop(_1[2..3]) -> [return: bb25, unwind terminate(cleanup)];
180+
}
181+
}
182+

0 commit comments

Comments
 (0)