about summary refs log tree commit diff
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2024-10-04 14:59:07 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2024-12-27 10:46:58 +0000
commit11f7e302e154cdb378a8ae4b0ca8332c40218b20 (patch)
tree3e0e5d157667fd4fcbfb7f3014dc4b157b21f85b
parent19e75f4fb3f960267996e8788459e97b8769aac7 (diff)
downloadrust-11f7e302e154cdb378a8ae4b0ca8332c40218b20.tar.gz
rust-11f7e302e154cdb378a8ae4b0ca8332c40218b20.zip
Add diff test for MatchBranchSimplification
-rw-r--r--tests/mir-opt/matches_reduce_branches.my_is_some.MatchBranchSimplification.diff32
-rw-r--r--tests/mir-opt/matches_reduce_branches.rs14
2 files changed, 46 insertions, 0 deletions
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 00000000000..d55e764e1c2
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.my_is_some.MatchBranchSimplification.diff
@@ -0,0 +1,32 @@
+- // MIR for `my_is_some` before MatchBranchSimplification
++ // MIR for `my_is_some` after MatchBranchSimplification
+  
+  fn my_is_some(_1: Option<()>) -> bool {
+      debug bar => _1;
+      let mut _0: bool;
+      let mut _2: isize;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const false;
+          goto -> bb4;
+      }
+  
+      bb3: {
+          _0 = const true;
+          goto -> bb4;
+      }
+  
+      bb4: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.rs b/tests/mir-opt/matches_reduce_branches.rs
index 6787e5816a3..e2bd7b3459c 100644
--- a/tests/mir-opt/matches_reduce_branches.rs
+++ b/tests/mir-opt/matches_reduce_branches.rs
@@ -19,6 +19,18 @@ fn foo(bar: Option<()>) {
     }
 }
 
+// EMIT_MIR matches_reduce_branches.my_is_some.MatchBranchSimplification.diff
+// Test for #131219.
+fn my_is_some(bar: Option<()>) -> bool {
+    // CHECK-LABEL: fn my_is_some(
+    // CHECK: switchInt
+    // CHECK: return
+    match bar {
+        Some(_) => true,
+        None => false,
+    }
+}
+
 // EMIT_MIR matches_reduce_branches.bar.MatchBranchSimplification.diff
 fn bar(i: i32) -> (bool, bool, bool, bool) {
     // CHECK-LABEL: fn bar(
@@ -651,4 +663,6 @@ fn main() {
     let _: u8 = match_trunc_u16_u8_failed(EnumAu16::u0_0x0000);
 
     let _ = match_i128_u128(EnumAi128::A);
+
+    let _ = my_is_some(None);
 }