Skip to content

Commit 234f59d

Browse files
committed
adjust for init_allocation_extra
1 parent 0978e4f commit 234f59d

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/machine.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -291,27 +291,24 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
291291
Ok(())
292292
}
293293

294-
fn tag_allocation<'b>(
294+
fn init_allocation_extra<'b>(
295295
memory_extra: &MemoryExtra,
296296
id: AllocId,
297297
alloc: Cow<'b, Allocation>,
298298
kind: Option<MemoryKind<Self::MemoryKinds>>,
299-
) -> (
300-
Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>,
301-
Self::PointerTag,
302-
) {
299+
) -> Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>> {
303300
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
304301
let alloc = alloc.into_owned();
305-
let (stacks, base_tag) = if !memory_extra.validate {
306-
(None, Tag::Untagged)
307-
} else {
308-
let (stacks, base_tag) = Stacks::new_allocation(
302+
let stacks = if memory_extra.validate {
303+
Some(Stacks::new_allocation(
309304
id,
310305
alloc.size,
311306
Rc::clone(&memory_extra.stacked_borrows),
312307
kind,
313-
);
314-
(Some(stacks), base_tag)
308+
))
309+
} else {
310+
// No stacks.
311+
None
315312
};
316313
let mut stacked_borrows = memory_extra.stacked_borrows.borrow_mut();
317314
let alloc: Allocation<Tag, Self::AllocExtra> = alloc.with_tags_and_extra(
@@ -328,7 +325,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
328325
stacked_borrows: stacks,
329326
},
330327
);
331-
(Cow::Owned(alloc), base_tag)
328+
Cow::Owned(alloc)
332329
}
333330

334331
#[inline(always)]

src/stacked_borrows.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl Stacks {
462462
size: Size,
463463
extra: MemoryExtra,
464464
kind: MemoryKind<MiriMemoryKind>,
465-
) -> (Self, Tag) {
465+
) -> Self {
466466
let (tag, perm) = match kind {
467467
MemoryKind::Stack =>
468468
// New unique borrow. This tag is not accessible by the program,
@@ -472,12 +472,15 @@ impl Stacks {
472472
// and in particular, *all* raw pointers.
473473
(Tag::Tagged(extra.borrow_mut().new_ptr()), Permission::Unique),
474474
MemoryKind::Machine(MiriMemoryKind::Static) =>
475+
// Statics are inherently shared, so we do not derive any uniqueness assumptions
476+
// from direct accesses to a static. Thus, the base permission is `SharedReadWrite`.
475477
(extra.borrow_mut().static_base_ptr(id), Permission::SharedReadWrite),
476478
_ =>
479+
// Everything else we handle entirely untagged for now.
480+
// FIXME: experiment with more precise tracking.
477481
(Tag::Untagged, Permission::SharedReadWrite),
478482
};
479-
let stack = Stacks::new(size, perm, tag, extra);
480-
(stack, tag)
483+
Stacks::new(size, perm, tag, extra)
481484
}
482485

483486
#[inline(always)]
@@ -591,7 +594,12 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
591594

592595
// Compute new borrow.
593596
let new_tag = match kind {
597+
// Give up tracking for raw pointers.
598+
// FIXME: Experiment with more precise tracking. Blocked on `&raw`
599+
// because `Rc::into_raw` currently creates intermediate references,
600+
// breaking `Rc::from_raw`.
594601
RefKind::Raw { .. } => Tag::Untagged,
602+
// All other pointesr are properly tracked.
595603
_ => Tag::Tagged(this.memory.extra.stacked_borrows.borrow_mut().new_ptr()),
596604
};
597605

0 commit comments

Comments
 (0)