From c15c1ecbdbf7d660aaaa19ce7343f3b59644bbc2 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Fri, 4 Oct 2024 14:59:07 +0000 Subject: [PATCH] Add diff test for MatchBranchSimplification --- ....my_is_some.MatchBranchSimplification.diff | 31 ++++++++++++++++ tests/mir-opt/matches_reduce_branches.rs | 37 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/mir-opt/matches_reduce_branches.my_is_some.MatchBranchSimplification.diff diff --git a/tests/mir-opt/matches_reduce_branches.my_is_some.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.my_is_some.MatchBranchSimplification.diff new file mode 100644 index 0000000000000..50e7596db54f0 --- /dev/null +++ b/tests/mir-opt/matches_reduce_branches.my_is_some.MatchBranchSimplification.diff @@ -0,0 +1,31 @@ +- // MIR for `my_is_some` before MatchBranchSimplification ++ // MIR for `my_is_some` after MatchBranchSimplification + + fn my_is_some(_1: Option) -> 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; + } + } + diff --git a/tests/mir-opt/matches_reduce_branches.rs b/tests/mir-opt/matches_reduce_branches.rs index 6787e5816a309..cf96dcf9a73e2 100644 --- a/tests/mir-opt/matches_reduce_branches.rs +++ b/tests/mir-opt/matches_reduce_branches.rs @@ -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(bar: Option) -> 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( @@ -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(())); }