2016-02-11 10:13:35 +02:00
|
|
|
//! This pass removes the unwind branch of all the terminators when the no-landing-pads option is
|
|
|
|
//! specified.
|
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
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;
|
2016-02-11 10:13:35 +02:00
|
|
|
|
2021-01-18 00:00:00 +00:00
|
|
|
pub struct NoLandingPads;
|
2016-02-11 10:13:35 +02:00
|
|
|
|
2021-01-18 00:00:00 +00:00
|
|
|
impl<'tcx> MirPass<'tcx> for NoLandingPads {
|
2020-10-04 11:01:38 -07:00
|
|
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
2019-11-06 12:00:46 -05:00
|
|
|
no_landing_pads(tcx, body)
|
2017-04-25 18:23:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-12 10:31:00 -07:00
|
|
|
pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
2021-01-18 00:00:00 +00:00
|
|
|
if tcx.sess.panic_strategy() != PanicStrategy::Abort {
|
|
|
|
return;
|
2019-10-20 16:11:04 -04:00
|
|
|
}
|
|
|
|
|
2021-01-18 00:00:00 +00:00
|
|
|
for block in body.basic_blocks_mut() {
|
|
|
|
let terminator = block.terminator_mut();
|
2020-05-31 12:13:29 +02:00
|
|
|
if let Some(unwind) = terminator.kind.unwind_mut() {
|
2017-11-27 21:50:36 +02:00
|
|
|
unwind.take();
|
2016-02-11 10:13:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|