]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/dangling_pointers/dyn_size.rs
Add 'src/tools/miri/' from commit '75dd959a3a40eb5b4574f8d2e23aa6efbeb33573'
[rust.git] / src / tools / miri / tests / fail / dangling_pointers / dyn_size.rs
1 // should find the bug even without these, but gets masked by optimizations
2 //@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows -Zmir-opt-level=0
3
4 struct SliceWithHead(u8, [u8]);
5
6 fn main() {
7     let buf = [0u32; 1];
8     // We craft a wide pointer `*const SliceWithHead` such that the unsized tail is only partially allocated.
9     // That should be UB, as the reference is not fully dereferencable.
10     let ptr: *const SliceWithHead = unsafe { std::mem::transmute((&buf, 4usize)) };
11     // Re-borrow that. This should be UB.
12     let _ptr = unsafe { &*ptr }; //~ ERROR: pointer to 5 bytes starting at offset 0 is out-of-bounds
13 }