2021-03-25 06:44:30 -05:00
|
|
|
// Some optimizations remove ZST accesses, thus masking this UB.
|
2022-07-05 04:15:22 -05:00
|
|
|
//@compile-flags: -Zmir-opt-level=0
|
2021-03-25 06:44:30 -05:00
|
|
|
|
2021-04-15 03:00:39 -05:00
|
|
|
#[allow(deref_nullptr)]
|
2018-09-15 09:35:37 -05:00
|
|
|
fn main() {
|
|
|
|
// Not using the () type here, as writes of that type do not even have MIR generated.
|
|
|
|
// Also not assigning directly as that's array initialization, not assignment.
|
|
|
|
let zst_val = [1u8; 0];
|
2021-07-15 13:33:08 -05:00
|
|
|
unsafe { std::ptr::null_mut::<[u8; 0]>().write(zst_val) };
|
2022-07-24 07:37:29 -05:00
|
|
|
//~^ERROR: memory access failed: null pointer is a dangling pointer
|
2018-09-15 09:35:37 -05:00
|
|
|
}
|