2022-06-26 20:14:18 -05:00
|
|
|
// compile-flags: -Zmiri-permissive-provenance
|
|
|
|
|
2021-12-03 14:57:37 -06:00
|
|
|
fn main() {
|
|
|
|
// The slack between allocations is random.
|
|
|
|
// Loop a few times to hit the zero-slack case.
|
|
|
|
for _ in 0..1024 {
|
|
|
|
let n = 0u64;
|
|
|
|
let ptr: *const u64 = &n;
|
|
|
|
|
|
|
|
// Allocate a new stack variable whose lifetime quickly ends.
|
|
|
|
// If there's a chance that &m == ptr.add(1), then an int-to-ptr cast of
|
|
|
|
// that value will have ambiguous provenance between n and m.
|
|
|
|
// See https://github.com/rust-lang/miri/issues/1866#issuecomment-985770125
|
|
|
|
{
|
|
|
|
let m = 0u64;
|
|
|
|
let _ = &m as *const u64;
|
|
|
|
}
|
|
|
|
|
|
|
|
let iptr = ptr as usize;
|
|
|
|
let zst = (iptr + 8) as *const ();
|
2021-12-05 19:33:20 -06:00
|
|
|
// This is a ZST ptr just at the end of `n`, so it should be valid to deref.
|
2021-12-03 14:57:37 -06:00
|
|
|
unsafe { *zst }
|
|
|
|
}
|
|
|
|
}
|