File tree Expand file tree Collapse file tree 2 files changed +15
-13
lines changed
src/tools/miri/tests/fail/tree_borrows Expand file tree Collapse file tree 2 files changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -16,12 +16,15 @@ impl Foo {
1616
1717pub fn main ( ) {
1818 let mut f = Foo ( 0 ) ;
19- let inner = & mut f. 0 as * mut u64 ;
20- let _res = f. add ( unsafe {
21- let n = f. 0 ;
19+ let alias = & mut f. 0 as * mut u64 ;
20+ let res = f. add ( unsafe {
2221 // This is the access at fault, but it's not immediately apparent because
2322 // the reference that got invalidated is not under a Protector.
24- * inner = 42 ;
25- n
23+ * alias = 42 ;
24+ 0
2625 } ) ;
26+ // `res` could be optimized to be `0`, since at the time the reference for the `self` argument
27+ // is created, it has value `0`, and then later we add `0` to that. But turns out there is
28+ // a sneaky alias that's used to change the value of `*self` before it is read...
29+ assert_eq ! ( res, 42 ) ;
2730}
Original file line number Diff line number Diff line change @@ -9,26 +9,25 @@ LL | fn add(&mut self, n: u64) -> u64 {
99help: the accessed tag <TAG> was created here, in the initial state Reserved
1010 --> tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
1111 |
12- LL | let _res = f.add(unsafe {
13- | ^
12+ LL | let res = f.add(unsafe {
13+ | ^
1414help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x8]
1515 --> tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
1616 |
17- LL | *inner = 42;
17+ LL | *alias = 42;
1818 | ^^^^^^^^^^^
1919 = help: this transition corresponds to a loss of read and write permissions
2020 = note: BACKTRACE (of the first span):
2121 = note: inside `Foo::add` at tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
2222note: inside `main`
2323 --> tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
2424 |
25- LL | let _res = f.add(unsafe {
26- | ________________^
27- LL | | let n = f.0;
25+ LL | let res = f.add(unsafe {
26+ | _______________^
2827LL | | // This is the access at fault, but it's not immediately apparent because
2928LL | | // the reference that got invalidated is not under a Protector.
30- LL | | *inner = 42;
31- LL | | n
29+ LL | | *alias = 42;
30+ LL | | 0
3231LL | | });
3332 | |______^
3433
You can’t perform that action at this time.
0 commit comments