Skip to content

Commit c15c1ec

Browse files
committed
Add diff test for MatchBranchSimplification
1 parent 3002af6 commit c15c1ec

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
- // MIR for `my_is_some` before MatchBranchSimplification
2+
+ // MIR for `my_is_some` after MatchBranchSimplification
3+
4+
fn my_is_some(_1: Option<T>) -> bool {
5+
let mut _0: bool;
6+
let mut _2: isize;
7+
8+
bb0: {
9+
_2 = discriminant(_1);
10+
switchInt(copy _2) -> [0: bb1, 1: bb2, otherwise: bb3];
11+
}
12+
13+
bb1: {
14+
_0 = const false;
15+
goto -> bb4;
16+
}
17+
18+
bb2: {
19+
_0 = const true;
20+
goto -> bb4;
21+
}
22+
23+
bb3: {
24+
unreachable;
25+
}
26+
27+
bb4: {
28+
return;
29+
}
30+
}
31+

tests/mir-opt/matches_reduce_branches.rs

+37
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,40 @@ fn foo(bar: Option<()>) {
1919
}
2020
}
2121

22+
// EMIT_MIR matches_reduce_branches.my_is_some.MatchBranchSimplification.diff
23+
// Test for #131219. UnreachableEnumBranching introduces the third branch normally,
24+
// but is disabled during testing, so recreate the same MIR here.
25+
#[custom_mir(dialect = "built")]
26+
fn my_is_some<T>(bar: Option<T>) -> bool {
27+
// CHECK-LABEL: fn my_is_some(
28+
// CHECK: switchInt
29+
// CHECK: return
30+
mir! {
31+
{
32+
let a = Discriminant(bar);
33+
match a {
34+
0 => bb1,
35+
1 => bb2,
36+
_ => unreachable_bb,
37+
}
38+
}
39+
bb1 = {
40+
RET = false;
41+
Goto(ret)
42+
}
43+
bb2 = {
44+
RET = true;
45+
Goto(ret)
46+
}
47+
unreachable_bb = {
48+
Unreachable()
49+
}
50+
ret = {
51+
Return()
52+
}
53+
}
54+
}
55+
2256
// EMIT_MIR matches_reduce_branches.bar.MatchBranchSimplification.diff
2357
fn bar(i: i32) -> (bool, bool, bool, bool) {
2458
// CHECK-LABEL: fn bar(
@@ -651,4 +685,7 @@ fn main() {
651685
let _: u8 = match_trunc_u16_u8_failed(EnumAu16::u0_0x0000);
652686

653687
let _ = match_i128_u128(EnumAi128::A);
688+
689+
let _ = my_is_some::<()>(None);
690+
let _ = my_is_some(Some(()));
654691
}

0 commit comments

Comments
 (0)