stub Retag hook; fix tests for removal of -Zmir-emit-validate
This commit is contained in:
parent
fba55ba2a9
commit
7ac0e79ad5
32 changed files with 77 additions and 44 deletions
16
src/lib.rs
16
src/lib.rs
|
|
@ -26,7 +26,7 @@ use syntax::attr;
|
|||
|
||||
|
||||
pub use rustc_mir::interpret::*;
|
||||
pub use rustc_mir::interpret::{self, AllocMap}; // resolve ambiguity
|
||||
pub use rustc_mir::interpret::{self, AllocMap, PlaceTy}; // resolve ambiguity
|
||||
|
||||
mod fn_call;
|
||||
mod operator;
|
||||
|
|
@ -521,4 +521,18 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
|
|||
Ok(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn retag(
|
||||
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
|
||||
fn_entry: bool,
|
||||
place: PlaceTy<'tcx, Borrow>,
|
||||
) -> EvalResult<'tcx> {
|
||||
if !ecx.tcx.sess.opts.debugging_opts.mir_emit_retag || !ecx.machine.validate {
|
||||
// No tracking, or no retagging. This is possible because a dependency of ours might be
|
||||
// called with different flags than we are,
|
||||
return Ok(())
|
||||
}
|
||||
ecx.retag(fn_entry, place)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use rustc::hir;
|
|||
|
||||
use super::{
|
||||
MemoryAccess, MemoryKind, MiriMemoryKind, RangeMap, EvalResult, AllocId,
|
||||
Pointer,
|
||||
Pointer, PlaceTy,
|
||||
};
|
||||
|
||||
pub type Timestamp = u64;
|
||||
|
|
@ -362,6 +362,12 @@ pub trait EvalContextExt<'tcx> {
|
|||
id: AllocId,
|
||||
kind: MemoryKind<MiriMemoryKind>,
|
||||
) -> Borrow;
|
||||
|
||||
fn retag(
|
||||
&mut self,
|
||||
fn_entry: bool,
|
||||
place: PlaceTy<'tcx, Borrow>
|
||||
) -> EvalResult<'tcx>;
|
||||
}
|
||||
|
||||
impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, 'tcx> {
|
||||
|
|
@ -506,4 +512,13 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
|
|||
alloc.extra.first_borrow(mut_borrow, size);
|
||||
Borrow::Mut(mut_borrow)
|
||||
}
|
||||
|
||||
fn retag(
|
||||
&mut self,
|
||||
_fn_entry: bool,
|
||||
_place: PlaceTy<'tcx, Borrow>
|
||||
) -> EvalResult<'tcx> {
|
||||
// TODO do something
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation changes why we fail
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
// error-pattern: tried to deallocate Stack memory but gave Machine(Rust) as the kind
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let b = Box::new(42);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let g = unsafe {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
#![feature(box_syntax)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
use std::mem;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
assert!(std::char::from_u32(-1_i32 as u32).is_none());
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
// error-pattern: invalid enum discriminant
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
#![feature(never_type)]
|
||||
#![allow(unreachable_code)]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
#![feature(never_type)]
|
||||
#![allow(unreachable_code)]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
#![feature(never_type)]
|
||||
#![allow(unreachable_code)]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// FIXME: Something in panic handling fails validation with full-MIR
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
//error-pattern: the evaluated program panicked
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
static X: usize = 5;
|
||||
|
||||
#[allow(mutable_transmutes)]
|
||||
fn main() {
|
||||
let _x = unsafe {
|
||||
std::mem::transmute::<&usize, &mut usize>(&X) //~ ERROR mutable reference with frozen tag
|
||||
};
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation detects that we are casting & to &mut and so it changes why we fail
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
static X: usize = 5;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation detects that we are casting & to &mut and so it changes why we fail
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
use std::mem::transmute;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Validation detects that we are casting & to &mut and so it changes why we fail
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
use std::mem::transmute;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
static mut LEAK: usize = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
#[cfg(target_pointer_width="64")]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let x = &2u16;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let x = &2u16;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
|
||||
fn main() {
|
||||
let v: Vec<u8> = Vec::with_capacity(10);
|
||||
let undef = unsafe { *v.get_unchecked(5) };
|
||||
|
|
|
|||
8
tests/compile-fail/validity/execute_memory.rs
Normal file
8
tests/compile-fail/validity/execute_memory.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#![feature(box_syntax)]
|
||||
|
||||
fn main() {
|
||||
let x = box 42;
|
||||
unsafe {
|
||||
let _f = std::mem::transmute::<Box<i32>, fn()>(x); //~ ERROR encountered a pointer, but expected a function pointer
|
||||
}
|
||||
}
|
||||
10
tests/compile-fail/validity/fn_ptr_offset.rs
Normal file
10
tests/compile-fail/validity/fn_ptr_offset.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use std::mem;
|
||||
|
||||
fn f() {}
|
||||
|
||||
fn main() {
|
||||
let x : fn() = f;
|
||||
let y : *mut u8 = unsafe { mem::transmute(x) };
|
||||
let y = y.wrapping_offset(1);
|
||||
let _x : fn() = unsafe { mem::transmute(y) }; //~ ERROR encountered a potentially NULL pointer
|
||||
}
|
||||
|
|
@ -58,13 +58,11 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, need_fullm
|
|||
let mut flags = Vec::new();
|
||||
flags.push(format!("--sysroot {}", sysroot.display()));
|
||||
flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
|
||||
flags.push("-Zmir-emit-validate=1".to_owned());
|
||||
if opt {
|
||||
// Optimizing too aggressivley makes UB detection harder, but test at least
|
||||
// the default value.
|
||||
// FIXME: Opt level 3 ICEs during stack trace generation.
|
||||
flags.push("-Zmir-opt-level=1".to_owned());
|
||||
} else {
|
||||
flags.push("-Zmir-opt-level=0".to_owned());
|
||||
}
|
||||
|
||||
let mut config = compiletest::Config::default().tempdir();
|
||||
|
|
@ -102,11 +100,8 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir:
|
|||
let mut flags = Vec::new();
|
||||
flags.push(format!("--sysroot {}", sysroot.display()));
|
||||
flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
|
||||
flags.push("-Zmir-emit-validate=1".to_owned());
|
||||
if opt {
|
||||
flags.push("-Zmir-opt-level=3".to_owned());
|
||||
} else {
|
||||
flags.push("-Zmir-opt-level=0".to_owned());
|
||||
}
|
||||
|
||||
let mut config = compiletest::Config::default().tempdir();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
// Moving around undef is not allowed by validation
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
|
||||
struct Foo {
|
||||
_inner: i32,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
// compile-flags: -Zmir-emit-validate=0
|
||||
#![allow(dead_code)]
|
||||
#![feature(unsize, coerce_unsized)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
// FIXME: Disable validation until we figure out how to handle recursive statics.
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
|
||||
struct S(&'static S);
|
||||
static S1: S = S(&S2);
|
||||
static S2: S = S(&S1);
|
||||
|
|
|
|||
|
|
@ -8,9 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// FIXME: We handle uninitialized storage here, which currently makes validation fail.
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
|
||||
//ignore-windows: Uses POSIX APIs
|
||||
|
||||
#![feature(libc)]
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
use std::slice;
|
||||
|
||||
fn foo<T>(v: &[T]) -> Option<&[T]> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue