Skip to content

Commit b290d69

Browse files
mir-opt test before patch
1 parent 7659abc commit b290d69

3 files changed

+299
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// compile-flags: -Z validate-mir
2+
#![feature(let_chains)]
3+
struct Droppy(u8);
4+
impl Drop for Droppy {
5+
fn drop(&mut self) {
6+
println!("drop {}", self.0);
7+
}
8+
}
9+
10+
enum E {
11+
A(u8),
12+
B,
13+
}
14+
15+
impl E {
16+
fn f() -> Self {
17+
Self::A(1)
18+
}
19+
}
20+
21+
fn always_true() -> bool {
22+
true
23+
}
24+
25+
// EMIT_MIR logical_or_in_conditional.test_or.built.after.mir
26+
fn test_or() {
27+
if Droppy(0).0 > 0 || Droppy(1).0 > 1 {}
28+
}
29+
30+
// EMIT_MIR logical_or_in_conditional.test_complex.built.after.mir
31+
fn test_complex() {
32+
if let E::A(_) = E::f() && ((always_true() && Droppy(0).0 > 0) || Droppy(1).0 > 1) {}
33+
34+
if !always_true() && let E::B = E::f() {}
35+
}
36+
37+
fn main() {
38+
test_or();
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// MIR for `test_complex` after built
2+
3+
fn test_complex() -> () {
4+
let mut _0: ();
5+
let _1: ();
6+
let mut _2: E;
7+
let mut _3: isize;
8+
let mut _4: bool;
9+
let mut _5: bool;
10+
let mut _6: bool;
11+
let mut _7: bool;
12+
let mut _8: u8;
13+
let mut _9: Droppy;
14+
let mut _10: bool;
15+
let mut _11: u8;
16+
let mut _12: Droppy;
17+
let mut _13: bool;
18+
let mut _14: bool;
19+
let mut _15: E;
20+
let mut _16: isize;
21+
22+
bb0: {
23+
StorageLive(_1);
24+
StorageLive(_2);
25+
_2 = E::f() -> [return: bb1, unwind: bb27];
26+
}
27+
28+
bb1: {
29+
FakeRead(ForMatchedPlace(None), _2);
30+
_3 = discriminant(_2);
31+
switchInt(move _3) -> [0: bb2, otherwise: bb3];
32+
}
33+
34+
bb2: {
35+
falseEdge -> [real: bb4, imaginary: bb3];
36+
}
37+
38+
bb3: {
39+
goto -> bb16;
40+
}
41+
42+
bb4: {
43+
StorageLive(_4);
44+
StorageLive(_5);
45+
StorageLive(_6);
46+
_6 = always_true() -> [return: bb11, unwind: bb27];
47+
}
48+
49+
bb5: {
50+
_4 = const true;
51+
goto -> bb7;
52+
}
53+
54+
bb6: {
55+
StorageLive(_10);
56+
StorageLive(_11);
57+
StorageLive(_12);
58+
_12 = Droppy(const 1_u8);
59+
_11 = (_12.0: u8);
60+
_10 = Gt(move _11, const 1_u8);
61+
drop(_12) -> [return: bb13, unwind: bb27];
62+
}
63+
64+
bb7: {
65+
StorageDead(_10);
66+
StorageDead(_5);
67+
switchInt(move _4) -> [0: bb15, otherwise: bb14];
68+
}
69+
70+
bb8: {
71+
_5 = const false;
72+
goto -> bb10;
73+
}
74+
75+
bb9: {
76+
StorageLive(_7);
77+
StorageLive(_8);
78+
StorageLive(_9);
79+
_9 = Droppy(const 0_u8);
80+
_8 = (_9.0: u8);
81+
_7 = Gt(move _8, const 0_u8);
82+
drop(_9) -> [return: bb12, unwind: bb27];
83+
}
84+
85+
bb10: {
86+
StorageDead(_7);
87+
StorageDead(_6);
88+
switchInt(move _5) -> [0: bb6, otherwise: bb5];
89+
}
90+
91+
bb11: {
92+
switchInt(move _6) -> [0: bb8, otherwise: bb9];
93+
}
94+
95+
bb12: {
96+
StorageDead(_9);
97+
StorageDead(_8);
98+
_5 = move _7;
99+
goto -> bb10;
100+
}
101+
102+
bb13: {
103+
StorageDead(_12);
104+
StorageDead(_11);
105+
_4 = move _10;
106+
goto -> bb7;
107+
}
108+
109+
bb14: {
110+
_1 = const ();
111+
goto -> bb17;
112+
}
113+
114+
bb15: {
115+
goto -> bb16;
116+
}
117+
118+
bb16: {
119+
_1 = const ();
120+
goto -> bb17;
121+
}
122+
123+
bb17: {
124+
StorageDead(_4);
125+
StorageDead(_2);
126+
StorageDead(_1);
127+
StorageLive(_13);
128+
StorageLive(_14);
129+
_14 = always_true() -> [return: bb18, unwind: bb27];
130+
}
131+
132+
bb18: {
133+
_13 = Not(move _14);
134+
StorageDead(_14);
135+
switchInt(move _13) -> [0: bb20, otherwise: bb19];
136+
}
137+
138+
bb19: {
139+
StorageLive(_15);
140+
_15 = E::f() -> [return: bb21, unwind: bb27];
141+
}
142+
143+
bb20: {
144+
goto -> bb25;
145+
}
146+
147+
bb21: {
148+
FakeRead(ForMatchedPlace(None), _15);
149+
_16 = discriminant(_15);
150+
switchInt(move _16) -> [1: bb23, otherwise: bb22];
151+
}
152+
153+
bb22: {
154+
goto -> bb25;
155+
}
156+
157+
bb23: {
158+
falseEdge -> [real: bb24, imaginary: bb22];
159+
}
160+
161+
bb24: {
162+
_0 = const ();
163+
goto -> bb26;
164+
}
165+
166+
bb25: {
167+
_0 = const ();
168+
goto -> bb26;
169+
}
170+
171+
bb26: {
172+
StorageDead(_13);
173+
StorageDead(_15);
174+
return;
175+
}
176+
177+
bb27 (cleanup): {
178+
resume;
179+
}
180+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// MIR for `test_or` after built
2+
3+
fn test_or() -> () {
4+
let mut _0: ();
5+
let mut _1: bool;
6+
let mut _2: bool;
7+
let mut _3: u8;
8+
let mut _4: Droppy;
9+
let mut _5: bool;
10+
let mut _6: u8;
11+
let mut _7: Droppy;
12+
13+
bb0: {
14+
StorageLive(_1);
15+
StorageLive(_2);
16+
StorageLive(_3);
17+
StorageLive(_4);
18+
_4 = Droppy(const 0_u8);
19+
_3 = (_4.0: u8);
20+
_2 = Gt(move _3, const 0_u8);
21+
drop(_4) -> [return: bb4, unwind: bb10];
22+
}
23+
24+
bb1: {
25+
_1 = const true;
26+
goto -> bb3;
27+
}
28+
29+
bb2: {
30+
StorageLive(_5);
31+
StorageLive(_6);
32+
StorageLive(_7);
33+
_7 = Droppy(const 1_u8);
34+
_6 = (_7.0: u8);
35+
_5 = Gt(move _6, const 1_u8);
36+
drop(_7) -> [return: bb5, unwind: bb10];
37+
}
38+
39+
bb3: {
40+
StorageDead(_5);
41+
StorageDead(_2);
42+
switchInt(move _1) -> [0: bb7, otherwise: bb6];
43+
}
44+
45+
bb4: {
46+
StorageDead(_4);
47+
StorageDead(_3);
48+
switchInt(move _2) -> [0: bb2, otherwise: bb1];
49+
}
50+
51+
bb5: {
52+
StorageDead(_7);
53+
StorageDead(_6);
54+
_1 = move _5;
55+
goto -> bb3;
56+
}
57+
58+
bb6: {
59+
_0 = const ();
60+
goto -> bb9;
61+
}
62+
63+
bb7: {
64+
goto -> bb8;
65+
}
66+
67+
bb8: {
68+
_0 = const ();
69+
goto -> bb9;
70+
}
71+
72+
bb9: {
73+
StorageDead(_1);
74+
return;
75+
}
76+
77+
bb10 (cleanup): {
78+
resume;
79+
}
80+
}

0 commit comments

Comments
 (0)