Skip to content

Commit 0be3b0b

Browse files
address reviews
1 parent 2f3378c commit 0be3b0b

File tree

6 files changed

+26
-79
lines changed

6 files changed

+26
-79
lines changed

tests/fail/tree_borrows/children-can-alias.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/fail/tree_borrows/children-can-alias.stderr

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/pass/tree_borrows/interior_mutability.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@revisions: default
21
//@compile-flags: -Zmiri-tree-borrows
32
#![allow(dangerous_implicit_autorefs)]
43
use std::cell::{Cell, Ref, RefCell, RefMut, UnsafeCell};

tests/pass/tree_borrows/tree-borrows.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@revisions: default
21
//@compile-flags: -Zmiri-tree-borrows
32
#![feature(allocator_api)]
43

@@ -11,6 +10,7 @@ fn main() {
1110
direct_mut_to_const_raw();
1211
local_addr_of_mut();
1312
returned_mut_is_usable();
13+
raw_children_of_refmut_can_alias();
1414

1515
// Stacked Borrows tests
1616
read_does_not_invalidate1();
@@ -356,3 +356,20 @@ fn write_does_not_invalidate_all_aliases() {
356356
other::lib2();
357357
assert_eq!(*x, 1337); // oops, the value changed! I guess not all pointers were invalidated
358358
}
359+
360+
fn raw_children_of_refmut_can_alias() {
361+
fn test_with_protector(x: &mut u8) {
362+
unsafe {
363+
let child1 = &raw mut *x;
364+
let child2 = &raw mut *x;
365+
// We create two raw aliases of `x`: they have the exact same
366+
// tag and can be used interchangeably.
367+
child1.write(1);
368+
child2.write(2);
369+
child1.write(1);
370+
child2.write(2);
371+
}
372+
}
373+
374+
test_with_protector(&mut 42u8);
375+
}

tests/pass/tree_borrows/unique.rs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@revisions: default
21
// We disable the GC for this test because it would change what is printed.
32
//@compile-flags: -Zmiri-tree-borrows -Zmiri-provenance-gc=0
43

@@ -11,6 +10,8 @@ mod utils;
1110
use core::ptr::Unique;
1211

1312
// Check general handling of Unique
13+
// Currently, this test just tests that Unique is not handled special in any way.
14+
// In particular, it remains `Active` throughout the test.
1415

1516
fn main() {
1617
unsafe {
@@ -21,45 +22,17 @@ fn main() {
2122
let raw = &mut *base as *mut u8;
2223
name!(raw);
2324

24-
// We create a `Unique` and expect it to have a fresh tag
25-
// and uninitialized permissions.
2625
let uniq = Unique::new_unchecked(raw);
2726

28-
// With `-Zmiri-unique-is-unique`, `Unique::as_ptr` (which is called by
29-
// `Vec::as_ptr`) generates pointers with a fresh tag, so to name the actual
30-
// `base` pointer we care about we have to walk up the tree a bit.
31-
//
32-
// We care about naming this specific parent tag because it is the one
33-
// that stays `Active` during the entire execution, unlike the leaves
34-
// that will be invalidated the next time `as_ptr` is called.
35-
//
36-
// (We name it twice so that we have an indicator in the output of
37-
// whether we got the distance correct:
38-
// If the output shows
39-
//
40-
// |- <XYZ: uniq>
41-
// '- <XYZ: uniq>
42-
//
43-
// then `nth_parent` is not big enough.
44-
// The correct value for `nth_parent` should be the minimum
45-
// integer for which the output shows
46-
//
47-
// '- <XYZ: uniq, uniq>
48-
// )
49-
//
50-
// Ultimately we want pointers obtained through independent
51-
// calls of `as_ptr` to be able to alias, which will probably involve
52-
// a new permission that allows aliasing when there is no protector.
53-
let nth_parent = if cfg!(uniq) { 2 } else { 0 };
54-
name!(uniq.as_ptr()=>nth_parent, "uniq");
55-
name!(uniq.as_ptr()=>nth_parent, "uniq");
27+
name!(uniq.as_ptr(), "uniq");
5628
print_state!(alloc_id);
5729

5830
// We can activate the Unique and use it mutably.
5931
*uniq.as_ptr() = 42;
6032
print_state!(alloc_id);
6133

62-
// Write through the raw parent disables the Unique
34+
// Write through the raw parent does not disable the Unique,
35+
// since both have the same tag.
6336
*raw = 42;
6437
print_state!(alloc_id);
6538
}

tests/pass/tree_borrows/unique.default.stderr renamed to tests/pass/tree_borrows/unique.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ Warning: this tree is indicative only. Some tags may have been hidden.
33
0.. 1
44
| Act | └─┬──<TAG=root of the allocation>
55
| Res | └─┬──<TAG=base>
6-
| Res | └────<TAG=raw, uniq, uniq>
6+
| Res | └────<TAG=raw, uniq>
77
──────────────────────────────────────────────────
88
──────────────────────────────────────────────────
99
Warning: this tree is indicative only. Some tags may have been hidden.
1010
0.. 1
1111
| Act | └─┬──<TAG=root of the allocation>
1212
| Act | └─┬──<TAG=base>
13-
| Act | └────<TAG=raw, uniq, uniq>
13+
| Act | └────<TAG=raw, uniq>
1414
──────────────────────────────────────────────────
1515
──────────────────────────────────────────────────
1616
Warning: this tree is indicative only. Some tags may have been hidden.
1717
0.. 1
1818
| Act | └─┬──<TAG=root of the allocation>
1919
| Act | └─┬──<TAG=base>
20-
| Act | └────<TAG=raw, uniq, uniq>
20+
| Act | └────<TAG=raw, uniq>
2121
──────────────────────────────────────────────────

0 commit comments

Comments
 (0)