diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index ba286e5f40d2d..6ef303c848dc3 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -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; @@ -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); } diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 86d10e91d6de4..ddf21ff6338eb 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -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; @@ -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. diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index c84f38670f77b..4bc377a6d1777 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -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; @@ -1021,7 +1021,7 @@ fn start_executing_work( 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()), diff --git a/src/librustc_interface/tests.rs b/src/librustc_interface/tests.rs index cee2e5b5becdb..0b3ba73f86a86 100644 --- a/src/librustc_interface/tests.rs +++ b/src/librustc_interface/tests.rs @@ -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); diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 611d03405e2c8..00caa06a6c0ff 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -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; @@ -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; } diff --git a/src/librustc_mir/transform/no_landing_pads.rs b/src/librustc_mir/transform/no_landing_pads.rs index d89c8e72e526a..3bffafa1b2f9c 100644 --- a/src/librustc_mir/transform/no_landing_pads.rs +++ b/src/librustc_mir/transform/no_landing_pads.rs @@ -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>, @@ -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); } } diff --git a/src/librustc_mir/transform/remove_noop_landing_pads.rs b/src/librustc_mir/transform/remove_noop_landing_pads.rs index 44a68a8040f15..a86ef7f2f522a 100644 --- a/src/librustc_mir/transform/remove_noop_landing_pads.rs +++ b/src/librustc_mir/transform/remove_noop_landing_pads.rs @@ -3,6 +3,7 @@ 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 @@ -10,7 +11,7 @@ use rustc_middle::ty::TyCtxt; 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); diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index 69a04e772ecee..5a1a6c7bbf790 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -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 { diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs index 5b983d1105de4..be78d46b98196 100644 --- a/src/librustc_session/options.rs +++ b/src/librustc_session/options.rs @@ -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], diff --git a/src/librustc_session/session.rs b/src/librustc_session/session.rs index 42f9a8d6b0594..3b7c2f268ce5d 100644 --- a/src/librustc_session/session.rs +++ b/src/librustc_session/session.rs @@ -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 } diff --git a/src/test/mir-opt/generator-tiny.rs b/src/test/mir-opt/generator-tiny.rs index b537263dd1b72..c86e2865ca8a4 100644 --- a/src/test/mir-opt/generator-tiny.rs +++ b/src/test/mir-opt/generator-tiny.rs @@ -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 #![feature(generators, generator_trait)] diff --git a/src/test/mir-opt/generator-tiny/rustc.main-{{closure}}.generator_resume.0.mir b/src/test/mir-opt/generator-tiny/rustc.main-{{closure}}.generator_resume.0.mir index 84b8af5d6b7bc..75c2fb3d1307d 100644 --- a/src/test/mir-opt/generator-tiny/rustc.main-{{closure}}.generator_resume.0.mir +++ b/src/test/mir-opt/generator-tiny/rustc.main-{{closure}}.generator_resume.0.mir @@ -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()) // 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()) } } 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()) // 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()) } - 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 } } diff --git a/src/test/run-fail/mir_codegen_no_landing_pads.rs b/src/test/run-fail/mir_codegen_no_landing_pads.rs deleted file mode 100644 index f3384dc45f3d2..0000000000000 --- a/src/test/run-fail/mir_codegen_no_landing_pads.rs +++ /dev/null @@ -1,27 +0,0 @@ -// compile-flags: -Z no-landing-pads -C codegen-units=1 -// error-pattern:converging_fn called -// ignore-cloudabi no std::process - -use std::io::{self, Write}; - -struct Droppable; -impl Drop for Droppable { - fn drop(&mut self) { - ::std::process::exit(1) - } -} - -fn converging_fn() { - panic!("converging_fn called") -} - -fn mir(d: Droppable) { - let x = Droppable; - converging_fn(); - drop(x); - drop(d); -} - -fn main() { - mir(Droppable); -} diff --git a/src/test/run-fail/mir_codegen_no_landing_pads_diverging.rs b/src/test/run-fail/mir_codegen_no_landing_pads_diverging.rs deleted file mode 100644 index 08f6d578bb2e0..0000000000000 --- a/src/test/run-fail/mir_codegen_no_landing_pads_diverging.rs +++ /dev/null @@ -1,27 +0,0 @@ -// compile-flags: -Z no-landing-pads -C codegen-units=1 -// error-pattern:diverging_fn called -// ignore-cloudabi no std::process - -use std::io::{self, Write}; - -struct Droppable; -impl Drop for Droppable { - fn drop(&mut self) { - ::std::process::exit(1) - } -} - -fn diverging_fn() -> ! { - panic!("diverging_fn called") -} - -fn mir(d: Droppable) { - let x = Droppable; - diverging_fn(); - drop(x); - drop(d); -} - -fn main() { - mir(Droppable); -}