about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_mir_transform/src/early_otherwise_branch.rs4
-rw-r--r--tests/mir-opt/early_otherwise_branch_unwind.poll.EarlyOtherwiseBranch.diff62
-rw-r--r--tests/mir-opt/early_otherwise_branch_unwind.rs11
-rw-r--r--tests/mir-opt/early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff62
4 files changed, 53 insertions, 86 deletions
diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs
index 6dae6ec09ab..91e1395e764 100644
--- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs
+++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs
@@ -244,6 +244,10 @@ fn evaluate_candidate<'tcx>(
     parent: BasicBlock,
 ) -> Option<OptimizationData<'tcx>> {
     let bbs = &body.basic_blocks;
+    // NB: If this BB is a cleanup, we may need to figure out what else needs to be handled.
+    if bbs[parent].is_cleanup {
+        return None;
+    }
     let TerminatorKind::SwitchInt { targets, discr: parent_discr } = &bbs[parent].terminator().kind
     else {
         return None;
diff --git a/tests/mir-opt/early_otherwise_branch_unwind.poll.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch_unwind.poll.EarlyOtherwiseBranch.diff
index 5f03b94ccb8..b6450e43b09 100644
--- a/tests/mir-opt/early_otherwise_branch_unwind.poll.EarlyOtherwiseBranch.diff
+++ b/tests/mir-opt/early_otherwise_branch_unwind.poll.EarlyOtherwiseBranch.diff
@@ -12,7 +12,6 @@
       let mut _7: bool;
       let mut _8: bool;
       let mut _9: isize;
-+     let mut _10: bool;
       scope 1 {
           debug _trailers => _5;
       }
@@ -45,14 +44,12 @@
   
       bb4: {
           _0 = const ();
--         goto -> bb17;
-+         goto -> bb15;
+          goto -> bb17;
       }
   
       bb5: {
           _0 = const ();
--         goto -> bb17;
-+         goto -> bb15;
+          goto -> bb17;
       }
   
       bb6: {
@@ -60,26 +57,22 @@
           _6 = copy ((((_1 as Ready).0: std::result::Result<std::option::Option<std::vec::Vec<u8>>, u8>) as Err).0: u8);
           _0 = const ();
           StorageDead(_6);
--         goto -> bb17;
-+         goto -> bb15;
+          goto -> bb17;
       }
   
       bb7: {
           StorageLive(_5);
           _5 = move ((((((_1 as Ready).0: std::result::Result<std::option::Option<std::vec::Vec<u8>>, u8>) as Ok).0: std::option::Option<std::vec::Vec<u8>>) as Some).0: std::vec::Vec<u8>);
           _0 = const ();
--         drop(_5) -> [return: bb8, unwind: bb20];
-+         drop(_5) -> [return: bb8, unwind: bb16];
+          drop(_5) -> [return: bb8, unwind: bb20];
       }
   
       bb8: {
           StorageDead(_5);
--         goto -> bb17;
-+         goto -> bb15;
+          goto -> bb17;
       }
   
       bb9 (cleanup): {
-+         StorageDead(_10);
           resume;
       }
   
@@ -88,8 +81,7 @@
       }
   
       bb11: {
--         switchInt(copy _7) -> [0: bb12, otherwise: bb16];
-+         switchInt(copy _7) -> [0: bb12, otherwise: bb14];
+          switchInt(copy _7) -> [0: bb12, otherwise: bb16];
       }
   
       bb12: {
@@ -98,45 +90,37 @@
       }
   
       bb13: {
--         switchInt(copy _8) -> [0: bb14, otherwise: bb15];
--     }
-- 
--     bb14: {
+          switchInt(copy _8) -> [0: bb14, otherwise: bb15];
+      }
+  
+      bb14: {
           _8 = const false;
           goto -> bb12;
       }
   
--     bb15: {
--         goto -> bb14;
--     }
-- 
--     bb16: {
-+     bb14: {
+      bb15: {
+          goto -> bb14;
+      }
+  
+      bb16: {
           _9 = discriminant(((_1 as Ready).0: std::result::Result<std::option::Option<std::vec::Vec<u8>>, u8>));
           switchInt(move _9) -> [0: bb13, otherwise: bb12];
       }
   
--     bb17: {
-+     bb15: {
+      bb17: {
           switchInt(copy _4) -> [0: bb11, otherwise: bb10];
       }
   
--     bb18 (cleanup): {
--         switchInt(copy _3) -> [0: bb19, otherwise: bb9];
-+     bb16 (cleanup): {
-+         StorageLive(_10);
-+         _10 = Ne(copy _4, copy _3);
-+         switchInt(move _10) -> [0: bb17, otherwise: bb9];
+      bb18 (cleanup): {
+          switchInt(copy _3) -> [0: bb19, otherwise: bb9];
       }
   
--     bb19 (cleanup): {
-+     bb17 (cleanup): {
-+         StorageDead(_10);
+      bb19 (cleanup): {
           goto -> bb9;
--     }
-- 
--     bb20 (cleanup): {
--         switchInt(copy _4) -> [0: bb18, otherwise: bb9];
+      }
+  
+      bb20 (cleanup): {
+          switchInt(copy _4) -> [0: bb18, otherwise: bb9];
       }
   }
   
diff --git a/tests/mir-opt/early_otherwise_branch_unwind.rs b/tests/mir-opt/early_otherwise_branch_unwind.rs
index 7df58c7a64f..cbccf11729a 100644
--- a/tests/mir-opt/early_otherwise_branch_unwind.rs
+++ b/tests/mir-opt/early_otherwise_branch_unwind.rs
@@ -6,16 +6,14 @@ use std::task::Poll;
 
 // We find a matching pattern in the unwind path,
 // and we need to create a cleanup BB for this case to meet the unwind invariants rule.
+// NB: This transform is not happening currently.
 
 // EMIT_MIR early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff
 fn unwind<T>(val: Option<Option<Option<T>>>) {
     // CHECK-LABEL: fn unwind(
     // CHECK: drop({{.*}}) -> [return: bb{{.*}}, unwind: [[PARENT_UNWIND_BB:bb.*]]];
     // CHECK: [[PARENT_UNWIND_BB]] (cleanup): {
-    // CHECK-NEXT: StorageLive
-    // CHECK-NEXT: [[CMP_LOCAL:_.*]] = Ne
-    // CHECK-NEXT: switchInt(move [[CMP_LOCAL]]) -> [0: [[NEW_UNWIND_BB:bb.*]], otherwise
-    // CHECK: [[NEW_UNWIND_BB]] (cleanup): {
+    // CHECK-NEXT: switchInt
     match val {
         Some(Some(Some(_v))) => {}
         Some(Some(None)) => {}
@@ -30,10 +28,7 @@ pub fn poll(val: Poll<Result<Option<Vec<u8>>, u8>>) {
     // CHECK-LABEL: fn poll(
     // CHECK: drop({{.*}}) -> [return: bb{{.*}}, unwind: [[PARENT_UNWIND_BB:bb.*]]];
     // CHECK: [[PARENT_UNWIND_BB]] (cleanup): {
-    // CHECK-NEXT: StorageLive
-    // CHECK-NEXT: [[CMP_LOCAL:_.*]] = Ne
-    // CHECK-NEXT: switchInt(move [[CMP_LOCAL]]) -> [0: [[NEW_UNWIND_BB:bb.*]], otherwise
-    // CHECK: [[NEW_UNWIND_BB]] (cleanup): {
+    // CHECK-NEXT: switchInt
     match val {
         Poll::Ready(Ok(Some(_trailers))) => {}
         Poll::Ready(Err(_err)) => {}
diff --git a/tests/mir-opt/early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff
index 1405b9d314a..2b2c007e082 100644
--- a/tests/mir-opt/early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff
+++ b/tests/mir-opt/early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff
@@ -11,7 +11,6 @@
       let mut _6: bool;
       let mut _7: bool;
       let mut _8: isize;
-+     let mut _9: bool;
       scope 1 {
           debug _v => _5;
       }
@@ -41,38 +40,32 @@
   
       bb4: {
           _0 = const ();
--         goto -> bb17;
-+         goto -> bb15;
+          goto -> bb17;
       }
   
       bb5: {
           _0 = const ();
--         goto -> bb17;
-+         goto -> bb15;
+          goto -> bb17;
       }
   
       bb6: {
           _0 = const ();
--         goto -> bb17;
-+         goto -> bb15;
+          goto -> bb17;
       }
   
       bb7: {
           StorageLive(_5);
           _5 = move ((((((_1 as Some).0: std::option::Option<std::option::Option<T>>) as Some).0: std::option::Option<T>) as Some).0: T);
           _0 = const ();
--         drop(_5) -> [return: bb8, unwind: bb20];
-+         drop(_5) -> [return: bb8, unwind: bb16];
+          drop(_5) -> [return: bb8, unwind: bb20];
       }
   
       bb8: {
           StorageDead(_5);
--         goto -> bb17;
-+         goto -> bb15;
+          goto -> bb17;
       }
   
       bb9 (cleanup): {
-+         StorageDead(_9);
           resume;
       }
   
@@ -81,8 +74,7 @@
       }
   
       bb11: {
--         switchInt(copy _6) -> [0: bb12, otherwise: bb16];
-+         switchInt(copy _6) -> [0: bb12, otherwise: bb14];
+          switchInt(copy _6) -> [0: bb12, otherwise: bb16];
       }
   
       bb12: {
@@ -91,45 +83,37 @@
       }
   
       bb13: {
--         switchInt(copy _7) -> [0: bb14, otherwise: bb15];
--     }
-- 
--     bb14: {
+          switchInt(copy _7) -> [0: bb14, otherwise: bb15];
+      }
+  
+      bb14: {
           _7 = const false;
           goto -> bb12;
       }
   
--     bb15: {
--         goto -> bb14;
--     }
-- 
--     bb16: {
-+     bb14: {
+      bb15: {
+          goto -> bb14;
+      }
+  
+      bb16: {
           _8 = discriminant(((_1 as Some).0: std::option::Option<std::option::Option<T>>));
           switchInt(move _8) -> [1: bb13, otherwise: bb12];
       }
   
--     bb17: {
-+     bb15: {
+      bb17: {
           switchInt(copy _4) -> [1: bb11, otherwise: bb10];
       }
   
--     bb18 (cleanup): {
--         switchInt(copy _3) -> [1: bb19, otherwise: bb9];
-+     bb16 (cleanup): {
-+         StorageLive(_9);
-+         _9 = Ne(copy _4, copy _3);
-+         switchInt(move _9) -> [0: bb17, otherwise: bb9];
+      bb18 (cleanup): {
+          switchInt(copy _3) -> [1: bb19, otherwise: bb9];
       }
   
--     bb19 (cleanup): {
-+     bb17 (cleanup): {
-+         StorageDead(_9);
+      bb19 (cleanup): {
           goto -> bb9;
--     }
-- 
--     bb20 (cleanup): {
--         switchInt(copy _4) -> [1: bb18, otherwise: bb9];
+      }
+  
+      bb20 (cleanup): {
+          switchInt(copy _4) -> [1: bb18, otherwise: bb9];
       }
   }