defend test against overly smart Miri

This commit is contained in:
Ralf Jung 2022-08-15 20:23:19 -04:00
parent 2e3da5d8c3
commit db43ee5714
2 changed files with 10 additions and 5 deletions

View File

@ -5,9 +5,14 @@ fn main() {
unsafe {
let mut mem = 0;
let base = &mut mem as *mut i32; // the base pointer we build the rest of the stack on
let mutref = &mut *base;
let raw = mutref as *mut i32;
// in the stack, we now have [base, mutref, raw]
let raw = {
let mutref = &mut *base;
mutref as *mut i32
};
// In the stack, we now have [base, mutref, raw].
// We do this in a weird way where `mutref` is out of scope here, just in case
// Miri decides to get smart and argue that items for tags that are no longer
// used by any pointer stored anywhere in the machine can be removed.
let _val = *base;
// now mutref is disabled
*base = 1;

View File

@ -12,8 +12,8 @@ LL | let _val = *raw;
help: <TAG> was created by a retag at offsets [0x0..0x4]
--> $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
|
LL | let raw = mutref as *mut i32;
| ^^^^^^
LL | mutref as *mut i32
| ^^^^^^
help: <TAG> was later invalidated at offsets [0x0..0x4]
--> $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
|