Skip to content

Commit 13573e8

Browse files
committed
Auto merge of #2600 - saethlin:ice, r=RalfJung
Fix ICE when trying to GC a Stack with an unknown bottom Fixes rust-lang/rust#103167 `@RalfJung` I prefer this approach because the whole GC system is sloppy already in order to be efficient (doesn't run often, ignores small stacks) so a bit more imprecision for a simple implementation seems worth it to me. But I'm of course willing to be convinced otherwise.
2 parents 4a1ce8a + 0969163 commit 13573e8

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/stacked_borrows/stack.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ impl Stack {
4343
pub fn retain(&mut self, tags: &FxHashSet<SbTag>) {
4444
let mut first_removed = None;
4545

46-
// For stacks with a known bottom, we never consider removing the bottom-most tag, because
47-
// that is the base tag which exists whether or not there are any pointers to the
48-
// allocation.
49-
let mut read_idx = if self.unknown_bottom.is_some() { 0 } else { 1 };
46+
// We never consider removing the bottom-most tag. For stacks without an unknown
47+
// bottom this preserves the base tag.
48+
// Note that the algorithm below is based on considering the tag at read_idx - 1,
49+
// so precisely considering the tag at index 0 for removal when we have an unknown
50+
// bottom would complicate the implementation. The simplification of not considering
51+
// it does not have a significant impact on the degree to which the GC mititages
52+
// memory growth.
53+
let mut read_idx = 1;
5054
let mut write_idx = read_idx;
5155
while read_idx < self.borrows.len() {
5256
let left = self.borrows[read_idx - 1];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@compile-flags: -Zmiri-permissive-provenance
2+
#![feature(strict_provenance)]
3+
4+
use std::ptr;
5+
6+
fn main() {
7+
let mut v = 1u8;
8+
let ptr = &mut v as *mut u8;
9+
10+
// Expose the allocation and use the exposed pointer, creating an unknown bottom
11+
unsafe {
12+
let p: *mut u8 = ptr::from_exposed_addr::<u8>(ptr.expose_addr()) as *mut u8;
13+
*p = 1;
14+
}
15+
16+
// Pile on a lot of SharedReadOnly at the top of the stack
17+
let r = &v;
18+
for _ in 0..1024 {
19+
let _x = &*r;
20+
}
21+
}

0 commit comments

Comments
 (0)