1 //@compile-flags: -Zmiri-permissive-provenance
3 fn ensure_allocs_can_be_adjacent() {
6 let ptr: *const u64 = &n;
11 if ptr.wrapping_add(1) == ptr2 {
15 panic!("never saw adjacent stack variables?");
19 // The slack between allocations is random.
20 // Loop a few times to hit the zero-slack case.
23 let ptr: *const u64 = &n;
25 // Allocate a new stack variable whose lifetime quickly ends.
26 // If there's a chance that &m == ptr.add(1), then an int-to-ptr cast of
27 // that value will have ambiguous provenance between n and m.
28 // See https://github.com/rust-lang/miri/issues/1866#issuecomment-985770125
31 let _ = &m as *const u64;
34 let iptr = ptr as usize;
35 let zst = (iptr + 8) as *const ();
36 // This is a ZST ptr just at the end of `n`, so it should be valid to deref.
48 let ptr: *const u64 = &n;
50 let iptr = ptr as usize;
52 let start = &*std::ptr::slice_from_raw_parts(iptr as *const (), 1);
53 let end = &*std::ptr::slice_from_raw_parts((iptr + 8) as *const (), 1);
54 assert_eq!(start.len(), end.len());
60 ensure_allocs_can_be_adjacent();