Skip to content

Commit bf45975

Browse files
committed
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.
2 parents 7c8dbd9 + c6817ff commit bf45975

File tree

14 files changed

+57
-114
lines changed

14 files changed

+57
-114
lines changed

src/librustc_codegen_llvm/attributes.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_middle::ty::query::Providers;
1313
use rustc_middle::ty::{self, TyCtxt};
1414
use rustc_session::config::{OptLevel, Sanitizer};
1515
use rustc_session::Session;
16+
use rustc_target::spec::PanicStrategy;
1617

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

src/librustc_codegen_llvm/intrinsic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_middle::ty::{self, Ty};
2222
use rustc_middle::{bug, span_bug};
2323
use rustc_span::Span;
2424
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Primitive};
25+
use rustc_target::spec::PanicStrategy;
2526

2627
use std::cmp::Ordering;
2728
use std::iter;
@@ -804,7 +805,7 @@ fn try_intrinsic(
804805
catch_func: &'ll Value,
805806
dest: &'ll Value,
806807
) {
807-
if bx.sess().no_landing_pads() {
808+
if bx.sess().panic_strategy() == PanicStrategy::Abort {
808809
bx.call(try_func, &[data], None);
809810
// Return 0 unconditionally from the intrinsic call;
810811
// we can never unwind.

src/librustc_codegen_ssa/back/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_session::Session;
3535
use rustc_span::hygiene::ExpnId;
3636
use rustc_span::source_map::SourceMap;
3737
use rustc_span::symbol::{sym, Symbol};
38-
use rustc_target::spec::MergeFunctions;
38+
use rustc_target::spec::{MergeFunctions, PanicStrategy};
3939

4040
use std::any::Any;
4141
use std::fs;
@@ -995,7 +995,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
995995
crate_types: sess.crate_types.borrow().clone(),
996996
each_linked_rlib_for_lto,
997997
lto: sess.lto(),
998-
no_landing_pads: sess.no_landing_pads(),
998+
no_landing_pads: sess.panic_strategy() == PanicStrategy::Abort,
999999
fewer_names: sess.fewer_names(),
10001000
save_temps: sess.opts.cg.save_temps,
10011001
opts: Arc::new(sess.opts.clone()),

src/librustc_interface/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,6 @@ fn test_debugging_options_tracking_hash() {
546546
tracked!(new_llvm_pass_manager, true);
547547
tracked!(no_codegen, true);
548548
tracked!(no_generate_arange_section, true);
549-
tracked!(no_landing_pads, true);
550549
tracked!(no_link, true);
551550
tracked!(no_profiler_runtime, true);
552551
tracked!(osx_rpath_install_name, true);

src/librustc_mir/transform/generator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ use rustc_middle::ty::subst::SubstsRef;
6868
use rustc_middle::ty::GeneratorSubsts;
6969
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
7070
use rustc_target::abi::VariantIdx;
71+
use rustc_target::spec::PanicStrategy;
7172
use std::borrow::Cow;
7273
use std::iter;
7374

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

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

src/librustc_mir/transform/no_landing_pads.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::transform::{MirPass, MirSource};
55
use rustc_middle::mir::visit::MutVisitor;
66
use rustc_middle::mir::*;
77
use rustc_middle::ty::TyCtxt;
8+
use rustc_target::spec::PanicStrategy;
89

910
pub struct NoLandingPads<'tcx> {
1011
tcx: TyCtxt<'tcx>,
@@ -23,7 +24,7 @@ impl<'tcx> MirPass<'tcx> for NoLandingPads<'tcx> {
2324
}
2425

2526
pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
26-
if tcx.sess.no_landing_pads() {
27+
if tcx.sess.panic_strategy() == PanicStrategy::Abort {
2728
NoLandingPads::new(tcx).visit_body(body);
2829
}
2930
}

src/librustc_mir/transform/remove_noop_landing_pads.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use crate::util::patch::MirPatch;
33
use rustc_index::bit_set::BitSet;
44
use rustc_middle::mir::*;
55
use rustc_middle::ty::TyCtxt;
6+
use rustc_target::spec::PanicStrategy;
67

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

1213
pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
13-
if tcx.sess.no_landing_pads() {
14+
if tcx.sess.panic_strategy() == PanicStrategy::Abort {
1415
return;
1516
}
1617
debug!("remove_noop_landing_pads({:?})", body);

src/librustc_mir_build/build/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,6 @@ fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, _abi: Abi) -> b
536536
return false;
537537
}
538538

539-
// We cannot add landing pads, so don't add one.
540-
if tcx.sess.no_landing_pads() {
541-
return false;
542-
}
543-
544539
// This is a special case: some functions have a C abi but are meant to
545540
// unwind anyway. Don't stop them.
546541
match unwind_attr {

src/librustc_session/options.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
878878
"omit DWARF address ranges that give faster lookups"),
879879
no_interleave_lints: bool = (false, parse_no_flag, [UNTRACKED],
880880
"execute lints separately; allows benchmarking individual lints"),
881-
no_landing_pads: bool = (false, parse_no_flag, [TRACKED],
882-
"omit landing pads for unwinding"),
883881
no_leak_check: bool = (false, parse_no_flag, [UNTRACKED],
884882
"disable the 'leak check' for subtyping; unsound, but useful for tests"),
885883
no_link: bool = (false, parse_no_flag, [TRACKED],

src/librustc_session/session.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,6 @@ impl Session {
540540
self.opts.debugging_opts.fewer_names || !more_names
541541
}
542542

543-
pub fn no_landing_pads(&self) -> bool {
544-
self.opts.debugging_opts.no_landing_pads || self.panic_strategy() == PanicStrategy::Abort
545-
}
546543
pub fn unstable_options(&self) -> bool {
547544
self.opts.debugging_opts.unstable_options
548545
}

0 commit comments

Comments
 (0)