2016-02-11 02:13:35 -06:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! This pass removes the unwind branch of all the terminators when the no-landing-pads option is
|
|
|
|
//! specified.
|
|
|
|
|
2016-03-22 10:30:57 -05:00
|
|
|
use rustc::ty::TyCtxt;
|
2016-09-19 15:50:00 -05:00
|
|
|
use rustc::mir::*;
|
2016-02-11 02:13:35 -06:00
|
|
|
use rustc::mir::visit::MutVisitor;
|
2017-11-09 16:49:51 -06:00
|
|
|
use rustc::mir::transform::MirSource;
|
|
|
|
use transform::MirPass;
|
2016-02-11 02:13:35 -06:00
|
|
|
|
|
|
|
pub struct NoLandingPads;
|
|
|
|
|
2017-04-25 17:23:33 -05:00
|
|
|
impl MirPass for NoLandingPads {
|
|
|
|
fn run_pass<'a, 'tcx>(&self,
|
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|
|
|
_: MirSource,
|
|
|
|
mir: &mut Mir<'tcx>) {
|
|
|
|
no_landing_pads(tcx, mir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn no_landing_pads<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &mut Mir<'tcx>) {
|
|
|
|
if tcx.sess.no_landing_pads() {
|
|
|
|
NoLandingPads.visit_mir(mir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 02:13:35 -06:00
|
|
|
impl<'tcx> MutVisitor<'tcx> for NoLandingPads {
|
2016-08-08 20:46:06 -05:00
|
|
|
fn visit_terminator(&mut self,
|
|
|
|
bb: BasicBlock,
|
|
|
|
terminator: &mut Terminator<'tcx>,
|
|
|
|
location: Location) {
|
2016-03-10 08:55:15 -06:00
|
|
|
match terminator.kind {
|
|
|
|
TerminatorKind::Goto { .. } |
|
|
|
|
TerminatorKind::Resume |
|
|
|
|
TerminatorKind::Return |
|
2016-06-08 11:26:19 -05:00
|
|
|
TerminatorKind::Unreachable |
|
2016-12-26 07:34:03 -06:00
|
|
|
TerminatorKind::GeneratorDrop |
|
2017-07-10 14:11:31 -05:00
|
|
|
TerminatorKind::Yield { .. } |
|
2017-10-13 08:36:15 -05:00
|
|
|
TerminatorKind::SwitchInt { .. } |
|
|
|
|
TerminatorKind::FalseEdges { .. } => {
|
2016-02-11 14:57:09 -06:00
|
|
|
/* nothing to do */
|
|
|
|
},
|
2016-05-16 17:06:52 -05:00
|
|
|
TerminatorKind::Call { cleanup: ref mut unwind, .. } |
|
2016-05-25 00:39:32 -05:00
|
|
|
TerminatorKind::Assert { cleanup: ref mut unwind, .. } |
|
2016-05-16 17:06:52 -05:00
|
|
|
TerminatorKind::DropAndReplace { ref mut unwind, .. } |
|
2016-03-10 08:55:15 -06:00
|
|
|
TerminatorKind::Drop { ref mut unwind, .. } => {
|
2016-02-11 02:13:35 -06:00
|
|
|
unwind.take();
|
|
|
|
},
|
|
|
|
}
|
2016-08-08 20:46:06 -05:00
|
|
|
self.super_terminator(bb, terminator, location);
|
2016-02-11 02:13:35 -06:00
|
|
|
}
|
|
|
|
}
|