Skip to content

Commit fd30646

Browse files
committed
Add panic=immediate-abort
1 parent a09fbe2 commit fd30646

File tree

74 files changed

+544
-160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+544
-160
lines changed

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub fn inject(
6464

6565
if sess.is_test_crate() {
6666
let panic_strategy = match (panic_strategy, sess.opts.unstable_opts.panic_abort_tests) {
67-
(PanicStrategy::Abort, true) => PanicStrategy::Abort,
68-
(PanicStrategy::Abort, false) => {
67+
(PanicStrategy::Abort | PanicStrategy::ImmediateAbort, true) => panic_strategy,
68+
(PanicStrategy::Abort | PanicStrategy::ImmediateAbort, false) => {
6969
if panic_strategy == platform_panic_strategy {
7070
// Silently allow compiling with panic=abort on these platforms,
7171
// but with old behavior (abort if a test fails).
@@ -288,10 +288,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> Box<ast::Item> {
288288
let ecx = &cx.ext_cx;
289289
let test_ident = Ident::new(sym::test, sp);
290290

291-
let runner_name = match cx.panic_strategy {
292-
PanicStrategy::Unwind => "test_main_static",
293-
PanicStrategy::Abort => "test_main_static_abort",
294-
};
291+
let runner_name =
292+
if cx.panic_strategy.unwinds() { "test_main_static" } else { "test_main_static_abort" };
295293

296294
// test::test_main_static(...)
297295
let mut test_runner = cx.test_runner.clone().unwrap_or_else(|| {

compiler/rustc_codegen_gcc/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use rustc_middle::mir::mono::Visibility;
1515
use rustc_middle::ty::TyCtxt;
1616
use rustc_session::config::DebugInfo;
1717
use rustc_span::Symbol;
18+
use rustc_target::spec::RelocModel;
1819
#[cfg(feature = "master")]
1920
use rustc_target::spec::SymbolVisibility;
20-
use rustc_target::spec::{PanicStrategy, RelocModel};
2121

2222
use crate::builder::Builder;
2323
use crate::context::CodegenCx;
@@ -101,7 +101,7 @@ pub fn compile_codegen_unit(
101101
// Instantiate monomorphizations without filling out definitions yet...
102102
let context = new_context(tcx);
103103

104-
if tcx.sess.panic_strategy() == PanicStrategy::Unwind {
104+
if tcx.sess.panic_strategy().unwinds() {
105105
context.add_command_line_option("-fexceptions");
106106
context.add_driver_option("-fexceptions");
107107
}

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_middle::ty::layout::LayoutOf;
2929
use rustc_middle::ty::{self, Instance, Ty};
3030
use rustc_span::{Span, Symbol, sym};
3131
use rustc_target::callconv::{ArgAbi, PassMode};
32-
use rustc_target::spec::PanicStrategy;
3332

3433
#[cfg(feature = "master")]
3534
use crate::abi::FnAbiGccExt;
@@ -1339,7 +1338,7 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(
13391338
_catch_func: RValue<'gcc>,
13401339
dest: PlaceRef<'tcx, RValue<'gcc>>,
13411340
) {
1342-
if bx.sess().panic_strategy() == PanicStrategy::Abort {
1341+
if !bx.sess().panic_strategy().unwinds() {
13431342
bx.call(bx.type_void(), None, None, try_func, &[data], None, None);
13441343
// Return 0 unconditionally from the intrinsic call;
13451344
// we can never unwind.

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_middle::{bug, span_bug};
1818
use rustc_span::{Span, Symbol, sym};
1919
use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
2020
use rustc_target::callconv::PassMode;
21-
use rustc_target::spec::PanicStrategy;
2221
use tracing::debug;
2322

2423
use crate::abi::FnAbiLlvmExt;
@@ -674,7 +673,7 @@ fn catch_unwind_intrinsic<'ll, 'tcx>(
674673
catch_func: &'ll Value,
675674
dest: PlaceRef<'tcx, &'ll Value>,
676675
) {
677-
if bx.sess().panic_strategy() == PanicStrategy::Abort {
676+
if !bx.sess().panic_strategy().unwinds() {
678677
let try_func_ty = bx.type_func(&[bx.type_ptr()], bx.type_void());
679678
bx.call(try_func_ty, None, None, try_func, &[data], None, None);
680679
// Return 0 unconditionally from the intrinsic call;

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ unsafe fn configure_llvm(sess: &Session) {
106106

107107
if sess.target.os == "emscripten"
108108
&& !sess.opts.unstable_opts.emscripten_wasm_eh
109-
&& sess.panic_strategy() == PanicStrategy::Unwind
109+
&& sess.panic_strategy().unwinds()
110110
{
111111
add("-enable-emscripten-cxx-exceptions", false);
112112
}

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ use rustc_span::Symbol;
4747
use rustc_target::spec::crt_objects::CrtObjects;
4848
use rustc_target::spec::{
4949
BinaryFormat, Cc, LinkOutputKind, LinkSelfContainedComponents, LinkSelfContainedDefault,
50-
LinkerFeatures, LinkerFlavor, LinkerFlavorCli, Lld, PanicStrategy, RelocModel, RelroLevel,
51-
SanitizerSet, SplitDebuginfo,
50+
LinkerFeatures, LinkerFlavor, LinkerFlavorCli, Lld, RelocModel, RelroLevel, SanitizerSet,
51+
SplitDebuginfo,
5252
};
5353
use tracing::{debug, info, warn};
5454

@@ -2512,10 +2512,10 @@ fn add_order_independent_options(
25122512
if sess.target.os == "emscripten" {
25132513
cmd.cc_arg(if sess.opts.unstable_opts.emscripten_wasm_eh {
25142514
"-fwasm-exceptions"
2515-
} else if sess.panic_strategy() == PanicStrategy::Abort {
2516-
"-sDISABLE_EXCEPTION_CATCHING=1"
2517-
} else {
2515+
} else if sess.panic_strategy().unwinds() {
25182516
"-sDISABLE_EXCEPTION_CATCHING=0"
2517+
} else {
2518+
"-sDISABLE_EXCEPTION_CATCHING=1"
25192519
});
25202520
}
25212521

compiler/rustc_interface/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ interface_out_dir_error =
4848
failed to find or create the directory specified by `--out-dir`
4949
5050
interface_proc_macro_crate_panic_abort =
51-
building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic
51+
building proc macro crate with `panic=abort` or `panic=immediate-abort` may crash the compiler should the proc-macro panic
5252
5353
interface_temps_dir_error =
5454
failed to find or create the directory specified by `--temps-dir`

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use rustc_span::{
4040
DUMMY_SP, ErrorGuaranteed, ExpnKind, FileName, SourceFileHash, SourceFileHashAlgorithm, Span,
4141
Symbol, sym,
4242
};
43-
use rustc_target::spec::PanicStrategy;
4443
use rustc_trait_selection::{solve, traits};
4544
use tracing::{info, instrument};
4645

@@ -272,7 +271,7 @@ fn configure_and_expand(
272271
feature_err(sess, sym::export_stable, DUMMY_SP, "`sdylib` crate type is unstable").emit();
273272
}
274273

275-
if is_proc_macro_crate && sess.panic_strategy() == PanicStrategy::Abort {
274+
if is_proc_macro_crate && !sess.panic_strategy().unwinds() {
276275
sess.dcx().emit_warn(errors::ProcMacroCratePanicAbort);
277276
}
278277

compiler/rustc_metadata/messages.ftl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ metadata_full_metadata_not_found =
9898
metadata_global_alloc_required =
9999
no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait
100100
101+
metadata_incompatible_with_immediate_abort =
102+
the crate `{$crate_name}` was compiled with a panic strategy which is incompatible with `immediate-abort`
103+
104+
metadata_incompatible_with_immediate_abort_core =
105+
the crate `core` was compiled with a panic strategy which is incompatible with `immediate-abort`
106+
.help = consider building the standard library from source with `cargo build -Zbuild-std`
107+
101108
metadata_incompatible_panic_in_drop_strategy =
102109
the crate `{$crate_name}` is compiled with the panic-in-drop strategy `{$found_strategy}` which is incompatible with this crate's strategy of `{$desired_strategy}`
103110

compiler/rustc_metadata/src/creader.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,10 @@ impl CStore {
10271027
let name = match desired_strategy {
10281028
PanicStrategy::Unwind => sym::panic_unwind,
10291029
PanicStrategy::Abort => sym::panic_abort,
1030+
PanicStrategy::ImmediateAbort => {
1031+
// Immediate-aborting panics don't use a runtime.
1032+
return;
1033+
}
10301034
};
10311035
info!("panic runtime not found -- loading {}", name);
10321036

0 commit comments

Comments
 (0)