add test that we do not merge neighboring SRW

This commit is contained in:
Ralf Jung 2022-08-15 18:31:40 -04:00
parent a000764fb9
commit 297ddffff3
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,17 @@
// This tests demonstrates the effect of 'Disabling' mutable references on reads, rather than
// removing them from the stack -- the latter would 'merge' neighboring SRW groups which we would
// like to avoid.
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 _val = *base;
// now mutref is disabled
*base = 1;
// this should pop raw from the stack, since it is in a different SRW group
let _val = *raw; //~ERROR: that tag does not exist in the borrow stack
}
}

View File

@ -0,0 +1,28 @@
error: Undefined Behavior: attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
--> $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
|
LL | let _val = *raw;
| ^^^^
| |
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of an access at ALLOC[0x0..0x4]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
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;
| ^^^^^^
help: <TAG> was later invalidated at offsets [0x0..0x4]
--> $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
|
LL | *base = 1;
| ^^^^^^^^^
= note: backtrace:
= note: inside `main` at $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to previous error