panic_immediate_abort: Fix issues from review
This commit is contained in:
parent
fdef3848a0
commit
d3f9788e59
2 changed files with 12 additions and 12 deletions
|
@ -40,13 +40,13 @@ use fmt;
|
||||||
use panic::{Location, PanicInfo};
|
use panic::{Location, PanicInfo};
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
// inline(never) is required even in panic_immediate_abort mode, lest linker error
|
// never inline unless panic_immediate_abort to avoid code bloat at the call sites as much as possible
|
||||||
#[inline(never)]
|
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
|
||||||
#[lang = "panic"]
|
#[lang = "panic"]
|
||||||
pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
|
pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
|
||||||
if cfg!(feature = "panic_immediate_abort") {
|
if cfg!(feature = "panic_immediate_abort") {
|
||||||
unsafe { super::intrinsics::abort() }
|
unsafe { super::intrinsics::abort() }
|
||||||
};
|
}
|
||||||
|
|
||||||
// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
|
// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
|
||||||
// reduce size overhead. The format_args! macro uses str's Display trait to
|
// 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)) -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
// inline(never) is required even in panic_immediate_abort mode, lest linker error
|
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
|
||||||
#[inline(never)]
|
|
||||||
#[lang = "panic_bounds_check"]
|
#[lang = "panic_bounds_check"]
|
||||||
fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
|
fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
|
||||||
index: usize, len: usize) -> ! {
|
index: usize, len: usize) -> ! {
|
||||||
if cfg!(feature = "panic_immediate_abort") {
|
if cfg!(feature = "panic_immediate_abort") {
|
||||||
unsafe { super::intrinsics::abort() }
|
unsafe { super::intrinsics::abort() }
|
||||||
};
|
}
|
||||||
|
|
||||||
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
|
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
|
||||||
len, index), file_line_col)
|
len, index), file_line_col)
|
||||||
|
@ -78,7 +77,7 @@ fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
|
||||||
pub fn panic_fmt(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32)) -> ! {
|
pub fn panic_fmt(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32)) -> ! {
|
||||||
if cfg!(feature = "panic_immediate_abort") {
|
if cfg!(feature = "panic_immediate_abort") {
|
||||||
unsafe { super::intrinsics::abort() }
|
unsafe { super::intrinsics::abort() }
|
||||||
};
|
}
|
||||||
|
|
||||||
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
|
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
|
||||||
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
|
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
|
||||||
|
|
|
@ -335,13 +335,15 @@ pub fn rust_begin_panic(info: &PanicInfo) -> ! {
|
||||||
reason = "used by the panic! macro",
|
reason = "used by the panic! macro",
|
||||||
issue = "0")]
|
issue = "0")]
|
||||||
#[cold]
|
#[cold]
|
||||||
|
// If panic_immediate_abort, inline the abort call,
|
||||||
|
// otherwise avoid inlining because of it is cold path.
|
||||||
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
|
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
|
||||||
#[cfg_attr( feature="panic_immediate_abort" ,inline)]
|
#[cfg_attr( feature="panic_immediate_abort" ,inline)]
|
||||||
pub fn begin_panic_fmt(msg: &fmt::Arguments,
|
pub fn begin_panic_fmt(msg: &fmt::Arguments,
|
||||||
file_line_col: &(&'static str, u32, u32)) -> ! {
|
file_line_col: &(&'static str, u32, u32)) -> ! {
|
||||||
if cfg!(feature = "panic_immediate_abort") {
|
if cfg!(feature = "panic_immediate_abort") {
|
||||||
unsafe { intrinsics::abort() }
|
unsafe { intrinsics::abort() }
|
||||||
};
|
}
|
||||||
|
|
||||||
let (file, line, col) = *file_line_col;
|
let (file, line, col) = *file_line_col;
|
||||||
let info = PanicInfo::internal_constructor(
|
let info = PanicInfo::internal_constructor(
|
||||||
|
@ -404,14 +406,13 @@ fn continue_panic_fmt(info: &PanicInfo) -> ! {
|
||||||
reason = "used by the panic! macro",
|
reason = "used by the panic! macro",
|
||||||
issue = "0")]
|
issue = "0")]
|
||||||
#[cfg_attr(not(test), lang = "begin_panic")]
|
#[cfg_attr(not(test), lang = "begin_panic")]
|
||||||
// avoid code bloat at the call sites as much as possible
|
// never inline unless panic_immediate_abort to avoid code bloat at the call sites as much as possible
|
||||||
// inline(never) is required even in panic_immediate_abort mode, lest linker error
|
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
|
||||||
#[inline(never)]
|
|
||||||
#[cold]
|
#[cold]
|
||||||
pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u32)) -> ! {
|
pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u32)) -> ! {
|
||||||
if cfg!(feature = "panic_immediate_abort") {
|
if cfg!(feature = "panic_immediate_abort") {
|
||||||
unsafe { intrinsics::abort() }
|
unsafe { intrinsics::abort() }
|
||||||
};
|
}
|
||||||
|
|
||||||
// Note that this should be the only allocation performed in this code path.
|
// Note that this should be the only allocation performed in this code path.
|
||||||
// Currently this means that panic!() on OOM will invoke this code path,
|
// Currently this means that panic!() on OOM will invoke this code path,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue