From 58a17026c996f8f759b775a0582d50f9130ab0f6 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 1 Aug 2017 23:40:03 -0700 Subject: [PATCH] Let -Zmir-emit-validate also control whether miri even acts on the validation commands --- src/librustc_mir/interpret/validation.rs | 12 ++++++++++-- tests/compile-fail/panic.rs | 3 +++ tests/compile-fail/zst2.rs | 3 +++ tests/compile-fail/zst3.rs | 3 +++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/interpret/validation.rs b/src/librustc_mir/interpret/validation.rs index bc3affed836..5b7c932efc2 100644 --- a/src/librustc_mir/interpret/validation.rs +++ b/src/librustc_mir/interpret/validation.rs @@ -39,6 +39,14 @@ impl ValidationMode { // Validity checks impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { pub(crate) fn validation_op(&mut self, op: ValidationOp, operand: &ValidationOperand<'tcx, mir::Lvalue<'tcx>>) -> EvalResult<'tcx> { + // If mir-emit-validate is set to 0 (i.e., disabled), we may still see validation commands + // because other crates may have been compiled with mir-emit-validate > 0. Ignore those + // commands. This makes mir-emit-validate also a flag to control whether miri will do + // validation or not. + if self.tcx.sess.opts.debugging_opts.mir_emit_validate == 0 { + return Ok(()); + } + // HACK: Determine if this method is whitelisted and hence we do not perform any validation. // We currently insta-UB on anything passing around uninitialized memory, so we have to whitelist // the places that are allowed to do that. @@ -50,14 +58,14 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { static ref RE: Regex = Regex::new("^(\ std::mem::uninitialized::|\ std::mem::forget::|\ - ::|\ + <(std|alloc)::heap::Heap as (std::heap|alloc::allocator)::Alloc>::|\ ><.*>::new$|\ as std::ops::DerefMut><.*>::deref_mut$|\ std::ptr::read::|\ \ ><.*>::inner$|\ ><.*>::drop_slow$|\ - std::heap::Layout::for_value::|\ + (std::heap|alloc::allocator)::Layout::for_value::|\ std::mem::(size|align)_of_val::\ )").unwrap(); } diff --git a/tests/compile-fail/panic.rs b/tests/compile-fail/panic.rs index 0d594f9bd4c..dbe80fecd00 100644 --- a/tests/compile-fail/panic.rs +++ b/tests/compile-fail/panic.rs @@ -1,3 +1,6 @@ +// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation +// compile-flags: -Zmir-emit-validate=0 + //error-pattern: the evaluated program panicked fn main() { diff --git a/tests/compile-fail/zst2.rs b/tests/compile-fail/zst2.rs index dd826c2fd74..0c46acb8ade 100644 --- a/tests/compile-fail/zst2.rs +++ b/tests/compile-fail/zst2.rs @@ -1,3 +1,6 @@ +// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation +// compile-flags: -Zmir-emit-validate=0 + // error-pattern: the evaluated program panicked #[derive(Debug)] diff --git a/tests/compile-fail/zst3.rs b/tests/compile-fail/zst3.rs index 53c42995b8a..a6d7fdd3552 100644 --- a/tests/compile-fail/zst3.rs +++ b/tests/compile-fail/zst3.rs @@ -1,3 +1,6 @@ +// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation +// compile-flags: -Zmir-emit-validate=0 + // error-pattern: the evaluated program panicked #[derive(Debug)]