diff options
| author | bors <bors@rust-lang.org> | 2023-06-18 01:58:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-18 01:58:51 +0000 |
| commit | 0c2c243342ec2a2427f0624fac5ac59f0ee6fbcd (patch) | |
| tree | df08bcbf071a40581b4aa501b205d7e0b80fb332 | |
| parent | ed7281e784423249ab85c094aaba81e3b949a65f (diff) | |
| parent | 7a2490eba3f161c81ad243c7d957b337dd70a2af (diff) | |
| download | rust-0c2c243342ec2a2427f0624fac5ac59f0ee6fbcd.tar.gz rust-0c2c243342ec2a2427f0624fac5ac59f0ee6fbcd.zip | |
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`
| -rw-r--r-- | compiler/rustc_mir_transform/src/check_alignment.rs | 10 | ||||
| -rw-r--r-- | library/core/src/panicking.rs | 5 |
2 files changed, 7 insertions, 8 deletions
diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index fd349c07040..856327e6ce6 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -9,7 +9,6 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::{Ty, TyCtxt, TypeAndMut}; use rustc_session::Session; -use rustc_target::spec::PanicStrategy; pub struct CheckAlignment; @@ -241,11 +240,10 @@ fn insert_alignment_check<'tcx>( required: Operand::Copy(alignment), found: Operand::Copy(addr), }), - unwind: if tcx.sess.panic_strategy() == PanicStrategy::Unwind { - UnwindAction::Terminate - } else { - UnwindAction::Unreachable - }, + // The panic symbol that this calls is #[rustc_nounwind]. We never want to insert an + // unwind into unsafe code, because unwinding could make a failing UB check turn into + // much worse UB when we start unwinding. + unwind: UnwindAction::Unreachable, }, }); } diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 81be3fb22ee..f0fcdab00ad 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -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. |
