allow deref of null ptr in test

This commit is contained in:
Aliénore Bouttefeux 2021-04-15 10:00:39 +02:00
parent f76e256086
commit 648638976a
4 changed files with 4 additions and 0 deletions

View file

@ -1,3 +1,4 @@
#[allow(deref_nullptr)]
fn main() {
let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR inbounds test failed: 0x0 is not a valid pointer
panic!("this should never print: {}", x);

View file

@ -1,6 +1,7 @@
// Some optimizations remove ZST accesses, thus masking this UB.
// compile-flags: -Zmir-opt-level=0
#[allow(deref_nullptr)]
fn main() {
let x: () = unsafe { *std::ptr::null() }; //~ ERROR memory access failed: 0x0 is not a valid pointer
panic!("this should never print: {:?}", x);

View file

@ -1,3 +1,4 @@
#[allow(deref_nullptr)]
fn main() {
unsafe { *std::ptr::null_mut() = 0i32 }; //~ ERROR inbounds test failed: 0x0 is not a valid pointer
}

View file

@ -1,6 +1,7 @@
// Some optimizations remove ZST accesses, thus masking this UB.
// compile-flags: -Zmir-opt-level=0
#[allow(deref_nullptr)]
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.