Skip to content

Commit 297ddff

Browse files
committed
add test that we do not merge neighboring SRW
1 parent a000764 commit 297ddff

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This tests demonstrates the effect of 'Disabling' mutable references on reads, rather than
2+
// removing them from the stack -- the latter would 'merge' neighboring SRW groups which we would
3+
// like to avoid.
4+
fn main() {
5+
unsafe {
6+
let mut mem = 0;
7+
let base = &mut mem as *mut i32; // the base pointer we build the rest of the stack on
8+
let mutref = &mut *base;
9+
let raw = mutref as *mut i32;
10+
// in the stack, we now have [base, mutref, raw]
11+
let _val = *base;
12+
// now mutref is disabled
13+
*base = 1;
14+
// this should pop raw from the stack, since it is in a different SRW group
15+
let _val = *raw; //~ERROR: that tag does not exist in the borrow stack
16+
}
17+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
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
2+
--> $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
3+
|
4+
LL | let _val = *raw;
5+
| ^^^^
6+
| |
7+
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
8+
| this error occurs as part of an access at ALLOC[0x0..0x4]
9+
|
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
11+
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
12+
help: <TAG> was created by a retag at offsets [0x0..0x4]
13+
--> $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
14+
|
15+
LL | let raw = mutref as *mut i32;
16+
| ^^^^^^
17+
help: <TAG> was later invalidated at offsets [0x0..0x4]
18+
--> $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
19+
|
20+
LL | *base = 1;
21+
| ^^^^^^^^^
22+
= note: backtrace:
23+
= note: inside `main` at $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
24+
25+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
26+
27+
error: aborting due to previous error
28+

0 commit comments

Comments
 (0)