2023-06-15 17:02:55 -05:00
|
|
|
//@ run-pass
|
|
|
|
//@ only-i686-pc-windows-msvc
|
|
|
|
//@ compile-flags: -Copt-level=0 -Cdebug-assertions=yes
|
|
|
|
|
|
|
|
// MSVC isn't sure if on 32-bit Windows its u64 type is 8-byte-aligned or 4-byte-aligned.
|
|
|
|
// So this test ensures that on i686-pc-windows-msvc, we do not insert a runtime check
|
|
|
|
// that will fail on dereferencing of a pointer to u64 which is not 8-byte-aligned but is
|
|
|
|
// 4-byte-aligned.
|
|
|
|
|
|
|
|
#![feature(strict_provenance)]
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut x = [0u64; 2];
|
2023-07-04 13:23:16 -05:00
|
|
|
let ptr = x.as_mut_ptr();
|
2023-06-15 17:02:55 -05:00
|
|
|
unsafe {
|
2023-07-04 13:23:16 -05:00
|
|
|
let misaligned = ptr.byte_add(4);
|
2023-06-15 17:02:55 -05:00
|
|
|
assert!(misaligned.addr() % 8 != 0);
|
|
|
|
assert!(misaligned.addr() % 4 == 0);
|
|
|
|
*misaligned = 42;
|
|
|
|
}
|
|
|
|
}
|