Skip to content

Commit 00a82a5

Browse files
committed
Auto merge of #3229 - saethlin:protector-gc-ice, r=RalfJung
Visit the AllocIds and BorTags in borrow state FrameExtra Fixes rust-lang/miri#3228 I said > The obvious way would be to visit the AllocIds in borrow_tracker::FrameExtra in the GC. Since I have had no new ideas, that's what this does.
2 parents fcb89b3 + ce4f575 commit 00a82a5

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/tools/miri/src/borrow_tracker/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub struct FrameState {
6565
/// incremental updates of the global list of protected tags stored in the
6666
/// `stacked_borrows::GlobalState` upon function return, and if we attempt to pop a protected
6767
/// tag, to identify which call is responsible for protecting the tag.
68-
/// See `Stack::item_popped` for more explanation.
68+
/// See `Stack::item_invalidated` for more explanation.
6969
/// Tree Borrows also needs to know which allocation these tags
7070
/// belong to so that it can perform a read through them immediately before
7171
/// the frame gets popped.
@@ -76,8 +76,10 @@ pub struct FrameState {
7676
}
7777

7878
impl VisitProvenance for FrameState {
79-
fn visit_provenance(&self, _visit: &mut VisitWith<'_>) {
80-
// `protected_tags` are already recorded by `GlobalStateInner`.
79+
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
80+
for (id, tag) in &self.protected_tags {
81+
visit(Some(*id), Some(*tag));
82+
}
8183
}
8284
}
8385

@@ -98,7 +100,7 @@ pub struct GlobalStateInner {
98100
/// An item is protected if its tag is in this set, *and* it has the "protected" bit set.
99101
/// We add tags to this when they are created with a protector in `reborrow`, and
100102
/// we remove tags from this when the call which is protecting them returns, in
101-
/// `GlobalStateInner::end_call`. See `Stack::item_popped` for more details.
103+
/// `GlobalStateInner::end_call`. See `Stack::item_invalidated` for more details.
102104
protected_tags: FxHashMap<BorTag, ProtectorKind>,
103105
/// The pointer ids to trace
104106
tracked_pointer_tags: FxHashSet<BorTag>,
@@ -111,10 +113,8 @@ pub struct GlobalStateInner {
111113
}
112114

113115
impl VisitProvenance for GlobalStateInner {
114-
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
115-
for &tag in self.protected_tags.keys() {
116-
visit(None, Some(tag));
117-
}
116+
fn visit_provenance(&self, _visit: &mut VisitWith<'_>) {
117+
// All the provenance in protected_tags is also stored in FrameState, and visited there.
118118
// The only other candidate is base_ptr_tags, and that does not need visiting since we don't ever
119119
// GC the bottommost/root tag.
120120
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// When we pop a stack frame with weak protectors, we need to check if the protected pointer's
2+
// allocation is still live. If the provenance GC only knows about the BorTag that is protected,
3+
// we can ICE. This test checks that we don't.
4+
// See https://github.com/rust-lang/miri/issues/3228
5+
6+
#[path = "../utils/mod.rs"]
7+
mod utils;
8+
9+
#[allow(unused)]
10+
fn oof(mut b: Box<u8>) {
11+
b = Box::new(0u8);
12+
utils::run_provenance_gc();
13+
}
14+
15+
fn main() {
16+
oof(Box::new(0u8));
17+
}

0 commit comments

Comments
 (0)