Skip to content

Commit 798dc5a

Browse files
committed
Make sure we notice when a u16 is loaded at offset 1 into a u8 allocation
1 parent c6b3f68 commit 798dc5a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This should fail even without validation or Stacked Borrows.
2+
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
3+
4+
fn main() {
5+
// Make sure we notice when a u16 is loaded at offset 1 into a u8 allocation.
6+
// (This would be missed if u8 allocations are *always* at odd addresses.)
7+
for _ in 0..10 { // Try many times as this might work by chance.
8+
let x = [0u8; 4];
9+
let ptr = x.as_ptr().wrapping_offset(1).cast::<u16>();
10+
let _val = unsafe { *ptr }; //~ERROR but alignment
11+
}
12+
}

0 commit comments

Comments
 (0)