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 /tests/ui | |
| parent | e2163008763c326ec4003e07b8e6eef0c98f6204 (diff) | |
| download | rust-8ccf53332e2ab70fa4efed5716ddcbb61e98dac2.tar.gz rust-8ccf53332e2ab70fa4efed5716ddcbb61e98dac2.zip | |
A MIR transform that checks pointers are aligned
Diffstat (limited to 'tests/ui')
| -rw-r--r-- | tests/ui/mir/mir_alignment_check.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/ui/mir/mir_alignment_check.rs b/tests/ui/mir/mir_alignment_check.rs new file mode 100644 index 00000000000..6c964c78bd1 --- /dev/null +++ b/tests/ui/mir/mir_alignment_check.rs @@ -0,0 +1,11 @@ +// run-fail +// compile-flags: -C debug-assertions +// error-pattern: misaligned pointer dereference: address must be a multiple of 0x4 but is + +fn main() { + let mut x = [0u32; 2]; + let ptr: *mut u8 = x.as_mut_ptr().cast::<u8>(); + unsafe { + *(ptr.add(1).cast::<u32>()) = 42; + } +} |
