2020-04-18 02:15:59 -05:00
|
|
|
// should find the bug even without these, but gets masked by optimizations
|
2022-07-08 11:08:32 -05:00
|
|
|
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows -Zmir-opt-level=0
|
2020-04-17 19:06:36 -05:00
|
|
|
|
|
|
|
struct SliceWithHead(u8, [u8]);
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let buf = [0u32; 1];
|
|
|
|
// We craft a wide pointer `*const SliceWithHead` such that the unsized tail is only partially allocated.
|
|
|
|
// That should be UB, as the reference is not fully dereferencable.
|
|
|
|
let ptr: *const SliceWithHead = unsafe { std::mem::transmute((&buf, 4usize)) };
|
|
|
|
// Re-borrow that. This should be UB.
|
2022-07-11 06:44:55 -05:00
|
|
|
let _ptr = unsafe { &*ptr }; //~ ERROR: pointer to 5 bytes starting at offset 0 is out-of-bounds
|
2020-04-17 19:06:36 -05:00
|
|
|
}
|