1 // should find the bug even without validation and stacked borrows, but gets masked by optimizations
2 //@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows -Zmir-opt-level=0
9 // Try many times as this might work by chance.
11 let buf = [0u32; 256];
12 // `buf` is sufficiently aligned for `layout.align` on a `dyn Debug`, but not
13 // for the actual alignment required by `MuchAlign`.
14 // We craft a wide reference `&dyn Debug` with the vtable for `MuchAlign`. That should be UB,
15 // as the reference is not aligned to its dynamic alignment requirements.
16 let mut ptr = &MuchAlign as &dyn std::fmt::Debug;
17 // Overwrite the data part of `ptr` so it points to `buf`.
19 (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8);
21 // Re-borrow that. This should be UB.
22 let _ptr = &*ptr; //~ERROR: alignment 256 is required