Codegen const panic messages as function calls
This skips emitting extra arguments at every callsite (of which there can be many). For a librustc_driver build with overflow checks enabled, this cuts 0.7MB from the resulting binary.
This commit is contained in:
parent
678e62405f
commit
c8cb091e1e
@ -418,6 +418,36 @@ pub fn panic(_msg: &'static str) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! panic_const {
|
||||
($($lang:ident = $message:expr,)+) => {
|
||||
#[cfg(not(bootstrap))]
|
||||
pub mod panic_const {
|
||||
use super::*;
|
||||
|
||||
$(
|
||||
#[track_caller]
|
||||
#[lang = stringify!($lang)]
|
||||
pub fn $lang() -> ! {
|
||||
panic($message);
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
panic_const! {
|
||||
panic_const_add_overflow = "attempt to add with overflow",
|
||||
panic_const_sub_overflow = "attempt to subtract with overflow",
|
||||
panic_const_mul_overflow = "attempt to multiply with overflow",
|
||||
panic_const_div_overflow = "attempt to divide with overflow",
|
||||
panic_const_rem_overflow = "attempt to calculate the remainder with overflow",
|
||||
panic_const_neg_overflow = "attempt to negate with overflow",
|
||||
panic_const_shr_overflow = "attempt to shift right with overflow",
|
||||
panic_const_shl_overflow = "attempt to shift left with overflow",
|
||||
panic_const_div_by_zero = "attempt to divide by zero",
|
||||
panic_const_rem_by_zero = "attempt to calculate the remainder with a divisor of zero",
|
||||
}
|
||||
|
||||
#[lang = "panic_cannot_unwind"]
|
||||
fn panic_cannot_unwind() -> ! {
|
||||
unsafe {
|
||||
|
Loading…
x
Reference in New Issue
Block a user