]> git.lizzy.rs Git - rust.git/commitdiff
with permissive-provenance set, we already treat ptr::invalid correctly
authorRalf Jung <post@ralfj.de>
Tue, 24 May 2022 15:49:11 +0000 (17:49 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 24 May 2022 15:49:11 +0000 (17:49 +0200)
tests/compile-fail/provenance/ptr_invalid.rs [new file with mode: 0644]

diff --git a/tests/compile-fail/provenance/ptr_invalid.rs b/tests/compile-fail/provenance/ptr_invalid.rs
new file mode 100644 (file)
index 0000000..b371103
--- /dev/null
@@ -0,0 +1,10 @@
+// compile-flags: -Zmiri-permissive-provenance
+#![feature(strict_provenance)]
+
+// Ensure that a `ptr::invalid` ptr is truly invalid.
+fn main() {
+    let x = 42;
+    let xptr = &x as *const i32;
+    let xptr_invalid = std::ptr::invalid::<i32>(xptr.expose_addr());
+    let _val = unsafe { *xptr_invalid }; //~ ERROR is not a valid pointer
+}