whitelist std::ptr::read

This commit is contained in:
Ralf Jung 2018-10-12 10:40:44 +02:00
parent 26f9d617c3
commit 62b819ba18
6 changed files with 19 additions and 16 deletions

View 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

View 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());

View 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;

View 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 {

View 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;

View 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;