]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_mir/src/transform/no_landing_pads.rs
Rollup merge of #82789 - csmoe:issue-82772, r=estebank
[rust.git] / compiler / rustc_mir / src / transform / no_landing_pads.rs
1 //! This pass removes the unwind branch of all the terminators when the no-landing-pads option is
2 //! specified.
3
4 use crate::transform::MirPass;
5 use rustc_middle::mir::*;
6 use rustc_middle::ty::TyCtxt;
7 use rustc_target::spec::PanicStrategy;
8
9 pub struct NoLandingPads;
10
11 impl<'tcx> MirPass<'tcx> for NoLandingPads {
12     fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
13         no_landing_pads(tcx, body)
14     }
15 }
16
17 pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
18     if tcx.sess.panic_strategy() != PanicStrategy::Abort {
19         return;
20     }
21
22     for block in body.basic_blocks_mut() {
23         let terminator = block.terminator_mut();
24         if let Some(unwind) = terminator.kind.unwind_mut() {
25             unwind.take();
26         }
27     }
28 }