From 62b819ba18a4a32833bb823afeb32778fd28bbde Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 12 Oct 2018 10:40:44 +0200 Subject: [PATCH] whitelist std::ptr::read --- src/lib.rs | 21 +++++++++++++++++-- tests/compiletest.rs | 2 -- .../run-pass/call_drop_through_owned_slice.rs | 3 --- tests/run-pass/issue-29746.rs | 3 --- tests/run-pass/sendable-class.rs | 3 --- tests/run-pass/unique-send.rs | 3 --- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 13b42d8e3c27..d52fd0028039 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -255,9 +255,26 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> { const STATIC_KIND: Option = 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 diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 43989a49b308..151aa89be3f3 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -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()); diff --git a/tests/run-pass/call_drop_through_owned_slice.rs b/tests/run-pass/call_drop_through_owned_slice.rs index b0e336c0480a..3ec6be65ed8b 100644 --- a/tests/run-pass/call_drop_through_owned_slice.rs +++ b/tests/run-pass/call_drop_through_owned_slice.rs @@ -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; diff --git a/tests/run-pass/issue-29746.rs b/tests/run-pass/issue-29746.rs index 94ca146db1cd..61c601ac6a90 100644 --- a/tests/run-pass/issue-29746.rs +++ b/tests/run-pass/issue-29746.rs @@ -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 { diff --git a/tests/run-pass/sendable-class.rs b/tests/run-pass/sendable-class.rs index 7ca4e1a90841..66f0c84e23c1 100644 --- a/tests/run-pass/sendable-class.rs +++ b/tests/run-pass/sendable-class.rs @@ -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; diff --git a/tests/run-pass/unique-send.rs b/tests/run-pass/unique-send.rs index 8a48d331f454..7644da08e4af 100644 --- a/tests/run-pass/unique-send.rs +++ b/tests/run-pass/unique-send.rs @@ -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;