about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-01-26 15:02:22 +0100
committerGitHub <noreply@github.com>2023-01-26 15:02:22 +0100
commit4ed8cfc2024a86aa18783a86e9ed51adeef12a63 (patch)
tree3b3ca4900d3c54b89a25dc08a4d93ad89129b9f6 /compiler/rustc_mir_transform/src
parentc87996a8ada9be5373cb069b20351a18ef74f226 (diff)
parentf8aaf9aadb12c599eb20679cc141ce7c7c253c3a (diff)
downloadrust-4ed8cfc2024a86aa18783a86e9ed51adeef12a63.tar.gz
rust-4ed8cfc2024a86aa18783a86e9ed51adeef12a63.zip
Rollup merge of #107323 - JakobDegen:const-goto, r=tmiasko
Disable ConstGoto opt in cleanup blocks

Fixes #107315 .

There is probably a smaller hammer that we could use here, but none that is super obviously correct. We can always revisit this in the future.

Could not add a test because custom mir does not support cleanup blocks. However, did check that the fallible_iterator crate no longer ICEs with the other PR cherry picked.

r? `@tmiasko`
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/const_goto.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/const_goto.rs b/compiler/rustc_mir_transform/src/const_goto.rs
index 40eefda4f07..da101ca7ad2 100644
--- a/compiler/rustc_mir_transform/src/const_goto.rs
+++ b/compiler/rustc_mir_transform/src/const_goto.rs
@@ -57,6 +57,15 @@ impl<'tcx> MirPass<'tcx> for ConstGoto {
 }
 
 impl<'tcx> Visitor<'tcx> for ConstGotoOptimizationFinder<'_, 'tcx> {
+    fn visit_basic_block_data(&mut self, block: BasicBlock, data: &BasicBlockData<'tcx>) {
+        if data.is_cleanup {
+            // Because of the restrictions around control flow in cleanup blocks, we don't perform
+            // this optimization at all in such blocks.
+            return;
+        }
+        self.super_basic_block_data(block, data);
+    }
+
     fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
         let _: Option<_> = try {
             let target = terminator.kind.as_goto()?;