2021-03-25 12:44:30 +01:00
|
|
|
// Some optimizations remove ZST accesses, thus masking this UB.
|
|
|
|
// compile-flags: -Zmir-opt-level=0
|
2022-03-10 18:56:19 -05:00
|
|
|
// error-pattern: memory access failed: null pointer is not a valid pointer
|
2021-03-25 12:44:30 +01:00
|
|
|
|
2021-04-15 10:00:39 +02:00
|
|
|
#[allow(deref_nullptr)]
|
2018-09-15 16:35:37 +02: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 20:33:08 +02:00
|
|
|
unsafe { std::ptr::null_mut::<[u8; 0]>().write(zst_val) };
|
2018-09-15 16:35:37 +02:00
|
|
|
}
|