diff options
| author | Ben Kimock <kimockb@gmail.com> | 2022-11-10 11:37:28 -0500 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2023-03-23 18:23:06 -0400 |
| commit | 8ccf53332e2ab70fa4efed5716ddcbb61e98dac2 (patch) | |
| tree | 632b4dfa8f9fcdc21d09b8fa93312d0f6a306b00 /library/core/src | |
| parent | e2163008763c326ec4003e07b8e6eef0c98f6204 (diff) | |
A MIR transform that checks pointers are aligned
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/panicking.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index dd0105c0eb4..0d060e123b1 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -159,6 +159,20 @@ fn panic_bounds_check(index: usize, len: usize) -> ! { panic!("index out of bounds: the len is {len} but the index is {index}") } +#[cold] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[track_caller] +#[cfg_attr(not(bootstrap), lang = "panic_misaligned_pointer_dereference")] // needed by codegen for panic on misaligned pointer deref +fn panic_misaligned_pointer_dereference(required: usize, found: usize) -> ! { + if cfg!(feature = "panic_immediate_abort") { + super::intrinsics::abort() + } + + panic!( + "misaligned pointer dereference: address must be a multiple of {required:#x} but is {found:#x}" + ) +} + /// Panic because we cannot unwind out of a function. /// /// This function is called directly by the codegen backend, and must not have |
