]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/dangling_pointers/null_pointer_write_zst.rs
Rollup merge of #102187 - b-naber:inline-const-source-info, r=eholk
[rust.git] / src / tools / miri / tests / fail / dangling_pointers / null_pointer_write_zst.rs
1 // Some optimizations remove ZST accesses, thus masking this UB.
2 //@compile-flags: -Zmir-opt-level=0
3
4 #[allow(deref_nullptr)]
5 fn main() {
6     // Not using the () type here, as writes of that type do not even have MIR generated.
7     // Also not assigning directly as that's array initialization, not assignment.
8     let zst_val = [1u8; 0];
9     unsafe { std::ptr::null_mut::<[u8; 0]>().write(zst_val) };
10     //~^ERROR: memory access failed: null pointer is a dangling pointer
11 }