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`
This commit is contained in:
Matthias Krüger 2023-01-26 15:02:22 +01:00 committed by GitHub
commit 4ed8cfc202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,6 +57,15 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
}
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()?;