Skip to content

Commit

Permalink
add local_addr_of_mut test
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 2, 2023
1 parent c951208 commit df3b25f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn main() {
string_as_mut_ptr();
two_mut_protected_same_alloc();
direct_mut_to_const_raw();
local_addr_of_mut();

// Stacked Borrows tests
read_does_not_invalidate1();
Expand All @@ -31,6 +32,17 @@ fn main() {
write_does_not_invalidate_all_aliases();
}

#[allow(unused_assignments)]
fn local_addr_of_mut() {
let mut local = 0;
let ptr = ptr::addr_of_mut!(local);
// In SB, `local` and `*ptr` would have different tags, but in TB they have the same tag.
local = 1;
unsafe { *ptr = 2 };
local = 3;
unsafe { *ptr = 4 };
}

// Tree Borrows has no issue with several mutable references existing
// at the same time, as long as they are used only immutably.
// I.e. multiple Reserved can coexist.
Expand Down

0 comments on commit df3b25f

Please sign in to comment.