diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2024-03-17 22:26:39 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2024-03-22 09:55:50 -0400 |
| commit | 00f4daa27673a07bf9ad20f4707d97bc1079450f (patch) | |
| tree | eef31d06035d56a9abaabb0d0cd3b972d84a4b0b /compiler/rustc_codegen_gcc/example | |
| parent | 0ad927c0c07b65fc0dae37105e09c877c87c296a (diff) | |
| download | rust-00f4daa27673a07bf9ad20f4707d97bc1079450f.tar.gz rust-00f4daa27673a07bf9ad20f4707d97bc1079450f.zip | |
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.
Diffstat (limited to 'compiler/rustc_codegen_gcc/example')
| -rw-r--r-- | compiler/rustc_codegen_gcc/example/mini_core.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index a868471ed1d..4665009e191 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -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 { |
