From 7ac0e79ad5bcd8d7e4f8317c15238d5911faf11c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 24 Oct 2018 17:17:44 +0200 Subject: [PATCH] stub Retag hook; fix tests for removal of -Zmir-emit-validate --- src/lib.rs | 16 +++++++++++++++- src/stacked_borrows.rs | 17 ++++++++++++++++- tests/compile-fail-fullmir/stack_free.rs | 2 +- tests/compile-fail/cast_box_int_to_fn_ptr.rs | 2 +- tests/compile-fail/cast_int_to_fn_ptr.rs | 2 +- tests/compile-fail/execute_memory.rs | 2 +- tests/compile-fail/fn_ptr_offset.rs | 2 +- .../{invalid_bool2.rs => invalid_bool.rs} | 2 +- .../{invalid_char2.rs => invalid_char.rs} | 2 +- ...iminant2.rs => invalid_enum_discriminant.rs} | 2 +- tests/compile-fail/never_say_never.rs | 2 +- tests/compile-fail/never_transmute_humans.rs | 2 +- tests/compile-fail/never_transmute_void.rs | 2 +- tests/compile-fail/panic.rs | 2 -- tests/compile-fail/reference_to_packed.rs | 2 +- .../static_memory_modification.rs | 8 ++++++++ .../compile-fail/static_memory_modification.rs | 2 +- .../compile-fail/static_memory_modification2.rs | 2 +- .../compile-fail/static_memory_modification3.rs | 2 +- tests/compile-fail/storage_dead_dangling.rs | 2 +- tests/compile-fail/transmute_fat.rs | 2 +- tests/compile-fail/unaligned_ptr_cast.rs | 2 +- tests/compile-fail/unaligned_ptr_cast2.rs | 2 +- tests/compile-fail/undefined_byte_read.rs | 3 --- tests/compile-fail/validity/execute_memory.rs | 8 ++++++++ tests/compile-fail/validity/fn_ptr_offset.rs | 10 ++++++++++ tests/compiletest.rs | 7 +------ tests/run-pass/move-undef-primval.rs | 3 --- tests/run-pass/packed_struct.rs | 1 - tests/run-pass/recursive_static.rs | 3 --- tests/run-pass/regions-mock-trans.rs | 3 --- tests/run-pass/slice-of-zero-size-elements.rs | 2 -- 32 files changed, 77 insertions(+), 44 deletions(-) rename tests/compile-fail/{invalid_bool2.rs => invalid_bool.rs} (73%) rename tests/compile-fail/{invalid_char2.rs => invalid_char.rs} (80%) rename tests/compile-fail/{invalid_enum_discriminant2.rs => invalid_enum_discriminant.rs} (79%) create mode 100644 tests/compile-fail/stacked_borrows/static_memory_modification.rs create mode 100644 tests/compile-fail/validity/execute_memory.rs create mode 100644 tests/compile-fail/validity/fn_ptr_offset.rs diff --git a/src/lib.rs b/src/lib.rs index 2de6665186bf..5d20078082f9 100644 --- a/src/lib.rs +++ b/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) + } } diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index a569ed4e5551..22216345b65e 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -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, ) -> 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(()) + } } diff --git a/tests/compile-fail-fullmir/stack_free.rs b/tests/compile-fail-fullmir/stack_free.rs index 6d853e75fb4a..a33bca126759 100644 --- a/tests/compile-fail-fullmir/stack_free.rs +++ b/tests/compile-fail-fullmir/stack_free.rs @@ -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 diff --git a/tests/compile-fail/cast_box_int_to_fn_ptr.rs b/tests/compile-fail/cast_box_int_to_fn_ptr.rs index c3b1fa595888..7ee3bc62767f 100644 --- a/tests/compile-fail/cast_box_int_to_fn_ptr.rs +++ b/tests/compile-fail/cast_box_int_to_fn_ptr.rs @@ -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); diff --git a/tests/compile-fail/cast_int_to_fn_ptr.rs b/tests/compile-fail/cast_int_to_fn_ptr.rs index 1971ce1557e7..207af4ae2cef 100644 --- a/tests/compile-fail/cast_int_to_fn_ptr.rs +++ b/tests/compile-fail/cast_int_to_fn_ptr.rs @@ -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 { diff --git a/tests/compile-fail/execute_memory.rs b/tests/compile-fail/execute_memory.rs index d859e9072e32..295756ef0f56 100644 --- a/tests/compile-fail/execute_memory.rs +++ b/tests/compile-fail/execute_memory.rs @@ -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)] diff --git a/tests/compile-fail/fn_ptr_offset.rs b/tests/compile-fail/fn_ptr_offset.rs index cccb21790d65..9d29316fe24f 100644 --- a/tests/compile-fail/fn_ptr_offset.rs +++ b/tests/compile-fail/fn_ptr_offset.rs @@ -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; diff --git a/tests/compile-fail/invalid_bool2.rs b/tests/compile-fail/invalid_bool.rs similarity index 73% rename from tests/compile-fail/invalid_bool2.rs rename to tests/compile-fail/invalid_bool.rs index 2348c62559b0..e80dc15efaec 100644 --- a/tests/compile-fail/invalid_bool2.rs +++ b/tests/compile-fail/invalid_bool.rs @@ -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::(2) }; diff --git a/tests/compile-fail/invalid_char2.rs b/tests/compile-fail/invalid_char.rs similarity index 80% rename from tests/compile-fail/invalid_char2.rs rename to tests/compile-fail/invalid_char.rs index 5de2d073f323..b67ed9ba520d 100644 --- a/tests/compile-fail/invalid_char2.rs +++ b/tests/compile-fail/invalid_char.rs @@ -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()); diff --git a/tests/compile-fail/invalid_enum_discriminant2.rs b/tests/compile-fail/invalid_enum_discriminant.rs similarity index 79% rename from tests/compile-fail/invalid_enum_discriminant2.rs rename to tests/compile-fail/invalid_enum_discriminant.rs index ea94081693e1..bd5cb55b6c92 100644 --- a/tests/compile-fail/invalid_enum_discriminant2.rs +++ b/tests/compile-fail/invalid_enum_discriminant.rs @@ -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 diff --git a/tests/compile-fail/never_say_never.rs b/tests/compile-fail/never_say_never.rs index 634488489b53..d7e6a8c09f64 100644 --- a/tests/compile-fail/never_say_never.rs +++ b/tests/compile-fail/never_say_never.rs @@ -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)] diff --git a/tests/compile-fail/never_transmute_humans.rs b/tests/compile-fail/never_transmute_humans.rs index c5c53d4231c7..169e861be0b1 100644 --- a/tests/compile-fail/never_transmute_humans.rs +++ b/tests/compile-fail/never_transmute_humans.rs @@ -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)] diff --git a/tests/compile-fail/never_transmute_void.rs b/tests/compile-fail/never_transmute_void.rs index 5620b6559cfd..9c0165fed222 100644 --- a/tests/compile-fail/never_transmute_void.rs +++ b/tests/compile-fail/never_transmute_void.rs @@ -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)] diff --git a/tests/compile-fail/panic.rs b/tests/compile-fail/panic.rs index 80149eeffaa6..0d594f9bd4c3 100644 --- a/tests/compile-fail/panic.rs +++ b/tests/compile-fail/panic.rs @@ -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() { diff --git a/tests/compile-fail/reference_to_packed.rs b/tests/compile-fail/reference_to_packed.rs index 14a2afc33f7f..befe96f2b35d 100644 --- a/tests/compile-fail/reference_to_packed.rs +++ b/tests/compile-fail/reference_to_packed.rs @@ -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)] diff --git a/tests/compile-fail/stacked_borrows/static_memory_modification.rs b/tests/compile-fail/stacked_borrows/static_memory_modification.rs new file mode 100644 index 000000000000..c092cbfe5098 --- /dev/null +++ b/tests/compile-fail/stacked_borrows/static_memory_modification.rs @@ -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 + }; +} diff --git a/tests/compile-fail/static_memory_modification.rs b/tests/compile-fail/static_memory_modification.rs index c75892645865..07a277a16f3a 100644 --- a/tests/compile-fail/static_memory_modification.rs +++ b/tests/compile-fail/static_memory_modification.rs @@ -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; diff --git a/tests/compile-fail/static_memory_modification2.rs b/tests/compile-fail/static_memory_modification2.rs index c9857b20592e..73928f533cb7 100644 --- a/tests/compile-fail/static_memory_modification2.rs +++ b/tests/compile-fail/static_memory_modification2.rs @@ -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; diff --git a/tests/compile-fail/static_memory_modification3.rs b/tests/compile-fail/static_memory_modification3.rs index 41a62787296f..280f34a5a021 100644 --- a/tests/compile-fail/static_memory_modification3.rs +++ b/tests/compile-fail/static_memory_modification3.rs @@ -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; diff --git a/tests/compile-fail/storage_dead_dangling.rs b/tests/compile-fail/storage_dead_dangling.rs index 69917dce8591..85c76f6f41f6 100644 --- a/tests/compile-fail/storage_dead_dangling.rs +++ b/tests/compile-fail/storage_dead_dangling.rs @@ -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; diff --git a/tests/compile-fail/transmute_fat.rs b/tests/compile-fail/transmute_fat.rs index e1f916910d73..ede0486be413 100644 --- a/tests/compile-fail/transmute_fat.rs +++ b/tests/compile-fail/transmute_fat.rs @@ -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")] diff --git a/tests/compile-fail/unaligned_ptr_cast.rs b/tests/compile-fail/unaligned_ptr_cast.rs index 47317afd36ec..e64594d3e7ed 100644 --- a/tests/compile-fail/unaligned_ptr_cast.rs +++ b/tests/compile-fail/unaligned_ptr_cast.rs @@ -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; diff --git a/tests/compile-fail/unaligned_ptr_cast2.rs b/tests/compile-fail/unaligned_ptr_cast2.rs index d146f21dfe60..1112f2f33c14 100644 --- a/tests/compile-fail/unaligned_ptr_cast2.rs +++ b/tests/compile-fail/unaligned_ptr_cast2.rs @@ -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; diff --git a/tests/compile-fail/undefined_byte_read.rs b/tests/compile-fail/undefined_byte_read.rs index 1f092936148e..fca749ef9ccb 100644 --- a/tests/compile-fail/undefined_byte_read.rs +++ b/tests/compile-fail/undefined_byte_read.rs @@ -1,6 +1,3 @@ -// This should fail even without validation -// compile-flags: -Zmir-emit-validate=0 - fn main() { let v: Vec = Vec::with_capacity(10); let undef = unsafe { *v.get_unchecked(5) }; diff --git a/tests/compile-fail/validity/execute_memory.rs b/tests/compile-fail/validity/execute_memory.rs new file mode 100644 index 000000000000..426a51faf8a3 --- /dev/null +++ b/tests/compile-fail/validity/execute_memory.rs @@ -0,0 +1,8 @@ +#![feature(box_syntax)] + +fn main() { + let x = box 42; + unsafe { + let _f = std::mem::transmute::, fn()>(x); //~ ERROR encountered a pointer, but expected a function pointer + } +} diff --git a/tests/compile-fail/validity/fn_ptr_offset.rs b/tests/compile-fail/validity/fn_ptr_offset.rs new file mode 100644 index 000000000000..4989f4d3af7b --- /dev/null +++ b/tests/compile-fail/validity/fn_ptr_offset.rs @@ -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 +} diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 0b2058597e18..98e3fde54e69 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -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(); diff --git a/tests/run-pass/move-undef-primval.rs b/tests/run-pass/move-undef-primval.rs index 2c18c2d3687a..73c33943a63a 100644 --- a/tests/run-pass/move-undef-primval.rs +++ b/tests/run-pass/move-undef-primval.rs @@ -1,6 +1,3 @@ -// Moving around undef is not allowed by validation -// compile-flags: -Zmir-emit-validate=0 - struct Foo { _inner: i32, } diff --git a/tests/run-pass/packed_struct.rs b/tests/run-pass/packed_struct.rs index e10781e65605..303e90742fc1 100644 --- a/tests/run-pass/packed_struct.rs +++ b/tests/run-pass/packed_struct.rs @@ -1,4 +1,3 @@ -// compile-flags: -Zmir-emit-validate=0 #![allow(dead_code)] #![feature(unsize, coerce_unsized)] diff --git a/tests/run-pass/recursive_static.rs b/tests/run-pass/recursive_static.rs index d259ca6361c9..77f2902917a1 100644 --- a/tests/run-pass/recursive_static.rs +++ b/tests/run-pass/recursive_static.rs @@ -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); diff --git a/tests/run-pass/regions-mock-trans.rs b/tests/run-pass/regions-mock-trans.rs index 039175e9acd6..130eaa288ebe 100644 --- a/tests/run-pass/regions-mock-trans.rs +++ b/tests/run-pass/regions-mock-trans.rs @@ -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)] diff --git a/tests/run-pass/slice-of-zero-size-elements.rs b/tests/run-pass/slice-of-zero-size-elements.rs index dbe8ec9addac..aa9d117d726f 100644 --- a/tests/run-pass/slice-of-zero-size-elements.rs +++ b/tests/run-pass/slice-of-zero-size-elements.rs @@ -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(v: &[T]) -> Option<&[T]> {