Add a test for misaligned pointer derefs inside addr_of!
This commit is contained in:
parent
1a5f8bce74
commit
de4dddf155
15
tests/ui/mir/addrof_alignment.rs
Normal file
15
tests/ui/mir/addrof_alignment.rs
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user