]> git.lizzy.rs Git - rust.git/commitdiff
stub Retag hook; fix tests for removal of -Zmir-emit-validate
authorRalf Jung <post@ralfj.de>
Wed, 24 Oct 2018 15:17:44 +0000 (17:17 +0200)
committerRalf Jung <post@ralfj.de>
Thu, 1 Nov 2018 07:58:03 +0000 (08:58 +0100)
35 files changed:
src/lib.rs
src/stacked_borrows.rs
tests/compile-fail-fullmir/stack_free.rs
tests/compile-fail/cast_box_int_to_fn_ptr.rs
tests/compile-fail/cast_int_to_fn_ptr.rs
tests/compile-fail/execute_memory.rs
tests/compile-fail/fn_ptr_offset.rs
tests/compile-fail/invalid_bool.rs [new file with mode: 0644]
tests/compile-fail/invalid_bool2.rs [deleted file]
tests/compile-fail/invalid_char.rs [new file with mode: 0644]
tests/compile-fail/invalid_char2.rs [deleted file]
tests/compile-fail/invalid_enum_discriminant.rs [new file with mode: 0644]
tests/compile-fail/invalid_enum_discriminant2.rs [deleted file]
tests/compile-fail/never_say_never.rs
tests/compile-fail/never_transmute_humans.rs
tests/compile-fail/never_transmute_void.rs
tests/compile-fail/panic.rs
tests/compile-fail/reference_to_packed.rs
tests/compile-fail/stacked_borrows/static_memory_modification.rs [new file with mode: 0644]
tests/compile-fail/static_memory_modification.rs
tests/compile-fail/static_memory_modification2.rs
tests/compile-fail/static_memory_modification3.rs
tests/compile-fail/storage_dead_dangling.rs
tests/compile-fail/transmute_fat.rs
tests/compile-fail/unaligned_ptr_cast.rs
tests/compile-fail/unaligned_ptr_cast2.rs
tests/compile-fail/undefined_byte_read.rs
tests/compile-fail/validity/execute_memory.rs [new file with mode: 0644]
tests/compile-fail/validity/fn_ptr_offset.rs [new file with mode: 0644]
tests/compiletest.rs
tests/run-pass/move-undef-primval.rs
tests/run-pass/packed_struct.rs
tests/run-pass/recursive_static.rs
tests/run-pass/regions-mock-trans.rs
tests/run-pass/slice-of-zero-size-elements.rs

index 2de6665186bf7b94edd256187abb4853faf54764..5d20078082f972e180075719915bc5ee337ee3e9 100644 (file)
@@ -26,7 +26,7 @@
 
 
 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 @@ fn tag_new_allocation(
             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)
+    }
 }
index a569ed4e55513b20edb1c9dc5385af412da94931..22216345b65e750739606ac14d8889ed72e32472 100644 (file)
@@ -5,7 +5,7 @@
 
 use super::{
     MemoryAccess, MemoryKind, MiriMemoryKind, RangeMap, EvalResult, AllocId,
-    Pointer,
+    Pointer, PlaceTy,
 };
 
 pub type Timestamp = u64;
@@ -362,6 +362,12 @@ fn tag_new_allocation(
         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 @@ fn tag_new_allocation(
         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(())
+    }
 }
index 6d853e75fb4aec207cd641359002a7499cd158f3..a33bca1267595cb67538c8a7e6f9009c20ae0e9c 100644 (file)
@@ -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
 
index c3b1fa595888519c45cea7f3e62858138482be85..7ee3bc62767fb4f2076ffecbb9a209f2a43bf71f 100644 (file)
@@ -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);
index 1971ce1557e7957e3cf6a40608f0690721204c8a..207af4ae2cefb45a9e719f997671af2b7e961bfe 100644 (file)
@@ -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 {
index d859e9072e3246f2a9692bd3c95c491f64ab4f0a..295756ef0f56155c3e383888440d195c0b228412 100644 (file)
@@ -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)]
 
index cccb21790d6505eda4c4dada728c57c10f1cbd2b..9d29316fe24fe6c8499ebc05ea04ad5a4b23ae21 100644 (file)
@@ -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_bool.rs b/tests/compile-fail/invalid_bool.rs
new file mode 100644 (file)
index 0000000..e80dc15
--- /dev/null
@@ -0,0 +1,7 @@
+// Validation makes this fail in the wrong place
+// compile-flags: -Zmiri-disable-validation
+
+fn main() {
+    let b = unsafe { std::mem::transmute::<u8, bool>(2) };
+    let _x = b == true; //~ ERROR invalid boolean value read
+}
diff --git a/tests/compile-fail/invalid_bool2.rs b/tests/compile-fail/invalid_bool2.rs
deleted file mode 100644 (file)
index 2348c62..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// Validation makes this fail in the wrong place
-// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
-
-fn main() {
-    let b = unsafe { std::mem::transmute::<u8, bool>(2) };
-    let _x = b == true; //~ ERROR invalid boolean value read
-}
diff --git a/tests/compile-fail/invalid_char.rs b/tests/compile-fail/invalid_char.rs
new file mode 100644 (file)
index 0000000..b67ed9b
--- /dev/null
@@ -0,0 +1,8 @@
+// Validation makes this fail in the wrong place
+// compile-flags: -Zmiri-disable-validation
+
+fn main() {
+    assert!(std::char::from_u32(-1_i32 as u32).is_none());
+    let c = unsafe { std::mem::transmute::<i32, char>(-1) };
+    let _x = c == 'x'; //~ ERROR tried to interpret an invalid 32-bit value as a char
+}
diff --git a/tests/compile-fail/invalid_char2.rs b/tests/compile-fail/invalid_char2.rs
deleted file mode 100644 (file)
index 5de2d07..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-// Validation makes this fail in the wrong place
-// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
-
-fn main() {
-    assert!(std::char::from_u32(-1_i32 as u32).is_none());
-    let c = unsafe { std::mem::transmute::<i32, char>(-1) };
-    let _x = c == 'x'; //~ ERROR tried to interpret an invalid 32-bit value as a char
-}
diff --git a/tests/compile-fail/invalid_enum_discriminant.rs b/tests/compile-fail/invalid_enum_discriminant.rs
new file mode 100644 (file)
index 0000000..bd5cb55
--- /dev/null
@@ -0,0 +1,16 @@
+// Validation makes this fail in the wrong place
+// compile-flags: -Zmiri-disable-validation
+
+// error-pattern: invalid enum discriminant
+
+use std::mem;
+
+#[repr(C)]
+pub enum Foo {
+    A, B, C, D
+}
+
+fn main() {
+    let f = unsafe { std::mem::transmute::<i32, Foo>(42) };
+    let _ = mem::discriminant(&f);
+}
diff --git a/tests/compile-fail/invalid_enum_discriminant2.rs b/tests/compile-fail/invalid_enum_discriminant2.rs
deleted file mode 100644 (file)
index ea94081..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Validation makes this fail in the wrong place
-// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
-
-// error-pattern: invalid enum discriminant
-
-use std::mem;
-
-#[repr(C)]
-pub enum Foo {
-    A, B, C, D
-}
-
-fn main() {
-    let f = unsafe { std::mem::transmute::<i32, Foo>(42) };
-    let _ = mem::discriminant(&f);
-}
index 634488489b539a0d2f911f0f243e769353ba8cf6..d7e6a8c09f64e14422881da7af65dddeaaeebe9e 100644 (file)
@@ -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)]
index c5c53d4231c7c516f18c4c50db30d18e3e766d9a..169e861be0b1fb590b0d5f3356d05015d8131575 100644 (file)
@@ -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)]
index 5620b6559cfde40a7d0abf7decd1c584951c0f3a..9c0165fed222a114dc50d7851dc153ea3e84c9a0 100644 (file)
@@ -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)]
index 80149eeffaa641c32a70dc2dc04645c2a426658e..0d594f9bd4c3b14df93523dbc039ffb5fa74e7aa 100644 (file)
@@ -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() {
index 14a2afc33f7fec26f376d0699e05707dcdd757ee..befe96f2b35d95d2b9a5d3705650a53c2480b6c5 100644 (file)
@@ -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 (file)
index 0000000..c092cbf
--- /dev/null
@@ -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
+    };
+}
index c758926458651c30b11dcd313de3d597ed3069bb..07a277a16f3aea1f79b5728d6f5cba218e1d37f1 100644 (file)
@@ -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;
 
index c9857b20592e4410207eed01c322aabf857c8338..73928f533cb708f9400ec1d7cf2192db03405d90 100644 (file)
@@ -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;
 
index 41a62787296f066a54c37772fc4676ecd5bbbded..280f34a5a0213b53fd61c75c5eb7c53dd4c84ea2 100644 (file)
@@ -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;
 
index 69917dce8591073b314170c02ce61281d742bcd5..85c76f6f41f6ee33c1c268af204c6894bf7977ce 100644 (file)
@@ -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;
 
index e1f916910d732f52d066e7e0e69ac35e1a425644..ede0486be4130c5e065cd303eb85c5611f5f8f9c 100644 (file)
@@ -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")]
index 47317afd36ec9899fa19e0446fe920978b4cc28c..e64594d3e7eda966f43d95f3c69df72619189898 100644 (file)
@@ -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;
index d146f21dfe60fd7e50820ac0d35c7abe063f829f..1112f2f33c148f23eea25143e2c2bb5360881fcc 100644 (file)
@@ -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;
index 1f092936148e0bd0aefaefb0b2e0d78d13a1f40c..fca749ef9ccbdb37ffdee64749be4b187e818e3f 100644 (file)
@@ -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) };
diff --git a/tests/compile-fail/validity/execute_memory.rs b/tests/compile-fail/validity/execute_memory.rs
new file mode 100644 (file)
index 0000000..426a51f
--- /dev/null
@@ -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
+    }
+}
diff --git a/tests/compile-fail/validity/fn_ptr_offset.rs b/tests/compile-fail/validity/fn_ptr_offset.rs
new file mode 100644 (file)
index 0000000..4989f4d
--- /dev/null
@@ -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
+}
index 0b2058597e185ab21ca826b36495bf6c46edbd74..98e3fde54e69e62415ea955c5c1354bcf40dc730 100644 (file)
@@ -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();
index 2c18c2d3687a5f9b879154f2a3b8d297a0871bb4..73c33943a63ac65fa586292963f67df44e5da382 100644 (file)
@@ -1,6 +1,3 @@
-// Moving around undef is not allowed by validation
-// compile-flags: -Zmir-emit-validate=0
-
 struct Foo {
     _inner: i32,
 }
index e10781e656058abb9b5076e3d0fffc0d90c038d4..303e90742fc11d8186430611e00c272a8406c1c3 100644 (file)
@@ -1,4 +1,3 @@
-// compile-flags: -Zmir-emit-validate=0
 #![allow(dead_code)]
 #![feature(unsize, coerce_unsized)]
 
index d259ca6361c978ed3bfa54e847b7226c50943d4d..77f2902917a1c21e22be8376ce8c82a2e5950332 100644 (file)
@@ -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);
index 039175e9acd6028ab81e57b17e6177cb4998c1ce..130eaa288ebefe433232a64bae3ebd33334fdd88 100644 (file)
@@ -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)]
index dbe8ec9addacc5f88ac0b269c0ead95a54b038da..aa9d117d726f16a1b8a8c51bc4144ba07c136dc6 100644 (file)
@@ -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]> {