]> git.lizzy.rs Git - rust.git/commitdiff
whitelist std::ptr::read
authorRalf Jung <post@ralfj.de>
Fri, 12 Oct 2018 08:40:44 +0000 (10:40 +0200)
committerRalf Jung <post@ralfj.de>
Fri, 12 Oct 2018 08:40:44 +0000 (10:40 +0200)
src/lib.rs
tests/compiletest.rs
tests/run-pass/call_drop_through_owned_slice.rs
tests/run-pass/issue-29746.rs
tests/run-pass/sendable-class.rs
tests/run-pass/unique-send.rs

index 13b42d8e3c2720227f399b3249bf92d2277ce876..d52fd0028039d5b6aebb3a581159447ac10d6e6c 100644 (file)
@@ -255,9 +255,26 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
 
     const STATIC_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::MutStatic);
 
-    #[inline(always)]
     fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool {
-        ecx.machine.validate
+        if !ecx.machine.validate {
+            return false;
+        }
+
+        // Some functions are whitelisted until we figure out how to fix them.
+        // We walk up the stack a few frames to also cover their callees.
+        const WHITELIST: &[&str] = &[
+            // Uses mem::uninitialized
+            "std::ptr::read",
+        ];
+        for frame in ecx.stack().iter()
+            .rev().take(3)
+        {
+            let name = frame.instance.to_string();
+            if WHITELIST.iter().any(|white| name.starts_with(white)) {
+                return false;
+            }
+        }
+        true
     }
 
     /// Returns Ok() when the function was handled, fail otherwise
index 43989a49b30883a42e252c0a9e8fdddbf036f540..151aa89be3f3af0396a9f64ab5d539d4521f229a 100644 (file)
@@ -103,8 +103,6 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir:
     flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
     if have_fullmir() {
         flags.push("-Zmiri-start-fn".to_owned());
-        // start-fn uses ptr::read, and so fails validation
-        flags.push("-Zmiri-disable-validation".to_owned());
     }
     if opt {
         flags.push("-Zmir-opt-level=3".to_owned());
index b0e336c0480a9f38c717ade5e1e61582c6d1bec1..3ec6be65ed8b6f8bc8bb35d560a42ef3c2f0dfb5 100644 (file)
@@ -1,6 +1,3 @@
-// FIXME validation disabled because ptr::read uses mem::uninitialized
-// compile-flags: -Zmiri-disable-validation
-
 struct Bar;
 
 static mut DROP_COUNT: usize = 0;
index 94ca146db1cdf848997029d2e4bbb0b9180a24ee..61c601ac6a903d887306a55d204b90d153a629b9 100644 (file)
@@ -8,9 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// FIXME validation disabled because ptr::read uses mem::uninitialized
-// compile-flags: -Zmiri-disable-validation
-
 // zip!(a1,a2,a3,a4) is equivalent to:
 //  a1.zip(a2).zip(a3).zip(a4).map(|(((x1,x2),x3),x4)| (x1,x2,x3,x4))
 macro_rules! zip {
index 7ca4e1a90841af77467843d1a11de6e004b914fd..66f0c84e23c1a2d4064e12c507ca2485297278b2 100644 (file)
@@ -8,9 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// FIXME validation disabled because ptr::read uses mem::uninitialized
-// compile-flags: -Zmiri-disable-validation
-
 // Test that a class with only sendable fields can be sent
 
 use std::sync::mpsc::channel;
index 8a48d331f4544028693f8ae466284e001ac3480d..7644da08e4afa7cf144dbbb3a5b0142f687ac5c7 100644 (file)
@@ -8,9 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// FIXME validation disabled because ptr::read uses mem::uninitialized
-// compile-flags: -Zmiri-disable-validation
-
 #![feature(box_syntax)]
 
 use std::sync::mpsc::channel;