summaryrefslogtreecommitdiffstats
path: root/tests/ui/mir/alignment/i686-pc-windows-msvc.rs
blob: 74ba1fde6499ee09e5bb81d3a4d9ee40880721e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 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];
    let ptr = x.as_mut_ptr();
    unsafe {
        let misaligned = ptr.byte_add(4);
        assert!(misaligned.addr() % 8 != 0);
        assert!(misaligned.addr() % 4 == 0);
        *misaligned = 42;
    }
}