diff options
| author | Ralf Jung <post@ralfj.de> | 2022-08-15 18:31:40 -0400 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-08-15 18:32:14 -0400 |
| commit | 297ddffff3248c0d60a07a8a96cb2d06d6191a2b (patch) | |
| tree | 79b3044804a918126341293bf864fdbf08361e86 | |
| parent | a000764fb9a892d00a77207323b856ef07d44d36 (diff) | |
| download | rust-297ddffff3248c0d60a07a8a96cb2d06d6191a2b.tar.gz rust-297ddffff3248c0d60a07a8a96cb2d06d6191a2b.zip | |
add test that we do not merge neighboring SRW
| -rw-r--r-- | tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.rs | 17 | ||||
| -rw-r--r-- | tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.stderr | 28 |
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.rs b/tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.rs new file mode 100644 index 00000000000..1dcd7621acd --- /dev/null +++ b/tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.rs @@ -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 + } +} diff --git a/tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.stderr b/tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.stderr new file mode 100644 index 00000000000..b3f0204c09f --- /dev/null +++ b/tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.stderr @@ -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 + |
