rust/tests/fail/unaligned_pointers/reference_to_packed.rs

20 lines
451 B
Rust
Raw Normal View History

// This should fail even without validation/SB
2022-07-08 11:08:32 -05:00
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
2021-03-27 19:36:41 -05:00
#![allow(dead_code, unused_variables, unaligned_references)]
2017-01-31 03:36:46 -06:00
#[repr(packed)]
struct Foo {
x: i32,
y: i32,
}
fn main() {
2022-06-22 01:48:09 -05:00
// Try many times as this might work by chance.
for _ in 0..10 {
let foo = Foo { x: 42, y: 99 };
2021-03-27 19:36:41 -05:00
let p = &foo.x;
2022-05-25 11:15:37 -05:00
let i = *p; //~ERROR alignment 4 is required
}
2017-06-22 23:01:24 -05:00
}