Skip to content

Commit

Permalink
Add a test for misaligned pointer derefs inside addr_of!
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin authored and Mark-Simulacrum committed May 30, 2023
1 parent 8b07c88 commit 655516b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/ui/mir/addrof_alignment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// run-pass
// ignore-wasm32-bare: No panic messages
// compile-flags: -C debug-assertions

struct Misalignment {
a: u32,
}

fn main() {
let items: [Misalignment; 2] = [Misalignment { a: 0 }, Misalignment { a: 1 }];
unsafe {
let ptr: *const Misalignment = items.as_ptr().cast::<u8>().add(1).cast::<Misalignment>();
let _ptr = core::ptr::addr_of!((*ptr).a);
}
}

0 comments on commit 655516b

Please sign in to comment.