Skip to content

Commit 6486389

Browse files
committed
allow deref of null ptr in test
1 parent f76e256 commit 6486389

File tree

4 files changed

+4
-0
lines changed

4 files changed

+4
-0
lines changed

tests/compile-fail/null_pointer_deref.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[allow(deref_nullptr)]
12
fn main() {
23
let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR inbounds test failed: 0x0 is not a valid pointer
34
panic!("this should never print: {}", x);

tests/compile-fail/null_pointer_deref_zst.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Some optimizations remove ZST accesses, thus masking this UB.
22
// compile-flags: -Zmir-opt-level=0
33

4+
#[allow(deref_nullptr)]
45
fn main() {
56
let x: () = unsafe { *std::ptr::null() }; //~ ERROR memory access failed: 0x0 is not a valid pointer
67
panic!("this should never print: {:?}", x);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[allow(deref_nullptr)]
12
fn main() {
23
unsafe { *std::ptr::null_mut() = 0i32 }; //~ ERROR inbounds test failed: 0x0 is not a valid pointer
34
}

tests/compile-fail/null_pointer_write_zst.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Some optimizations remove ZST accesses, thus masking this UB.
22
// compile-flags: -Zmir-opt-level=0
33

4+
#[allow(deref_nullptr)]
45
fn main() {
56
// Not using the () type here, as writes of that type do not even have MIR generated.
67
// Also not assigning directly as that's array initialization, not assignment.

0 commit comments

Comments
 (0)