1
Fork 0

Auto merge of #112599 - saethlin:cleaner-panics, r=thomcc

Launch a non-unwinding panic for misaligned pointer deref

This panic already never unwinds, but that's only because it always hits the unwind guard that's created by our `UnwindAction::Terminate`. Hitting the unwind guard generates a huge double-panic backtrace. Now we generate a normal-looking panic message when this check is hit.

r? `@thomcc`
This commit is contained in:
bors 2023-06-18 01:58:51 +00:00
commit 0c2c243342
2 changed files with 7 additions and 8 deletions

View file

@ -166,14 +166,15 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[track_caller]
#[lang = "panic_misaligned_pointer_dereference"] // needed by codegen for panic on misaligned pointer deref
#[rustc_nounwind] // `CheckAlignment` MIR pass requires this function to never unwind
fn panic_misaligned_pointer_dereference(required: usize, found: usize) -> ! {
if cfg!(feature = "panic_immediate_abort") {
super::intrinsics::abort()
}
panic!(
panic_nounwind_fmt(format_args!(
"misaligned pointer dereference: address must be a multiple of {required:#x} but is {found:#x}"
)
))
}
/// Panic because we cannot unwind out of a function.