Skip to content

Commit c186ebd

Browse files
committed
A MIR transform that checks pointers are aligned
1 parent df79603 commit c186ebd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/src/panicking.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
159159
panic!("index out of bounds: the len is {len} but the index is {index}")
160160
}
161161

162+
#[cold]
163+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
164+
#[track_caller]
165+
#[cfg_attr(not(bootstrap), lang = "panic_misaligned_pointer_dereference")] // needed by codegen for panic on misaligned pointer deref
166+
fn panic_misaligned_pointer_dereference(required: usize, found: usize) -> ! {
167+
if cfg!(feature = "panic_immediate_abort") {
168+
super::intrinsics::abort()
169+
}
170+
171+
panic!(
172+
"misaligned pointer dereference: address must be a multiple of {required:#x} but is {found:#x}"
173+
)
174+
}
175+
162176
/// Panic because we cannot unwind out of a function.
163177
///
164178
/// This function is called directly by the codegen backend, and must not have

0 commit comments

Comments
 (0)