Skip to content

Commit d3f9788

Browse files
committed
panic_immediate_abort: Fix issues from review
1 parent fdef384 commit d3f9788

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/libcore/panicking.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ use fmt;
4040
use panic::{Location, PanicInfo};
4141

4242
#[cold]
43-
// inline(never) is required even in panic_immediate_abort mode, lest linker error
44-
#[inline(never)]
43+
// never inline unless panic_immediate_abort to avoid code bloat at the call sites as much as possible
44+
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
4545
#[lang = "panic"]
4646
pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
4747
if cfg!(feature = "panic_immediate_abort") {
4848
unsafe { super::intrinsics::abort() }
49-
};
49+
}
5050

5151
// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
5252
// reduce size overhead. The format_args! macro uses str's Display trait to
@@ -59,14 +59,13 @@ pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
5959
}
6060

6161
#[cold]
62-
// inline(never) is required even in panic_immediate_abort mode, lest linker error
63-
#[inline(never)]
62+
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
6463
#[lang = "panic_bounds_check"]
6564
fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
6665
index: usize, len: usize) -> ! {
6766
if cfg!(feature = "panic_immediate_abort") {
6867
unsafe { super::intrinsics::abort() }
69-
};
68+
}
7069

7170
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
7271
len, index), file_line_col)
@@ -78,7 +77,7 @@ fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
7877
pub fn panic_fmt(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32)) -> ! {
7978
if cfg!(feature = "panic_immediate_abort") {
8079
unsafe { super::intrinsics::abort() }
81-
};
80+
}
8281

8382
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
8483
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe

src/libstd/panicking.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,15 @@ pub fn rust_begin_panic(info: &PanicInfo) -> ! {
335335
reason = "used by the panic! macro",
336336
issue = "0")]
337337
#[cold]
338+
// If panic_immediate_abort, inline the abort call,
339+
// otherwise avoid inlining because of it is cold path.
338340
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
339341
#[cfg_attr( feature="panic_immediate_abort" ,inline)]
340342
pub fn begin_panic_fmt(msg: &fmt::Arguments,
341343
file_line_col: &(&'static str, u32, u32)) -> ! {
342344
if cfg!(feature = "panic_immediate_abort") {
343345
unsafe { intrinsics::abort() }
344-
};
346+
}
345347

346348
let (file, line, col) = *file_line_col;
347349
let info = PanicInfo::internal_constructor(
@@ -404,14 +406,13 @@ fn continue_panic_fmt(info: &PanicInfo) -> ! {
404406
reason = "used by the panic! macro",
405407
issue = "0")]
406408
#[cfg_attr(not(test), lang = "begin_panic")]
407-
// avoid code bloat at the call sites as much as possible
408-
// inline(never) is required even in panic_immediate_abort mode, lest linker error
409-
#[inline(never)]
409+
// never inline unless panic_immediate_abort to avoid code bloat at the call sites as much as possible
410+
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
410411
#[cold]
411412
pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u32)) -> ! {
412413
if cfg!(feature = "panic_immediate_abort") {
413414
unsafe { intrinsics::abort() }
414-
};
415+
}
415416

416417
// Note that this should be the only allocation performed in this code path.
417418
// Currently this means that panic!() on OOM will invoke this code path,

0 commit comments

Comments
 (0)