]> git.proxmox.com Git - rustc.git/blame - src/librustc_mir/transform/no_landing_pads.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / librustc_mir / transform / no_landing_pads.rs
CommitLineData
7453a54e
SL
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! This pass removes the unwind branch of all the terminators when the no-landing-pads option is
12//! specified.
13
54a0048b 14use rustc::ty::TyCtxt;
7453a54e
SL
15use rustc::mir::repr::*;
16use rustc::mir::visit::MutVisitor;
54a0048b
SL
17use rustc::mir::transform::{Pass, MirPass};
18use syntax::ast::NodeId;
7453a54e
SL
19
20pub struct NoLandingPads;
21
22impl<'tcx> MutVisitor<'tcx> for NoLandingPads {
23 fn visit_terminator(&mut self, bb: BasicBlock, terminator: &mut Terminator<'tcx>) {
54a0048b
SL
24 match terminator.kind {
25 TerminatorKind::Goto { .. } |
26 TerminatorKind::Resume |
27 TerminatorKind::Return |
28 TerminatorKind::If { .. } |
29 TerminatorKind::Switch { .. } |
30 TerminatorKind::SwitchInt { .. } => {
7453a54e
SL
31 /* nothing to do */
32 },
54a0048b 33 TerminatorKind::Drop { ref mut unwind, .. } => {
7453a54e
SL
34 unwind.take();
35 },
54a0048b 36 TerminatorKind::Call { ref mut cleanup, .. } => {
7453a54e
SL
37 cleanup.take();
38 },
39 }
40 self.super_terminator(bb, terminator);
41 }
42}
43
54a0048b
SL
44impl<'tcx> MirPass<'tcx> for NoLandingPads {
45 fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, _: NodeId, mir: &mut Mir<'tcx>) {
46 if tcx.sess.no_landing_pads() {
7453a54e
SL
47 self.visit_mir(mir);
48 }
49 }
50}
54a0048b
SL
51
52impl Pass for NoLandingPads {}