2022-07-08 11:08:32 -05:00
|
|
|
//@compile-flags: -Zmiri-symbolic-alignment-check -Zmiri-permissive-provenance
|
2020-08-16 10:08:34 -05:00
|
|
|
// With the symbolic alignment check, even with intptrcast and without
|
|
|
|
// validation, we want to be *sure* to catch bugs that arise from pointers being
|
|
|
|
// insufficiently aligned. The only way to achieve that is not not let programs
|
|
|
|
// exploit integer information for alignment, so here we test that this is
|
|
|
|
// indeed the case.
|
2020-04-14 02:50:20 -05:00
|
|
|
//
|
|
|
|
// See https://github.com/rust-lang/miri/issues/1074.
|
2019-06-28 03:27:19 -05:00
|
|
|
fn main() {
|
|
|
|
let x = &mut [0u8; 3];
|
|
|
|
let base_addr = x as *mut _ as usize;
|
2020-08-18 03:11:54 -05:00
|
|
|
// Manually make sure the pointer is properly aligned.
|
2022-06-21 13:38:02 -05:00
|
|
|
let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr + 1 };
|
2019-07-27 04:03:12 -05:00
|
|
|
let u16_ptr = base_addr_aligned as *mut u16;
|
2022-06-25 22:30:29 -05:00
|
|
|
unsafe { *u16_ptr = 2 }; //~ERROR memory with alignment 1, but alignment 2 is required
|
2019-06-28 03:27:19 -05:00
|
|
|
println!("{:?}", x);
|
|
|
|
}
|