mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 04:04:06 +00:00
Auto merge of #70175 - Amanieu:remove_nlp, r=pnkfelix
Remove -Z no-landing-pads flag Since #67502, `-Z no-landing-pads` will cause all attempted unwinds to abort since we don't generate a `try` / `catch`. This previously worked because `__rust_try` was located in libpanic_unwind which is always compiled with `-C panic=unwind`, but `__rust_try` is now directly inline into the crate that uses `catch_unwind`. As such, `-Z no-landing-pads` is now mostly useless and people should use `-C panic=abort` instead.
This commit is contained in:
commit
bf459752d4
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -35,7 +35,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;
|
||||
@ -995,7 +995,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()),
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -536,11 +536,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 {
|
||||
|
@ -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],
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)]
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user