Skip to content

Commit cfbf1bf

Browse files
committed
Do not create new resume block if there isn't one already
1 parent 0f7f6b7 commit cfbf1bf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use rustc_middle::ty::TyCtxt;
66
use rustc_target::spec::PanicStrategy;
77

88
/// A pass that removes noop landing pads and replaces jumps to them with
9-
/// `None`. This is important because otherwise LLVM generates terrible
10-
/// code for these.
9+
/// `UnwindAction::Continue`. This is important because otherwise LLVM generates
10+
/// terrible code for these.
1111
pub struct RemoveNoopLandingPads;
1212

1313
impl<'tcx> MirPass<'tcx> for RemoveNoopLandingPads {
@@ -84,7 +84,17 @@ impl RemoveNoopLandingPads {
8484
fn remove_nop_landing_pads(&self, body: &mut Body<'_>) {
8585
debug!("body: {:#?}", body);
8686

87-
// make sure there's a resume block
87+
// Skip the pass if there are no blocks with a resume terminator.
88+
let has_resume = body
89+
.basic_blocks
90+
.iter_enumerated()
91+
.any(|(_bb, block)| matches!(block.terminator().kind, TerminatorKind::Resume));
92+
if !has_resume {
93+
debug!("remove_noop_landing_pads: no resume block in MIR");
94+
return;
95+
}
96+
97+
// make sure there's a resume block without any statements
8898
let resume_block = {
8999
let mut patch = MirPatch::new(body);
90100
let resume_block = patch.resume_block();

0 commit comments

Comments
 (0)