Skip to content

Commit 6506837

Browse files
committed
Add mir-opt test.
1 parent 9aa5c24 commit 6506837

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
- // MIR for `multiple` before DataflowConstProp
2+
+ // MIR for `multiple` after DataflowConstProp
3+
4+
fn multiple(_1: bool, _2: u8) -> () {
5+
debug x => _1; // in scope 0 at $DIR/enum.rs:+0:13: +0:14
6+
debug i => _2; // in scope 0 at $DIR/enum.rs:+0:22: +0:23
7+
let mut _0: (); // return place in scope 0 at $DIR/enum.rs:+0:29: +0:29
8+
let _3: std::option::Option<u8>; // in scope 0 at $DIR/enum.rs:+1:9: +1:10
9+
let mut _4: bool; // in scope 0 at $DIR/enum.rs:+1:16: +1:17
10+
let mut _5: u8; // in scope 0 at $DIR/enum.rs:+2:14: +2:15
11+
let mut _7: isize; // in scope 0 at $DIR/enum.rs:+9:23: +9:30
12+
scope 1 {
13+
debug e => _3; // in scope 1 at $DIR/enum.rs:+1:9: +1:10
14+
let _6: u8; // in scope 1 at $DIR/enum.rs:+9:9: +9:10
15+
let _8: u8; // in scope 1 at $DIR/enum.rs:+9:28: +9:29
16+
scope 2 {
17+
debug x => _6; // in scope 2 at $DIR/enum.rs:+9:9: +9:10
18+
let _9: u8; // in scope 2 at $DIR/enum.rs:+11:9: +11:10
19+
scope 4 {
20+
debug y => _9; // in scope 4 at $DIR/enum.rs:+11:9: +11:10
21+
}
22+
}
23+
scope 3 {
24+
debug i => _8; // in scope 3 at $DIR/enum.rs:+9:28: +9:29
25+
}
26+
}
27+
28+
bb0: {
29+
StorageLive(_3); // scope 0 at $DIR/enum.rs:+1:9: +1:10
30+
StorageLive(_4); // scope 0 at $DIR/enum.rs:+1:16: +1:17
31+
_4 = _1; // scope 0 at $DIR/enum.rs:+1:16: +1:17
32+
switchInt(move _4) -> [0: bb2, otherwise: bb1]; // scope 0 at $DIR/enum.rs:+1:16: +1:17
33+
}
34+
35+
bb1: {
36+
StorageLive(_5); // scope 0 at $DIR/enum.rs:+2:14: +2:15
37+
_5 = _2; // scope 0 at $DIR/enum.rs:+2:14: +2:15
38+
_3 = Option::<u8>::Some(move _5); // scope 0 at $DIR/enum.rs:+2:9: +2:16
39+
StorageDead(_5); // scope 0 at $DIR/enum.rs:+2:15: +2:16
40+
goto -> bb3; // scope 0 at $DIR/enum.rs:+1:13: +5:6
41+
}
42+
43+
bb2: {
44+
_3 = Option::<u8>::None; // scope 0 at $DIR/enum.rs:+4:9: +4:13
45+
goto -> bb3; // scope 0 at $DIR/enum.rs:+1:13: +5:6
46+
}
47+
48+
bb3: {
49+
StorageDead(_4); // scope 0 at $DIR/enum.rs:+5:5: +5:6
50+
StorageLive(_6); // scope 1 at $DIR/enum.rs:+9:9: +9:10
51+
_7 = discriminant(_3); // scope 1 at $DIR/enum.rs:+9:19: +9:20
52+
switchInt(move _7) -> [0: bb4, 1: bb6, otherwise: bb5]; // scope 1 at $DIR/enum.rs:+9:13: +9:20
53+
}
54+
55+
bb4: {
56+
_6 = const 0_u8; // scope 1 at $DIR/enum.rs:+9:45: +9:46
57+
goto -> bb7; // scope 1 at $DIR/enum.rs:+9:45: +9:46
58+
}
59+
60+
bb5: {
61+
unreachable; // scope 1 at $DIR/enum.rs:+9:19: +9:20
62+
}
63+
64+
bb6: {
65+
StorageLive(_8); // scope 1 at $DIR/enum.rs:+9:28: +9:29
66+
_8 = ((_3 as Some).0: u8); // scope 1 at $DIR/enum.rs:+9:28: +9:29
67+
_6 = _8; // scope 3 at $DIR/enum.rs:+9:34: +9:35
68+
StorageDead(_8); // scope 1 at $DIR/enum.rs:+9:34: +9:35
69+
goto -> bb7; // scope 1 at $DIR/enum.rs:+9:34: +9:35
70+
}
71+
72+
bb7: {
73+
StorageLive(_9); // scope 2 at $DIR/enum.rs:+11:9: +11:10
74+
- _9 = _6; // scope 2 at $DIR/enum.rs:+11:13: +11:14
75+
+ _9 = const 0_u8; // scope 2 at $DIR/enum.rs:+11:13: +11:14
76+
_0 = const (); // scope 0 at $DIR/enum.rs:+0:29: +12:2
77+
StorageDead(_9); // scope 2 at $DIR/enum.rs:+12:1: +12:2
78+
StorageDead(_6); // scope 1 at $DIR/enum.rs:+12:1: +12:2
79+
StorageDead(_3); // scope 0 at $DIR/enum.rs:+12:1: +12:2
80+
return; // scope 0 at $DIR/enum.rs:+12:2: +12:2
81+
}
82+
}
83+

tests/mir-opt/dataflow-const-prop/enum.rs

+16
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,23 @@ fn mutate_discriminant() -> u8 {
4646
)
4747
}
4848

49+
// EMIT_MIR enum.multiple.DataflowConstProp.diff
50+
fn multiple(x: bool, i: u8) {
51+
let e = if x {
52+
Some(i)
53+
} else {
54+
None
55+
};
56+
// The dataflow state must have:
57+
// discriminant(e) => Top
58+
// (e as Some).0 => Top
59+
let x = match e { Some(i) => i, None => 0 };
60+
// Therefore, `x` should be `Top` here, and no replacement shall happen.
61+
let y = x;
62+
}
63+
4964
fn main() {
5065
simple();
5166
mutate_discriminant();
67+
multiple(false, 5);
5268
}

0 commit comments

Comments
 (0)