Skip to content

Commit

Permalink
Rollup merge of #107323 - JakobDegen:const-goto, r=tmiasko
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
matthiaskrgr authored Jan 26, 2023
2 parents c87996a + f8aaf9a commit 4ed8cfc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/rustc_mir_transform/src/const_goto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down

0 comments on commit 4ed8cfc

Please sign in to comment.