Skip to content

Commit 234990c

Browse files
committed
Auto merge of #105997 - RalfJung:immediate-abort, r=eholk
abort immediately on bad mem::zeroed/uninit Now that we have non-unwinding panics, let's use them for these assertions. This re-establishes the property that `mem::uninitialized` and `mem::zeroed` will never unwind -- the earlier approach of causing panics here sometimes led to hard-to-debug segfaults when the surrounding code was not able to cope with the unexpected unwinding. Cc `@bjorn3` I did not touch cranelift but I assume it needs a similar patch. However it has a `codegen_panic` abstraction that I did not want to touch since I didn't know how else it is used.
2 parents 88b6c87 + 6644b43 commit 234990c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

core/src/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ macro_rules! assert_unsafe_precondition {
22812281
fn runtime$(<$($tt)*>)?($($i:$ty),*) {
22822282
if !$e {
22832283
// don't unwind to reduce impact on code size
2284-
::core::panicking::panic_str_nounwind(
2284+
::core::panicking::panic_nounwind(
22852285
concat!("unsafe precondition(s) violated: ", $name)
22862286
);
22872287
}

core/src/panicking.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
6464
unsafe { panic_impl(&pi) }
6565
}
6666

67-
/// Like panic_fmt, but without unwinding and track_caller to reduce the impact on codesize.
68-
/// Also just works on `str`, as a `fmt::Arguments` needs more space to be passed.
67+
/// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize.
68+
/// (No `fmt` variant as a `fmt::Arguments` needs more space to be passed.)
6969
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
7070
#[cfg_attr(feature = "panic_immediate_abort", inline)]
71+
#[cfg_attr(not(bootstrap), lang = "panic_nounwind")] // needed by codegen for non-unwinding panics
7172
#[rustc_nounwind]
72-
pub fn panic_str_nounwind(msg: &'static str) -> ! {
73+
pub fn panic_nounwind(msg: &'static str) -> ! {
7374
if cfg!(feature = "panic_immediate_abort") {
7475
super::intrinsics::abort()
7576
}
@@ -153,10 +154,11 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
153154
/// any extra arguments (including those synthesized by track_caller).
154155
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
155156
#[cfg_attr(feature = "panic_immediate_abort", inline)]
156-
#[lang = "panic_no_unwind"] // needed by codegen for panic in nounwind function
157+
#[cfg_attr(bootstrap, lang = "panic_no_unwind")] // needed by codegen for panic in nounwind function
158+
#[cfg_attr(not(bootstrap), lang = "panic_cannot_unwind")] // needed by codegen for panic in nounwind function
157159
#[rustc_nounwind]
158-
fn panic_no_unwind() -> ! {
159-
panic_str_nounwind("panic in a function that cannot unwind")
160+
fn panic_cannot_unwind() -> ! {
161+
panic_nounwind("panic in a function that cannot unwind")
160162
}
161163

162164
/// This function is used instead of panic_fmt in const eval.

0 commit comments

Comments
 (0)