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

@ -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,
},
});
}