1
Fork 0
rust/compiler/rustc_mir/src/transform/no_landing_pads.rs

29 lines
777 B
Rust
Raw Normal View History

//! This pass removes the unwind branch of all the terminators when the no-landing-pads option is
//! specified.
use crate::transform::MirPass;
2020-03-29 16:41:09 +02:00
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
2020-03-31 23:15:39 +01:00
use rustc_target::spec::PanicStrategy;
pub struct NoLandingPads;
impl<'tcx> MirPass<'tcx> for NoLandingPads {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
no_landing_pads(tcx, body)
}
}
2020-04-12 10:31:00 -07:00
pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if tcx.sess.panic_strategy() != PanicStrategy::Abort {
return;
2019-10-20 16:11:04 -04:00
}
for block in body.basic_blocks_mut() {
let terminator = block.terminator_mut();
if let Some(unwind) = terminator.kind.unwind_mut() {
unwind.take();
}
}
}