rust/src/librustc_mir/transform/no_landing_pads.rs

45 lines
1.2 KiB
Rust
Raw Normal View History

//! This pass removes the unwind branch of all the terminators when the no-landing-pads option is
//! specified.
use rustc::ty::TyCtxt;
2016-09-19 23:50:00 +03:00
use rustc::mir::*;
use rustc::mir::visit::MutVisitor;
2019-02-08 06:28:15 +09:00
use crate::transform::{MirPass, MirSource};
2019-10-20 16:11:04 -04:00
pub struct NoLandingPads<'tcx> {
tcx: TyCtxt<'tcx>,
}
impl<'tcx> NoLandingPads<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
NoLandingPads { tcx }
}
}
2019-10-20 16:11:04 -04:00
impl<'tcx> MirPass<'tcx> for NoLandingPads<'tcx> {
fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body_cache: &mut BodyCache<'tcx>) {
2019-10-27 22:45:02 -04:00
no_landing_pads(tcx, body_cache)
}
}
pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body_cache: &mut BodyCache<'tcx>) {
if tcx.sess.no_landing_pads() {
NoLandingPads::new(tcx).visit_body(body_cache);
}
}
2019-10-20 16:11:04 -04:00
impl<'tcx> MutVisitor<'tcx> for NoLandingPads<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
fn visit_terminator_kind(&mut self,
kind: &mut TerminatorKind<'tcx>,
location: Location) {
if let Some(unwind) = kind.unwind_mut() {
unwind.take();
}
self.super_terminator_kind(kind, location);
}
}