]> git.lizzy.rs Git - rust.git/commitdiff
port some tests away from flags we want to remove
authorRalf Jung <post@ralfj.de>
Mon, 6 Jun 2022 15:44:36 +0000 (11:44 -0400)
committerRalf Jung <post@ralfj.de>
Mon, 6 Jun 2022 15:44:36 +0000 (11:44 -0400)
tests/fail/stacked_borrows/illegal_read3.rs
tests/fail/stacked_borrows/illegal_read3.stderr
tests/fail/transmute-pair-uninit.rs
tests/fail/transmute-pair-uninit.stderr
tests/fail/uninit_byte_read.rs
tests/fail/uninit_byte_read.stderr
tests/fail/validity/invalid_enum_tag_256variants_uninit.rs
tests/pass/intptrcast.rs
tests/pass/transmute_fat.rs

index 672c200861c684dbc997b89bb1a78eb4312b0737..3de8f57d6223c1fdd883c41497ac4e6424b3e784 100644 (file)
@@ -1,16 +1,18 @@
-// compile-flags: -Zmiri-allow-ptr-int-transmute
 // A callee may not read the destination of our `&mut` without us noticing.
 // Thise code got carefully checked to not introduce any reborrows
 // that are not explicit in the source. Let's hope the compiler does not break this later!
 
-#![feature(untagged_unions)]
-
 use std::mem;
 
+union HiddenRef {
+    // We avoid retagging at this type, so shared vs mutable does not matter.
+    r: &'static i32,
+}
+
 fn main() {
     let mut x: i32 = 15;
     let xref1 = &mut x;
-    let xref1_sneaky: usize = unsafe { mem::transmute_copy(&xref1) };
+    let xref1_sneaky: HiddenRef = unsafe { mem::transmute_copy(&xref1) };
     // Derived from `xref1`, so using raw value is still ok, ...
     let xref2 = &mut *xref1;
     callee(xref1_sneaky);
@@ -19,14 +21,8 @@ fn main() {
     //~^ ERROR: borrow stack
 }
 
-fn callee(xref1: usize) {
-    // Transmuting through a union to avoid retagging.
-    union UsizeToRef {
-        from: usize,
-        to: &'static mut i32,
-    }
-    let xref1 = UsizeToRef { from: xref1 };
+fn callee(xref1: HiddenRef) {
     // Doing the deref and the transmute (through the union) in the same place expression
     // should avoid retagging.
-    let _val = unsafe { *xref1.to };
+    let _val = unsafe { *xref1.r };
 }
index ab26696a765c6584cda95125a7534d4a88545f9a..75c4305ee81f5c9c269f15469eb6e94781c928dc 100644 (file)
@@ -17,8 +17,8 @@ LL |     let xref2 = &mut *xref1;
 help: <TAG> was later invalidated at offsets [0x0..0x4]
   --> $DIR/illegal_read3.rs:LL:CC
    |
-LL |     let _val = unsafe { *xref1.to };
-   |                         ^^^^^^^^^
+LL |     let _val = unsafe { *xref1.r };
+   |                         ^^^^^^^^
    = note: inside `main` at $DIR/illegal_read3.rs:LL:CC
 
 note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
index 18c80ac42ac8ebc7f37d8eb1058014366cdae283..1bd60f9cff732ffc4f84e04b0b0ef0e781f4ed33 100644 (file)
@@ -1,4 +1,3 @@
-// compile-flags: -Zmiri-allow-uninit-numbers
 #![feature(core_intrinsics)]
 
 use std::mem;
@@ -18,6 +17,6 @@ fn main() {
         assert_eq!(byte, 0);
     }
     let v = unsafe { *z.offset(first_undef) };
+    //~^ ERROR uninitialized
     if v == 0 { println!("it is zero"); }
-    //~^ ERROR this operation requires initialized memory
 }
index f574e97402825bc74c65d20394599a33cc125208..833c3abbb2fb19929e4f3d7a13edead4e0b14cab 100644 (file)
@@ -1,8 +1,8 @@
-error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
+error: Undefined Behavior: type validation failed: encountered uninitialized bytes, but expected initialized bytes
   --> $DIR/transmute-pair-uninit.rs:LL:CC
    |
-LL |     if v == 0 { println!("it is zero"); }
-   |        ^^^^^^ using uninitialized data, but this operation requires initialized memory
+LL |     let v = unsafe { *z.offset(first_undef) };
+   |                      ^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected initialized bytes
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
index 9a1f8df94d60ff380e458c386e04d13cc0855888..6868e5895507dbce8242b53c0cb97214576d4979 100644 (file)
@@ -1,7 +1,6 @@
-// compile-flags: -Zmiri-allow-uninit-numbers
 fn main() {
     let v: Vec<u8> = Vec::with_capacity(10);
-    let undef = unsafe { *v.get_unchecked(5) };
-    let x = undef + 1; //~ ERROR this operation requires initialized memory
+    let undef = unsafe { *v.get_unchecked(5) }; //~ ERROR uninitialized
+    let x = undef + 1;
     panic!("this should never print: {}", x);
 }
index b07473f95b9e49e916e3c8bf9b550ffb4a78c689..d150be3e7e7814f8f9676bf7762c4fe3db17400c 100644 (file)
@@ -1,8 +1,8 @@
-error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
+error: Undefined Behavior: type validation failed: encountered uninitialized bytes, but expected initialized bytes
   --> $DIR/uninit_byte_read.rs:LL:CC
    |
-LL |     let x = undef + 1;
-   |             ^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
+LL |     let undef = unsafe { *v.get_unchecked(5) };
+   |                          ^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected initialized bytes
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
index c36685ab2f467cf6611f4f0d699c6238cd6f12e7..b6f86698b3fb376a4c12ca6790fe80a2b3244654 100644 (file)
@@ -1,3 +1,4 @@
+// Even when uninit numbers are allowed, this enum is not.
 // compile-flags: -Zmiri-allow-uninit-numbers
 #![allow(unused, deprecated, invalid_value)]
 
index 573bdbae704a4ebc138561822cb84fca2ecf4e4e..aafa90204fc2aebc19144f7559d2e1698a9e2cdb 100644 (file)
@@ -1,6 +1,4 @@
-// compile-flags: -Zmiri-allow-ptr-int-transmute
-
-// This returns a miri pointer at type usize, if the argument is a proper pointer
+// This strips provenance
 fn transmute_ptr_to_int<T>(x: *const T) -> usize {
     unsafe { std::mem::transmute(x) }
 }
@@ -39,7 +37,7 @@ fn transmute() {
     // transmuting.
     let a: *const i32 = &42;
     let b = transmute_ptr_to_int(a) as u8;
-    let c = a as usize as u8;
+    let c = a as u8;
     assert_eq!(b, c);
 }
 
index 8a6e15031cb4db68c26c270409ebd3118ec97008..c62298a9aced29cf274dff5ba22bf6fed99c8bd0 100644 (file)
@@ -1,14 +1,11 @@
 // Stacked Borrows disallows this becuase the reference is never cast to a raw pointer.
-// compile-flags: -Zmiri-disable-stacked-borrows -Zmiri-allow-ptr-int-transmute
+// compile-flags: -Zmiri-disable-stacked-borrows
 
 fn main() {
     // If we are careful, we can exploit data layout...
     let raw = unsafe {
-        std::mem::transmute::<&[u8], [usize; 2]>(&[42])
+        std::mem::transmute::<&[u8], [*const u8; 2]>(&[42])
     };
-    let ptr = raw[0] + raw[1];
-    // We transmute both ways, to really test allow-ptr-int-transmute.
-    let ptr: *const u8 = unsafe { std::mem::transmute(ptr) };
-    // The pointer is one-past-the end, but we decrement it into bounds before using it
-    assert_eq!(unsafe { *ptr.offset(-1) }, 42);
+    let ptr: *const u8 = unsafe { std::mem::transmute_copy(&raw) };
+    assert_eq!(unsafe { *ptr }, 42);
 }