Skip to content

Commit 2b23786

Browse files
committed
Auto merge of #1994 - RalfJung:unaligned-ptr-test, r=RalfJung
Make sure we notice when a u16 is loaded at offset 1 into a u8 allocation Cc #1990 which would have changed the integer address logic in a way that this bug could not be found any more.
2 parents c6b3f68 + 798dc5a commit 2b23786

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)