Skip to content

Commit 8acf40b

Browse files
committed
Auto merge of #117469 - cjgillot:filecheck-mir, r=Mark-Simulacrum
Add FileCheck annotations to a few MIR opt tests const_debuginfo did not specify which passes were running. const_prop_miscompile is renamed and moved to const_prop directory. while_storage was broken.
2 parents da1e0d1 + ac4d096 commit 8acf40b

12 files changed

+307
-119
lines changed
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
2+
// Test that we correctly generate StorageDead statements for while loop
3+
// conditions on all branches
4+
// compile-flags: -Zmir-opt-level=0
5+
6+
fn get_bool(c: bool) -> bool {
7+
c
8+
}
9+
10+
// EMIT_MIR while_storage.while_loop.PreCodegen.after.mir
11+
fn while_loop(c: bool) {
12+
// CHECK-LABEL: fn while_loop(
13+
// CHECK: bb0: {
14+
// CHECK-NEXT: goto -> bb1;
15+
// CHECK: bb1: {
16+
// CHECK-NEXT: StorageLive(_3);
17+
// CHECK-NEXT: StorageLive(_2);
18+
// CHECK-NEXT: _2 = _1;
19+
// CHECK-NEXT: _3 = get_bool(move _2) -> [return: bb2, unwind
20+
// CHECK: bb2: {
21+
// CHECK-NEXT: switchInt(move _3) -> [0: bb3, otherwise: bb4];
22+
// CHECK: bb3: {
23+
// CHECK-NEXT: StorageDead(_2);
24+
// CHECK-NEXT: StorageLive(_9);
25+
// CHECK-NEXT: _0 = const ();
26+
// CHECK-NEXT: StorageDead(_9);
27+
// CHECK-NEXT: goto -> bb8;
28+
// CHECK: bb4: {
29+
// CHECK-NEXT: StorageDead(_2);
30+
// CHECK-NEXT: StorageLive(_5);
31+
// CHECK-NEXT: StorageLive(_4);
32+
// CHECK-NEXT: _4 = _1;
33+
// CHECK-NEXT: _5 = get_bool(move _4) -> [return: bb5, unwind
34+
// CHECK: bb5: {
35+
// CHECK-NEXT: switchInt(move _5) -> [0: bb6, otherwise: bb7];
36+
// CHECK: bb6: {
37+
// CHECK-NEXT: StorageDead(_4);
38+
// CHECK-NEXT: _6 = const ();
39+
// CHECK-NEXT: StorageDead(_5);
40+
// CHECK-NEXT: StorageDead(_3);
41+
// CHECK-NEXT: goto -> bb1;
42+
// CHECK: bb7: {
43+
// CHECK-NEXT: StorageDead(_4);
44+
// CHECK-NEXT: _0 = const ();
45+
// CHECK-NEXT: StorageDead(_5);
46+
// CHECK-NEXT: goto -> bb8;
47+
// CHECK: bb8: {
48+
// CHECK-NEXT: StorageDead(_3);
49+
// CHECK-NEXT: return;
50+
51+
while get_bool(c) {
52+
if get_bool(c) {
53+
break;
54+
}
55+
}
56+
}
57+
58+
fn main() {
59+
while_loop(false);
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// MIR for `while_loop` after PreCodegen
2+
3+
fn while_loop(_1: bool) -> () {
4+
debug c => _1;
5+
let mut _0: ();
6+
let mut _2: bool;
7+
let mut _3: bool;
8+
let mut _4: bool;
9+
let mut _5: bool;
10+
let mut _6: ();
11+
let mut _7: !;
12+
let mut _8: !;
13+
let _9: ();
14+
let mut _10: !;
15+
16+
bb0: {
17+
goto -> bb1;
18+
}
19+
20+
bb1: {
21+
StorageLive(_3);
22+
StorageLive(_2);
23+
_2 = _1;
24+
_3 = get_bool(move _2) -> [return: bb2, unwind unreachable];
25+
}
26+
27+
bb2: {
28+
switchInt(move _3) -> [0: bb3, otherwise: bb4];
29+
}
30+
31+
bb3: {
32+
StorageDead(_2);
33+
StorageLive(_9);
34+
_0 = const ();
35+
StorageDead(_9);
36+
goto -> bb8;
37+
}
38+
39+
bb4: {
40+
StorageDead(_2);
41+
StorageLive(_5);
42+
StorageLive(_4);
43+
_4 = _1;
44+
_5 = get_bool(move _4) -> [return: bb5, unwind unreachable];
45+
}
46+
47+
bb5: {
48+
switchInt(move _5) -> [0: bb6, otherwise: bb7];
49+
}
50+
51+
bb6: {
52+
StorageDead(_4);
53+
_6 = const ();
54+
StorageDead(_5);
55+
StorageDead(_3);
56+
goto -> bb1;
57+
}
58+
59+
bb7: {
60+
StorageDead(_4);
61+
_0 = const ();
62+
StorageDead(_5);
63+
goto -> bb8;
64+
}
65+
66+
bb8: {
67+
StorageDead(_3);
68+
return;
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// MIR for `while_loop` after PreCodegen
2+
3+
fn while_loop(_1: bool) -> () {
4+
debug c => _1;
5+
let mut _0: ();
6+
let mut _2: bool;
7+
let mut _3: bool;
8+
let mut _4: bool;
9+
let mut _5: bool;
10+
let mut _6: ();
11+
let mut _7: !;
12+
let mut _8: !;
13+
let _9: ();
14+
let mut _10: !;
15+
16+
bb0: {
17+
goto -> bb1;
18+
}
19+
20+
bb1: {
21+
StorageLive(_3);
22+
StorageLive(_2);
23+
_2 = _1;
24+
_3 = get_bool(move _2) -> [return: bb2, unwind continue];
25+
}
26+
27+
bb2: {
28+
switchInt(move _3) -> [0: bb3, otherwise: bb4];
29+
}
30+
31+
bb3: {
32+
StorageDead(_2);
33+
StorageLive(_9);
34+
_0 = const ();
35+
StorageDead(_9);
36+
goto -> bb8;
37+
}
38+
39+
bb4: {
40+
StorageDead(_2);
41+
StorageLive(_5);
42+
StorageLive(_4);
43+
_4 = _1;
44+
_5 = get_bool(move _4) -> [return: bb5, unwind continue];
45+
}
46+
47+
bb5: {
48+
switchInt(move _5) -> [0: bb6, otherwise: bb7];
49+
}
50+
51+
bb6: {
52+
StorageDead(_4);
53+
_6 = const ();
54+
StorageDead(_5);
55+
StorageDead(_3);
56+
goto -> bb1;
57+
}
58+
59+
bb7: {
60+
StorageDead(_4);
61+
_0 = const ();
62+
StorageDead(_5);
63+
goto -> bb8;
64+
}
65+
66+
bb8: {
67+
StorageDead(_3);
68+
return;
69+
}
70+
}

tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff

+53-38
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: u8;
7+
let mut _5: u8;
8+
let mut _6: u8;
9+
let mut _7: u8;
10+
let mut _8: u8;
11+
let mut _14: u32;
12+
let mut _15: u32;
713
scope 1 {
814
- debug x => _1;
915
+ debug x => const 1_u8;
@@ -19,34 +25,23 @@
1925
scope 4 {
2026
- debug sum => _4;
2127
+ debug sum => const 6_u8;
22-
let _5: &str;
28+
let _9: &str;
2329
scope 5 {
24-
- debug s => _5;
30+
- debug s => _9;
2531
+ debug s => const "hello, world!";
26-
let _8: bool;
27-
let _9: bool;
28-
let _10: u32;
32+
let _10: (bool, bool, u32);
2933
scope 6 {
30-
- debug ((f: (bool, bool, u32)).0: bool) => _8;
31-
- debug ((f: (bool, bool, u32)).1: bool) => _9;
32-
- debug ((f: (bool, bool, u32)).2: u32) => _10;
33-
+ debug ((f: (bool, bool, u32)).0: bool) => const true;
34-
+ debug ((f: (bool, bool, u32)).1: bool) => const false;
35-
+ debug ((f: (bool, bool, u32)).2: u32) => const 123_u32;
36-
let _6: std::option::Option<u16>;
34+
debug f => _10;
35+
let _11: std::option::Option<u16>;
3736
scope 7 {
38-
- debug o => _6;
39-
+ debug o => const Option::<u16>::Some(99_u16);
40-
let _11: u32;
41-
let _12: u32;
37+
debug o => _11;
38+
let _12: Point;
4239
scope 8 {
43-
- debug ((p: Point).0: u32) => _11;
44-
- debug ((p: Point).1: u32) => _12;
45-
+ debug ((p: Point).0: u32) => const 32_u32;
46-
+ debug ((p: Point).1: u32) => const 32_u32;
47-
let _7: u32;
40+
- debug p => _12;
41+
+ debug p => const Point {{ x: 32_u32, y: 32_u32 }};
42+
let _13: u32;
4843
scope 9 {
49-
- debug a => _7;
44+
- debug a => _13;
5045
+ debug a => const 64_u32;
5146
}
5247
}
@@ -59,37 +54,57 @@
5954
}
6055

6156
bb0: {
57+
StorageLive(_1);
6258
_1 = const 1_u8;
59+
StorageLive(_2);
6360
_2 = const 2_u8;
61+
StorageLive(_3);
6462
_3 = const 3_u8;
6563
StorageLive(_4);
66-
_4 = const 6_u8;
6764
StorageLive(_5);
68-
_5 = const "hello, world!";
69-
StorageLive(_8);
70-
StorageLive(_9);
71-
StorageLive(_10);
72-
_8 = const true;
73-
_9 = const false;
74-
_10 = const 123_u32;
7565
StorageLive(_6);
76-
_6 = const Option::<u16>::Some(99_u16);
77-
_11 = const 32_u32;
78-
_12 = const 32_u32;
66+
_6 = const 1_u8;
7967
StorageLive(_7);
80-
_7 = const 64_u32;
68+
_7 = const 2_u8;
69+
_5 = const 3_u8;
8170
StorageDead(_7);
8271
StorageDead(_6);
72+
StorageLive(_8);
73+
_8 = const 3_u8;
74+
_4 = const 6_u8;
8375
StorageDead(_8);
84-
StorageDead(_9);
85-
StorageDead(_10);
8676
StorageDead(_5);
77+
StorageLive(_9);
78+
_9 = const "hello, world!";
79+
StorageLive(_10);
80+
_10 = (const true, const false, const 123_u32);
81+
StorageLive(_11);
82+
_11 = Option::<u16>::Some(const 99_u16);
83+
StorageLive(_12);
84+
_12 = const Point {{ x: 32_u32, y: 32_u32 }};
85+
StorageLive(_13);
86+
StorageLive(_14);
87+
_14 = const 32_u32;
88+
StorageLive(_15);
89+
_15 = const 32_u32;
90+
_13 = const 64_u32;
91+
StorageDead(_15);
92+
StorageDead(_14);
93+
_0 = const ();
94+
StorageDead(_13);
95+
StorageDead(_12);
96+
StorageDead(_11);
97+
StorageDead(_10);
98+
StorageDead(_9);
8799
StorageDead(_4);
100+
StorageDead(_3);
101+
StorageDead(_2);
102+
StorageDead(_1);
88103
return;
89104
}
90105
}
91106

92-
ALLOC0 (size: 4, align: 2) {
93-
01 00 63 00 │ ..c.
107+
ALLOC0 (size: 8, align: 4) {
108+
20 00 00 00 20 00 00 00 │ ... ...
94109
}
95110

tests/mir-opt/const_debuginfo.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
// skip-filecheck
2-
// compile-flags: -C overflow-checks=no -Zunsound-mir-opts
1+
// unit-test: ConstDebugInfo
2+
// compile-flags: -C overflow-checks=no -Zmir-enable-passes=+ConstProp
33

44
struct Point {
55
x: u32,
66
y: u32,
77
}
88

9+
// EMIT_MIR const_debuginfo.main.ConstDebugInfo.diff
910
fn main() {
11+
// CHECK-LABEL: fn main(
12+
// CHECK: debug x => const 1_u8;
13+
// CHECK: debug y => const 2_u8;
14+
// CHECK: debug z => const 3_u8;
15+
// CHECK: debug sum => const 6_u8;
16+
// CHECK: debug s => const "hello, world!";
17+
// CHECK: debug f => {{_.*}};
18+
// CHECK: debug o => {{_.*}};
19+
// CHECK: debug p => const Point
20+
// CHECK: debug a => const 64_u32;
1021
let x = 1u8;
1122
let y = 2u8;
1223
let z = 3u8;
@@ -21,5 +32,3 @@ fn main() {
2132
let p = Point { x: 32, y: 32 };
2233
let a = p.x + p.y;
2334
}
24-
25-
// EMIT_MIR const_debuginfo.main.ConstDebugInfo.diff

0 commit comments

Comments
 (0)