about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/unaligned_pointers/unaligned_ptr4.rs
blob: b8b01e113c9609e62434e52e1825018daf777c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// This should fail even without validation or Stacked Borrows.
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows -Cdebug-assertions=no

fn main() {
    // Make sure we notice when a u16 is loaded at offset 1 into a u8 allocation.
    // (This would be missed if u8 allocations are *always* at odd addresses.)
    //
    // Try many times as this might work by chance.
    for _ in 0..20 {
        let x = [0u8; 4];
        let ptr = x.as_ptr().wrapping_offset(1).cast::<u16>();
        let _val = unsafe { *ptr }; //~ERROR: but alignment
    }
}