Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove -Z no-landing-pads flag #70175

Merged
merged 4 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, TyCtxt};
use rustc_session::config::{OptLevel, Sanitizer};
use rustc_session::Session;
use rustc_target::spec::PanicStrategy;

use crate::attributes;
use crate::llvm::AttributePlace::Function;
Expand Down Expand Up @@ -270,7 +271,9 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
//
// You can also find more info on why Windows is whitelisted here in:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1302078
if !cx.sess().no_landing_pads() || cx.sess().target.target.options.requires_uwtable {
if cx.sess().panic_strategy() == PanicStrategy::Unwind
|| cx.sess().target.target.options.requires_uwtable
{
attributes::emit_uwtable(llfn, true);
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustc_middle::ty::{self, Ty};
use rustc_middle::{bug, span_bug};
use rustc_span::Span;
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Primitive};
use rustc_target::spec::PanicStrategy;

use std::cmp::Ordering;
use std::iter;
Expand Down Expand Up @@ -804,7 +805,7 @@ fn try_intrinsic(
catch_func: &'ll Value,
dest: &'ll Value,
) {
if bx.sess().no_landing_pads() {
if bx.sess().panic_strategy() == PanicStrategy::Abort {
bx.call(try_func, &[data], None);
// Return 0 unconditionally from the intrinsic call;
// we can never unwind.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rustc_session::Session;
use rustc_span::hygiene::ExpnId;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{sym, Symbol};
use rustc_target::spec::MergeFunctions;
use rustc_target::spec::{MergeFunctions, PanicStrategy};

use std::any::Any;
use std::fs;
Expand Down Expand Up @@ -1021,7 +1021,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
crate_types: sess.crate_types.borrow().clone(),
each_linked_rlib_for_lto,
lto: sess.lto(),
no_landing_pads: sess.no_landing_pads(),
no_landing_pads: sess.panic_strategy() == PanicStrategy::Abort,
fewer_names: sess.fewer_names(),
save_temps: sess.opts.cg.save_temps,
opts: Arc::new(sess.opts.clone()),
Expand Down
1 change: 0 additions & 1 deletion src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ fn test_debugging_options_tracking_hash() {
tracked!(new_llvm_pass_manager, true);
tracked!(no_codegen, true);
tracked!(no_generate_arange_section, true);
tracked!(no_landing_pads, true);
tracked!(no_link, true);
tracked!(no_profiler_runtime, true);
tracked!(osx_rpath_install_name, true);
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::GeneratorSubsts;
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
use rustc_target::abi::VariantIdx;
use rustc_target::spec::PanicStrategy;
use std::borrow::Cow;
use std::iter;

Expand Down Expand Up @@ -978,7 +979,7 @@ fn can_return<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> bool {

fn can_unwind<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> bool {
// Nothing can unwind when landing pads are off.
if tcx.sess.no_landing_pads() {
if tcx.sess.panic_strategy() == PanicStrategy::Abort {
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/transform/no_landing_pads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::transform::{MirPass, MirSource};
use rustc_middle::mir::visit::MutVisitor;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_target::spec::PanicStrategy;

pub struct NoLandingPads<'tcx> {
tcx: TyCtxt<'tcx>,
Expand All @@ -23,7 +24,7 @@ impl<'tcx> MirPass<'tcx> for NoLandingPads<'tcx> {
}

pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if tcx.sess.no_landing_pads() {
if tcx.sess.panic_strategy() == PanicStrategy::Abort {
NoLandingPads::new(tcx).visit_body(body);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/transform/remove_noop_landing_pads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use crate::util::patch::MirPatch;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_target::spec::PanicStrategy;

/// A pass that removes noop landing pads and replaces jumps to them with
/// `None`. This is important because otherwise LLVM generates terrible
/// code for these.
pub struct RemoveNoopLandingPads;

pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if tcx.sess.no_landing_pads() {
if tcx.sess.panic_strategy() == PanicStrategy::Abort {
return;
}
debug!("remove_noop_landing_pads({:?})", body);
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_mir_build/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,6 @@ fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, _abi: Abi) -> b
return false;
}

// We cannot add landing pads, so don't add one.
if tcx.sess.no_landing_pads() {
return false;
}

// This is a special case: some functions have a C abi but are meant to
// unwind anyway. Don't stop them.
match unwind_attr {
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_session/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"omit DWARF address ranges that give faster lookups"),
no_interleave_lints: bool = (false, parse_no_flag, [UNTRACKED],
"execute lints separately; allows benchmarking individual lints"),
no_landing_pads: bool = (false, parse_no_flag, [TRACKED],
"omit landing pads for unwinding"),
no_leak_check: bool = (false, parse_no_flag, [UNTRACKED],
"disable the 'leak check' for subtyping; unsound, but useful for tests"),
no_link: bool = (false, parse_no_flag, [TRACKED],
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,6 @@ impl Session {
self.opts.debugging_opts.fewer_names || !more_names
}

pub fn no_landing_pads(&self) -> bool {
self.opts.debugging_opts.no_landing_pads || self.panic_strategy() == PanicStrategy::Abort
}
pub fn unstable_options(&self) -> bool {
self.opts.debugging_opts.unstable_options
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/mir-opt/generator-tiny.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Tests that generators that cannot return or unwind don't have unnecessary
//! panic branches.

// compile-flags: -Zno-landing-pads
// compile-flags: -C panic=abort
// no-prefer-dynamic

Amanieu marked this conversation as resolved.
Show resolved Hide resolved
#![feature(generators, generator_trait)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
// MIR for `main::{{closure}}#0` 0 generator_resume
// generator_layout = GeneratorLayout { field_tys: [HasDrop], variant_fields: [[], [], [], [_0]], storage_conflicts: BitMatrix { num_rows: 1, num_columns: 1, words: [1], marker: PhantomData } }

fn main::{{closure}}#0(_1: std::pin::Pin<&mut [generator@$DIR/generator-tiny.rs:18:16: 24:6 {u8, HasDrop, ()}]>, _2: u8) -> std::ops::GeneratorState<(), ()> {
debug _x => _10; // in scope 0 at $DIR/generator-tiny.rs:18:17: 18:19
let mut _0: std::ops::GeneratorState<(), ()>; // return place in scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
let _3: HasDrop; // in scope 0 at $DIR/generator-tiny.rs:19:13: 19:15
let mut _4: !; // in scope 0 at $DIR/generator-tiny.rs:20:9: 23:10
let mut _5: (); // in scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
let _6: u8; // in scope 0 at $DIR/generator-tiny.rs:21:13: 21:18
let mut _7: (); // in scope 0 at $DIR/generator-tiny.rs:21:13: 21:18
let _8: (); // in scope 0 at $DIR/generator-tiny.rs:22:13: 22:21
let mut _9: (); // in scope 0 at $DIR/generator-tiny.rs:18:25: 18:25
let _10: u8; // in scope 0 at $DIR/generator-tiny.rs:18:17: 18:19
let mut _11: isize; // in scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
fn main::{{closure}}#0(_1: std::pin::Pin<&mut [generator@$DIR/generator-tiny.rs:19:16: 25:6 {u8, HasDrop, ()}]>, _2: u8) -> std::ops::GeneratorState<(), ()> {
debug _x => _10; // in scope 0 at $DIR/generator-tiny.rs:19:17: 19:19
let mut _0: std::ops::GeneratorState<(), ()>; // return place in scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
let _3: HasDrop; // in scope 0 at $DIR/generator-tiny.rs:20:13: 20:15
let mut _4: !; // in scope 0 at $DIR/generator-tiny.rs:21:9: 24:10
let mut _5: (); // in scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
let _6: u8; // in scope 0 at $DIR/generator-tiny.rs:22:13: 22:18
let mut _7: (); // in scope 0 at $DIR/generator-tiny.rs:22:13: 22:18
let _8: (); // in scope 0 at $DIR/generator-tiny.rs:23:13: 23:21
let mut _9: (); // in scope 0 at $DIR/generator-tiny.rs:19:25: 19:25
let _10: u8; // in scope 0 at $DIR/generator-tiny.rs:19:17: 19:19
let mut _11: isize; // in scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
scope 1 {
debug _d => (((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:18:16: 24:6 {u8, HasDrop, ()}])) as variant#3).0: HasDrop); // in scope 1 at $DIR/generator-tiny.rs:19:13: 19:15
debug _d => (((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:19:16: 25:6 {u8, HasDrop, ()}])) as variant#3).0: HasDrop); // in scope 1 at $DIR/generator-tiny.rs:20:13: 20:15
}

bb0: {
_11 = discriminant((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:18:16: 24:6 {u8, HasDrop, ()}]))); // scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
switchInt(move _11) -> [0u32: bb1, 3u32: bb5, otherwise: bb6]; // scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
_11 = discriminant((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:19:16: 25:6 {u8, HasDrop, ()}]))); // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
switchInt(move _11) -> [0u32: bb1, 3u32: bb5, otherwise: bb6]; // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
}

bb1: {
_10 = move _2; // scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
nop; // scope 0 at $DIR/generator-tiny.rs:19:13: 19:15
(((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:18:16: 24:6 {u8, HasDrop, ()}])) as variant#3).0: HasDrop) = HasDrop; // scope 0 at $DIR/generator-tiny.rs:19:18: 19:25
StorageLive(_4); // scope 1 at $DIR/generator-tiny.rs:20:9: 23:10
goto -> bb2; // scope 1 at $DIR/generator-tiny.rs:20:9: 23:10
_10 = move _2; // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
nop; // scope 0 at $DIR/generator-tiny.rs:20:13: 20:15
(((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:19:16: 25:6 {u8, HasDrop, ()}])) as variant#3).0: HasDrop) = HasDrop; // scope 0 at $DIR/generator-tiny.rs:20:18: 20:25
StorageLive(_4); // scope 1 at $DIR/generator-tiny.rs:21:9: 24:10
goto -> bb2; // scope 1 at $DIR/generator-tiny.rs:21:9: 24:10
}

bb2: {
StorageLive(_6); // scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
StorageLive(_7); // scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
_7 = (); // scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
_0 = std::ops::GeneratorState::<(), ()>::Yielded(move _7); // scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
discriminant((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:18:16: 24:6 {u8, HasDrop, ()}]))) = 3; // scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
return; // scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
StorageLive(_6); // scope 1 at $DIR/generator-tiny.rs:22:13: 22:18
StorageLive(_7); // scope 1 at $DIR/generator-tiny.rs:22:13: 22:18
_7 = (); // scope 1 at $DIR/generator-tiny.rs:22:13: 22:18
_0 = std::ops::GeneratorState::<(), ()>::Yielded(move _7); // scope 1 at $DIR/generator-tiny.rs:22:13: 22:18
discriminant((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:19:16: 25:6 {u8, HasDrop, ()}]))) = 3; // scope 1 at $DIR/generator-tiny.rs:22:13: 22:18
return; // scope 1 at $DIR/generator-tiny.rs:22:13: 22:18
}

bb3: {
StorageDead(_7); // scope 1 at $DIR/generator-tiny.rs:21:17: 21:18
StorageDead(_6); // scope 1 at $DIR/generator-tiny.rs:21:18: 21:19
StorageLive(_8); // scope 1 at $DIR/generator-tiny.rs:22:13: 22:21
_8 = const callee() -> bb4; // scope 1 at $DIR/generator-tiny.rs:22:13: 22:21
StorageDead(_7); // scope 1 at $DIR/generator-tiny.rs:22:17: 22:18
StorageDead(_6); // scope 1 at $DIR/generator-tiny.rs:22:18: 22:19
StorageLive(_8); // scope 1 at $DIR/generator-tiny.rs:23:13: 23:21
_8 = const callee() -> bb4; // scope 1 at $DIR/generator-tiny.rs:23:13: 23:21
// ty::Const
// + ty: fn() {callee}
// + val: Value(Scalar(<ZST>))
// mir::Constant
// + span: $DIR/generator-tiny.rs:22:13: 22:19
// + span: $DIR/generator-tiny.rs:23:13: 23:19
// + literal: Const { ty: fn() {callee}, val: Value(Scalar(<ZST>)) }
}

bb4: {
StorageDead(_8); // scope 1 at $DIR/generator-tiny.rs:22:21: 22:22
_5 = const (); // scope 1 at $DIR/generator-tiny.rs:20:14: 23:10
StorageDead(_8); // scope 1 at $DIR/generator-tiny.rs:23:21: 23:22
_5 = const (); // scope 1 at $DIR/generator-tiny.rs:21:14: 24:10
// ty::Const
// + ty: ()
// + val: Value(Scalar(<ZST>))
// mir::Constant
// + span: $DIR/generator-tiny.rs:20:14: 23:10
// + span: $DIR/generator-tiny.rs:21:14: 24:10
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
goto -> bb2; // scope 1 at $DIR/generator-tiny.rs:20:9: 23:10
goto -> bb2; // scope 1 at $DIR/generator-tiny.rs:21:9: 24:10
}

bb5: {
StorageLive(_4); // scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
StorageLive(_6); // scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
StorageLive(_7); // scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
_6 = move _2; // scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
goto -> bb3; // scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
StorageLive(_4); // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
StorageLive(_6); // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
StorageLive(_7); // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
_6 = move _2; // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
goto -> bb3; // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
}

bb6: {
unreachable; // scope 0 at $DIR/generator-tiny.rs:18:16: 24:6
unreachable; // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6
}
}
27 changes: 0 additions & 27 deletions src/test/run-fail/mir_codegen_no_landing_pads.rs

This file was deleted.

27 changes: 0 additions & 27 deletions src/test/run-fail/mir_codegen_no_landing_pads_diverging.rs

This file was deleted.