Skip to content

Commit de4dddf

Browse files
committed
Add a test for misaligned pointer derefs inside addr_of!
1 parent 1a5f8bc commit de4dddf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/ui/mir/addrof_alignment.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-pass
2+
// ignore-wasm32-bare: No panic messages
3+
// compile-flags: -C debug-assertions
4+
5+
struct Misalignment {
6+
a: u32,
7+
}
8+
9+
fn main() {
10+
let items: [Misalignment; 2] = [Misalignment { a: 0 }, Misalignment { a: 1 }];
11+
unsafe {
12+
let ptr: *const Misalignment = items.as_ptr().cast::<u8>().add(1).cast::<Misalignment>();
13+
let _ptr = core::ptr::addr_of!((*ptr).a);
14+
}
15+
}

0 commit comments

Comments
 (0)