This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +7
-8
lines changed
compiler/rustc_mir_transform/src Expand file tree Collapse file tree 2 files changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ use rustc_middle::mir::{
99} ;
1010use rustc_middle:: ty:: { Ty , TyCtxt , TypeAndMut } ;
1111use rustc_session:: Session ;
12- use rustc_target:: spec:: PanicStrategy ;
1312
1413pub struct CheckAlignment ;
1514
@@ -237,11 +236,10 @@ fn insert_alignment_check<'tcx>(
237236 required : Operand :: Copy ( alignment) ,
238237 found : Operand :: Copy ( addr) ,
239238 } ) ,
240- unwind : if tcx. sess . panic_strategy ( ) == PanicStrategy :: Unwind {
241- UnwindAction :: Terminate
242- } else {
243- UnwindAction :: Unreachable
244- } ,
239+ // The panic symbol that this calls is #[rustc_nounwind]. We never want to insert an
240+ // unwind into unsafe code, because unwinding could make a failing UB check turn into
241+ // much worse UB when we start unwinding.
242+ unwind : UnwindAction :: Unreachable ,
245243 } ,
246244 } ) ;
247245}
Original file line number Diff line number Diff line change @@ -166,14 +166,15 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
166166#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
167167#[ track_caller]
168168#[ lang = "panic_misaligned_pointer_dereference" ] // needed by codegen for panic on misaligned pointer deref
169+ #[ rustc_nounwind] // `CheckAlignment` MIR pass requires this function to never unwind
169170fn panic_misaligned_pointer_dereference ( required : usize , found : usize ) -> ! {
170171 if cfg ! ( feature = "panic_immediate_abort" ) {
171172 super :: intrinsics:: abort ( )
172173 }
173174
174- panic ! (
175+ panic_nounwind_fmt ( format_args ! (
175176 "misaligned pointer dereference: address must be a multiple of {required:#x} but is {found:#x}"
176- )
177+ ) )
177178}
178179
179180/// Panic because we cannot unwind out of a function.
You can’t perform that action at this time.
0 commit comments