Skip to content

Commit 3b3e0d6

Browse files
committed
Add diff test for MatchBranchSimplification
1 parent 9fa0146 commit 3b3e0d6

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
debug bar => _1;
6+
let mut _0: bool;
7+
let mut _2: isize;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const false;
20+
goto -> bb4;
21+
}
22+
23+
bb3: {
24+
_0 = const true;
25+
goto -> bb4;
26+
}
27+
28+
bb4: {
29+
drop(_1) -> [return: bb5, unwind: bb6];
30+
}
31+
32+
bb5: {
33+
return;
34+
}
35+
36+
bb6 (cleanup): {
37+
resume;
38+
}
39+
}
40+

tests/mir-opt/matches_reduce_branches.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ test-mir-pass: MatchBranchSimplification
2+
//@ needs-unwind
23

34
#![feature(repr128)]
45
#![feature(core_intrinsics)]
@@ -19,6 +20,18 @@ fn foo(bar: Option<()>) {
1920
}
2021
}
2122

23+
// EMIT_MIR matches_reduce_branches.my_is_some.MatchBranchSimplification.diff
24+
// Test for #131219.
25+
fn my_is_some<T>(bar: Option<T>) -> bool {
26+
// CHECK-LABEL: fn my_is_some(
27+
// CHECK: switchInt
28+
// CHECK: return
29+
match bar {
30+
Some(_) => true,
31+
None => false,
32+
}
33+
}
34+
2235
// EMIT_MIR matches_reduce_branches.bar.MatchBranchSimplification.diff
2336
fn bar(i: i32) -> (bool, bool, bool, bool) {
2437
// CHECK-LABEL: fn bar(
@@ -651,4 +664,7 @@ fn main() {
651664
let _: u8 = match_trunc_u16_u8_failed(EnumAu16::u0_0x0000);
652665

653666
let _ = match_i128_u128(EnumAi128::A);
667+
668+
let _ = my_is_some::<()>(None);
669+
let _ = my_is_some(Some(()));
654670
}

0 commit comments

Comments
 (0)