-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4008 from JoJoDeveloping/tb-access-state-based-sk…
…ipping [TB Optimization] Skip subtrees based on the subtree's root node's permissions
- Loading branch information
Showing
4 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
tests/fail/tree_borrows/subtree_traversal_skipping_diagnostics.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0 | ||
|
||
// Shows the effect of the optimization of #4008. | ||
// The diagnostics change, but not the error itself. | ||
|
||
// When this method is called, the tree will be a single line and look like this, | ||
// with other_ptr being the root at the top | ||
// other_ptr = root : Active | ||
// intermediary : Frozen // an intermediary node | ||
// m : Reserved | ||
fn write_to_mut(m: &mut u8, other_ptr: *const u8) { | ||
unsafe { | ||
std::hint::black_box(*other_ptr); | ||
} | ||
// In line 17 above, m should have become Reserved (protected) so that this write is impossible. | ||
// However, that does not happen because the read above is not forwarded to the subtree below | ||
// the Frozen intermediary node. This does not affect UB, however, because the Frozen that blocked | ||
// the read already prevents any child writes. | ||
*m = 42; //~ERROR: /write access through .* is forbidden/ | ||
} | ||
|
||
fn main() { | ||
let root = 42u8; | ||
unsafe { | ||
let intermediary = &root; | ||
let data = &mut *(core::ptr::addr_of!(*intermediary) as *mut u8); | ||
write_to_mut(data, core::ptr::addr_of!(root)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/fail/tree_borrows/subtree_traversal_skipping_diagnostics.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
error: Undefined Behavior: write access through <TAG> at ALLOC[0x0] is forbidden | ||
--> tests/fail/tree_borrows/subtree_traversal_skipping_diagnostics.rs:LL:CC | ||
| | ||
LL | *m = 42; | ||
| ^^^^^^^ write access through <TAG> at ALLOC[0x0] is forbidden | ||
| | ||
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental | ||
= help: the accessed tag <TAG> is a child of the conflicting tag <TAG> | ||
= help: the conflicting tag <TAG> has state Frozen which forbids this child write access | ||
help: the accessed tag <TAG> was created here | ||
--> tests/fail/tree_borrows/subtree_traversal_skipping_diagnostics.rs:LL:CC | ||
| | ||
LL | fn write_to_mut(m: &mut u8, other_ptr: *const u8) { | ||
| ^ | ||
help: the conflicting tag <TAG> was created here, in the initial state Frozen | ||
--> tests/fail/tree_borrows/subtree_traversal_skipping_diagnostics.rs:LL:CC | ||
| | ||
LL | let intermediary = &root; | ||
| ^^^^^ | ||
= note: BACKTRACE (of the first span): | ||
= note: inside `write_to_mut` at tests/fail/tree_borrows/subtree_traversal_skipping_diagnostics.rs:LL:CC | ||
note: inside `main` | ||
--> tests/fail/tree_borrows/subtree_traversal_skipping_diagnostics.rs:LL:CC | ||
| | ||
LL | write_to_mut(data, core::ptr::addr_of!(root)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|