The current alignment check does not include checks for creating misaligned references from raw pointers, which is now added in this patch. When inserting the check we need to be careful with references to field projections (e.g. `&(*ptr).a`), in which case the resulting reference must be aligned according to the field type and not the type of the pointer.
16 lines
287 B
Rust
16 lines
287 B
Rust
//@ run-pass
|
|
//@ compile-flags: -C debug-assertions
|
|
|
|
#[repr(align(8))]
|
|
struct Misalignment {
|
|
a: u8,
|
|
}
|
|
|
|
fn main() {
|
|
let mem = 0u64;
|
|
let ptr = &mem as *const u64 as *const Misalignment;
|
|
unsafe {
|
|
let ptr = ptr.byte_add(1);
|
|
let _ref: &u8 = &(*ptr).a;
|
|
}
|
|
}
|