Do not create new resume block if there isn't one already
This commit is contained in:
parent
0f7f6b7061
commit
cfbf1bf7cd
1 changed files with 13 additions and 3 deletions
|
@ -6,8 +6,8 @@ use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_target::spec::PanicStrategy;
|
use rustc_target::spec::PanicStrategy;
|
||||||
|
|
||||||
/// A pass that removes noop landing pads and replaces jumps to them with
|
/// A pass that removes noop landing pads and replaces jumps to them with
|
||||||
/// `None`. This is important because otherwise LLVM generates terrible
|
/// `UnwindAction::Continue`. This is important because otherwise LLVM generates
|
||||||
/// code for these.
|
/// terrible code for these.
|
||||||
pub struct RemoveNoopLandingPads;
|
pub struct RemoveNoopLandingPads;
|
||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for RemoveNoopLandingPads {
|
impl<'tcx> MirPass<'tcx> for RemoveNoopLandingPads {
|
||||||
|
@ -84,7 +84,17 @@ impl RemoveNoopLandingPads {
|
||||||
fn remove_nop_landing_pads(&self, body: &mut Body<'_>) {
|
fn remove_nop_landing_pads(&self, body: &mut Body<'_>) {
|
||||||
debug!("body: {:#?}", body);
|
debug!("body: {:#?}", body);
|
||||||
|
|
||||||
// make sure there's a resume block
|
// Skip the pass if there are no blocks with a resume terminator.
|
||||||
|
let has_resume = body
|
||||||
|
.basic_blocks
|
||||||
|
.iter_enumerated()
|
||||||
|
.any(|(_bb, block)| matches!(block.terminator().kind, TerminatorKind::Resume));
|
||||||
|
if !has_resume {
|
||||||
|
debug!("remove_noop_landing_pads: no resume block in MIR");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure there's a resume block without any statements
|
||||||
let resume_block = {
|
let resume_block = {
|
||||||
let mut patch = MirPatch::new(body);
|
let mut patch = MirPatch::new(body);
|
||||||
let resume_block = patch.resume_block();
|
let resume_block = patch.resume_block();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue