Skip to content

Commit 8b36376

Browse files
author
Xinglu Chen
committed
Correctly handle interior mutable data in Box
Previously, the pointee type would be behind a `*const` pointer, so `ty_is_freeze` would always be `true`, even if there was an `UnsafeCell` in `Box`.
1 parent 0238548 commit 8b36376

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'tcx> NewPermission {
173173
pointee.is_unpin(*cx.tcx, cx.typing_env()).then_some(()).map(|()| {
174174
// Regular `Unpin` box, give it `noalias` but only a weak protector
175175
// because it is valid to deallocate it within the function.
176-
let ty_is_freeze = ty.is_freeze(*cx.tcx, cx.typing_env());
176+
let ty_is_freeze = pointee.is_freeze(*cx.tcx, cx.typing_env());
177177
let protected = kind == RetagKind::FnEntry;
178178
let initial_state = Permission::new_reserved(ty_is_freeze, protected);
179179
Self {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@compile-flags: -Zmiri-tree-borrows
2+
#![feature(box_as_ptr)]
3+
#[path = "../../utils/mod.rs"]
4+
#[macro_use]
5+
mod utils;
6+
7+
use std::cell::UnsafeCell;
8+
9+
pub fn main() {
10+
let cell = UnsafeCell::new(42);
11+
let mut root = Box::new(cell);
12+
13+
let a = Box::as_mut_ptr(&mut root);
14+
unsafe {
15+
name!(a);
16+
let alloc_id = alloc_id!(a);
17+
print_state!(alloc_id);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
──────────────────────────────────────────────────
2+
Warning: this tree is indicative only. Some tags may have been hidden.
3+
0.. 4
4+
| Act | └─┬──<TAG=root of the allocation>
5+
| ReIM| └────<TAG=a>
6+
──────────────────────────────────────────────────

0 commit comments

Comments
 (0)