Skip to content

Commit a954dcc

Browse files
committed
fix opt-mir test and remove false edge if no guard
1 parent 2d71c5f commit a954dcc

File tree

2 files changed

+75
-74
lines changed

2 files changed

+75
-74
lines changed

src/librustc_mir/build/matches/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
752752
Some(otherwise)
753753
} else {
754754
self.cfg.terminate(block, candidate_source_info,
755-
TerminatorKind::FalseEdges {
756-
real_target: arm_block,
757-
imaginary_targets:
758-
vec![candidate.next_candidate_binding_start_block]});
755+
TerminatorKind::Goto { target: arm_block });
759756
None
760757
}
761758
}

src/test/mir-opt/match_false_edges.rs

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ fn guard2(_:i32) -> bool {
2121
fn full_tested_match()
2222
{
2323
let _ = match Some(42) {
24-
Some(_) if guard() => 1,
25-
Some(_) => 2,
24+
Some(x) if guard() => 1 + x,
25+
Some(y) => 2 + y,
2626
None => 3
2727
};
2828
}
@@ -42,125 +42,129 @@ fn main() {
4242
// bb0: {
4343
// ...
4444
// _2 = std::option::Option<i32>::Some(const 42i32,);
45-
// _3 = discriminant(_2);
46-
// switchInt(_3) -> [0isize: bb8, otherwise: bb9];
45+
// _5 = discriminant(_2);
46+
// switchInt(_5) -> [0isize: bb6, otherwise: bb7];
4747
// }
4848
// bb1: { // arm1
49-
// _1 = const 1i32;
50-
// goto -> bb13;
49+
// StorageLive(_7);
50+
// _7 = _3;
51+
// _1 = Add(const 1i32, _7);
52+
// ...
53+
// goto -> bb11;
5154
// }
52-
// bb2: { // arm2
53-
// _1 = const 2i32;
54-
// goto -> bb13;
55+
// bb2: { // binding1 guard
56+
// StorageLive(_3);
57+
// _3 = ((_2 as Some).0: i32);
58+
// StorageLive(_6);
59+
// _6 = const guard() -> bb8;
5560
// }
56-
// bb3: { // arm3
57-
// _1 = const 3i32;
58-
// goto -> bb13;
61+
// bb3: { // binding2 & arm2
62+
// StorageLive(_4);
63+
// _4 = ((_2 as Some).0: i32);
64+
// StorageLive(_8);
65+
// _8 = _4;
66+
// _1 = Add(const 2i32, _8);
67+
// StorageDead(_8);
68+
// goto -> bb11;
5969
// }
60-
// bb4: { // binding1
61-
// ...
62-
// _4 = const guard() -> bb10;
70+
// bb4: { // binding3(empty) arm3
71+
// _1 = const 3i32;
72+
// goto -> bb11;
6373
// }
64-
// bb5: { // binding2
65-
// falseEdges -> [real: bb2, imaginary: bb6];
74+
// bb5: {
75+
// unreachable;
6676
// }
67-
// bb6: { // binding3
68-
// falseEdges -> [real: bb3, imaginary: bb7];
77+
// bb6: {
78+
// falseEdges -> [real: bb4, imaginary: bb5]; // from before_binding3 to unreachable
6979
// }
7080
// bb7: {
71-
// unreachable;
81+
// falseEdges -> [real: bb2, imaginary: bb3]; // from before_binding1 to binding2
7282
// }
7383
// bb8: {
74-
// falseEdges -> [real: bb6, imaginary: bb7]; // from before_binding3 to unreachable
84+
// switchInt(_6) -> [0u8: bb9, otherwise: bb1]; // end of guard
7585
// }
7686
// bb9: {
77-
// falseEdges -> [real: bb4, imaginary: bb5]; // from before_binding1 to binding2
87+
// falseEdges -> [real: bb10, imaginary: bb3]; // after_guard to binding2
7888
// }
7989
// bb10: {
80-
// switchInt(_4) -> [0u8: bb11, otherwise: bb1]; // end of guard
90+
// falseEdges -> [real: bb3, imaginary: bb4]; // from before_binding2 to binding3
8191
// }
8292
// bb11: {
83-
// falseEdges -> [real: bb12, imaginary: bb5]; // after_guard to binding2
84-
// }
85-
// bb12: {
86-
// falseEdges -> [real: bb5, imaginary: bb6]; // from before_binding2 to binding3
87-
// }
88-
// bb13: {
8993
// ...
9094
// return;
9195
// }
9296
//
9397
//
9498
// END rustc.node17.NLL.before.mir
9599
//
96-
// START rustc.node36.NLL.before.mir
100+
// START rustc.node40.NLL.before.mir
97101
// bb0: {
98102
// ...
99103
// _2 = std::option::Option<i32>::Some(const 1i32,);
100104
// _7 = discriminant(_2);
101-
// switchInt(_7) -> [1isize: bb10, otherwise: bb13];
105+
// switchInt(_7) -> [1isize: bb8, otherwise: bb11];
102106
// }
103107
// bb1: { // arm1
104108
// _1 = const 1i32;
105-
// goto -> bb17;
106-
// }
107-
// bb2: { // arm2
108-
// _1 = const 2i32;
109-
// goto -> bb17;
109+
// goto -> bb15;
110110
// }
111-
// bb3: { // arm3
111+
// bb2: { // arm3
112112
// _1 = const 3i32;
113-
// goto -> bb17;
113+
// goto -> bb15;
114114
// }
115-
// bb4: { // arm4
116-
// _1 = const 4i32;
117-
// goto -> bb17;
118-
// }
119-
// bb5: { // binding1: Some(w) if guard() =>
120-
// ...
121-
// _8 = const guard() -> bb11;
115+
// bb3: { // binding1: Some(w) if guard() =>
116+
// StorageLive(_3);
117+
// _3 = ((_2 as Some).0: i32);
118+
// StorageLive(_8);
119+
// _8 = const guard() -> bb9;
122120
// }
123-
// bb6: { // binding2: x =>
124-
// ...
121+
// bb4: { // binding2 & arm2
122+
// StorageLive(_4);
125123
// _4 = _2;
126-
// falseEdges -> [real: bb2, imaginary: bb7]; // after binding2 to binding3
127-
// }
128-
// bb7: { // binding3: Some(y) if guard2(y) =>
129-
// ...
130-
// _10 = const guard2(_11) -> bb14;
131-
// }
132-
// bb8: { // binding4: z_ =>
133-
// ...
124+
// _1 = const 2i32;
125+
// goto -> bb15;
126+
// }
127+
// bb5: { // binding3: Some(y) if guard2(y) =>
128+
// StorageLive(_5);
129+
// _5 = ((_2 as Some).0: i32);
130+
// StorageLive(_10);
131+
// StorageLive(_11);
132+
// _11 = _5;
133+
// _10 = const guard2(_11) -> bb12;
134+
// }
135+
// bb6: { // binding4 & arm4
136+
// StorageLive(_6);
134137
// _6 = _2;
135-
// falseEdges -> [real: bb4, imaginary: bb9]; // after binding3 to unreachable
138+
// _1 = const 4i32;
139+
// goto -> bb15;
136140
// }
137-
// bb9: {
141+
// bb7: {
138142
// unreachable;
139143
// }
144+
// bb8: {
145+
// falseEdges -> [real: bb3, imaginary: bb4]; // from before_binding1 to binding2
146+
// }
147+
// bb9: {
148+
// switchInt(_8) -> [0u8: bb10, otherwise: bb1]; // end of gurard
149+
// }
140150
// bb10: {
141-
// falseEdges -> [real: bb5, imaginary: bb6]; // from before_binding1 to binding2
151+
// falseEdges -> [real: bb11, imaginary: bb4]; // after guard to binding2
142152
// }
143153
// bb11: {
144-
// switchInt(_8) -> [0u8: bb12, otherwise: bb1]; // end of gurard
154+
// falseEdges -> [real: bb4, imaginary: bb5]; // from before_binding2 to binding3
145155
// }
146156
// bb12: {
147-
// falseEdges -> [real: bb13, imaginary: bb6]; // after guard to binding2
157+
// StorageDead(_11);
158+
// switchInt(_10) -> [0u8: bb13, otherwise: bb2]; // end of guard2
148159
// }
149160
// bb13: {
150-
// falseEdges -> [real: bb6, imaginary: bb7]; // from before_binding2 to binding3
161+
// falseEdges -> [real: bb14, imaginary: bb6]; // after guard2 to binding4
151162
// }
152163
// bb14: {
153-
// ...
154-
// switchInt(_10) -> [0u8: bb15, otherwise: bb3]; // end of guard2
164+
// falseEdges -> [real: bb6, imaginary: bb7]; // from befor binding4 to unreachable
155165
// }
156166
// bb15: {
157-
// falseEdges -> [real: bb16, imaginary: bb8]; // after guard2 to binding4
158-
// }
159-
// bb16: {
160-
// falseEdges -> [real: bb8, imaginary: bb9]; // from befor binding3 to binding4
161-
// }
162-
// bb17: {
163167
// ...
164168
// return;
165169
// }
166-
// END rustc.node36.NLL.before.mir
170+
// END rustc.node40.NLL.before.mir

0 commit comments

Comments
 (0)