From 648638976af2f7331a61921997b0703edb2f4212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Thu, 15 Apr 2021 10:00:39 +0200 Subject: [PATCH] allow deref of null ptr in test --- tests/compile-fail/null_pointer_deref.rs | 1 + tests/compile-fail/null_pointer_deref_zst.rs | 1 + tests/compile-fail/null_pointer_write.rs | 1 + tests/compile-fail/null_pointer_write_zst.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/compile-fail/null_pointer_deref.rs b/tests/compile-fail/null_pointer_deref.rs index bd4758f737e7..ab415d8746d1 100644 --- a/tests/compile-fail/null_pointer_deref.rs +++ b/tests/compile-fail/null_pointer_deref.rs @@ -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); diff --git a/tests/compile-fail/null_pointer_deref_zst.rs b/tests/compile-fail/null_pointer_deref_zst.rs index d0f21a04d364..45925f3586c4 100644 --- a/tests/compile-fail/null_pointer_deref_zst.rs +++ b/tests/compile-fail/null_pointer_deref_zst.rs @@ -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); diff --git a/tests/compile-fail/null_pointer_write.rs b/tests/compile-fail/null_pointer_write.rs index 97c9ee8b1f52..599d2ff7fd5b 100644 --- a/tests/compile-fail/null_pointer_write.rs +++ b/tests/compile-fail/null_pointer_write.rs @@ -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 } diff --git a/tests/compile-fail/null_pointer_write_zst.rs b/tests/compile-fail/null_pointer_write_zst.rs index 1ee1a4b8a303..595011fcd6a7 100644 --- a/tests/compile-fail/null_pointer_write_zst.rs +++ b/tests/compile-fail/null_pointer_write_zst.rs @@ -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.