Skip to content

Commit

Permalink
Add diff test for MatchBranchSimplification
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Oct 4, 2024
1 parent 3002af6 commit c15c1ec
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- // MIR for `my_is_some` before MatchBranchSimplification
+ // MIR for `my_is_some` after MatchBranchSimplification

fn my_is_some(_1: Option<T>) -> bool {
let mut _0: bool;
let mut _2: isize;

bb0: {
_2 = discriminant(_1);
switchInt(copy _2) -> [0: bb1, 1: bb2, otherwise: bb3];
}

bb1: {
_0 = const false;
goto -> bb4;
}

bb2: {
_0 = const true;
goto -> bb4;
}

bb3: {
unreachable;
}

bb4: {
return;
}
}

37 changes: 37 additions & 0 deletions tests/mir-opt/matches_reduce_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,40 @@ fn foo(bar: Option<()>) {
}
}

// EMIT_MIR matches_reduce_branches.my_is_some.MatchBranchSimplification.diff
// Test for #131219. UnreachableEnumBranching introduces the third branch normally,
// but is disabled during testing, so recreate the same MIR here.
#[custom_mir(dialect = "built")]
fn my_is_some<T>(bar: Option<T>) -> bool {
// CHECK-LABEL: fn my_is_some(
// CHECK: switchInt
// CHECK: return
mir! {
{
let a = Discriminant(bar);
match a {
0 => bb1,
1 => bb2,
_ => unreachable_bb,
}
}
bb1 = {
RET = false;
Goto(ret)
}
bb2 = {
RET = true;
Goto(ret)
}
unreachable_bb = {
Unreachable()
}
ret = {
Return()
}
}
}

// EMIT_MIR matches_reduce_branches.bar.MatchBranchSimplification.diff
fn bar(i: i32) -> (bool, bool, bool, bool) {
// CHECK-LABEL: fn bar(
Expand Down Expand Up @@ -651,4 +685,7 @@ fn main() {
let _: u8 = match_trunc_u16_u8_failed(EnumAu16::u0_0x0000);

let _ = match_i128_u128(EnumAi128::A);

let _ = my_is_some::<()>(None);
let _ = my_is_some(Some(()));
}

0 comments on commit c15c1ec

Please sign in to comment.