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::{
9
9
} ;
10
10
use rustc_middle:: ty:: { Ty , TyCtxt , TypeAndMut } ;
11
11
use rustc_session:: Session ;
12
- use rustc_target:: spec:: PanicStrategy ;
13
12
14
13
pub struct CheckAlignment ;
15
14
@@ -237,11 +236,10 @@ fn insert_alignment_check<'tcx>(
237
236
required : Operand :: Copy ( alignment) ,
238
237
found : Operand :: Copy ( addr) ,
239
238
} ) ,
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 ,
245
243
} ,
246
244
} ) ;
247
245
}
Original file line number Diff line number Diff line change @@ -166,14 +166,15 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
166
166
#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
167
167
#[ track_caller]
168
168
#[ 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
169
170
fn panic_misaligned_pointer_dereference ( required : usize , found : usize ) -> ! {
170
171
if cfg ! ( feature = "panic_immediate_abort" ) {
171
172
super :: intrinsics:: abort ( )
172
173
}
173
174
174
- panic ! (
175
+ panic_nounwind_fmt ( format_args ! (
175
176
"misaligned pointer dereference: address must be a multiple of {required:#x} but is {found:#x}"
176
- )
177
+ ) )
177
178
}
178
179
179
180
/// Panic because we cannot unwind out of a function.
You can’t perform that action at this time.
0 commit comments