diff --git a/tests/fail/stacked_borrows/illegal_read3.rs b/tests/fail/stacked_borrows/illegal_read3.rs index 672c200861c..3de8f57d622 100644 --- a/tests/fail/stacked_borrows/illegal_read3.rs +++ b/tests/fail/stacked_borrows/illegal_read3.rs @@ -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 }; } diff --git a/tests/fail/stacked_borrows/illegal_read3.stderr b/tests/fail/stacked_borrows/illegal_read3.stderr index ab26696a765..75c4305ee81 100644 --- a/tests/fail/stacked_borrows/illegal_read3.stderr +++ b/tests/fail/stacked_borrows/illegal_read3.stderr @@ -17,8 +17,8 @@ LL | let xref2 = &mut *xref1; help: 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 diff --git a/tests/fail/transmute-pair-uninit.rs b/tests/fail/transmute-pair-uninit.rs index 18c80ac42ac..1bd60f9cff7 100644 --- a/tests/fail/transmute-pair-uninit.rs +++ b/tests/fail/transmute-pair-uninit.rs @@ -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 } diff --git a/tests/fail/transmute-pair-uninit.stderr b/tests/fail/transmute-pair-uninit.stderr index f574e974028..833c3abbb2f 100644 --- a/tests/fail/transmute-pair-uninit.stderr +++ b/tests/fail/transmute-pair-uninit.stderr @@ -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 diff --git a/tests/fail/uninit_byte_read.rs b/tests/fail/uninit_byte_read.rs index 9a1f8df94d6..6868e589550 100644 --- a/tests/fail/uninit_byte_read.rs +++ b/tests/fail/uninit_byte_read.rs @@ -1,7 +1,6 @@ -// compile-flags: -Zmiri-allow-uninit-numbers fn main() { let v: Vec = 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); } diff --git a/tests/fail/uninit_byte_read.stderr b/tests/fail/uninit_byte_read.stderr index b07473f95b9..d150be3e7e7 100644 --- a/tests/fail/uninit_byte_read.stderr +++ b/tests/fail/uninit_byte_read.stderr @@ -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 diff --git a/tests/fail/validity/invalid_enum_tag_256variants_uninit.rs b/tests/fail/validity/invalid_enum_tag_256variants_uninit.rs index c36685ab2f4..b6f86698b3f 100644 --- a/tests/fail/validity/invalid_enum_tag_256variants_uninit.rs +++ b/tests/fail/validity/invalid_enum_tag_256variants_uninit.rs @@ -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)] diff --git a/tests/pass/intptrcast.rs b/tests/pass/intptrcast.rs index 573bdbae704..aafa90204fc 100644 --- a/tests/pass/intptrcast.rs +++ b/tests/pass/intptrcast.rs @@ -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(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); } diff --git a/tests/pass/transmute_fat.rs b/tests/pass/transmute_fat.rs index 8a6e15031cb..c62298a9ace 100644 --- a/tests/pass/transmute_fat.rs +++ b/tests/pass/transmute_fat.rs @@ -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); }