Skip to content

Commit 3856f96

Browse files
committed
Provide slightly better notes when tracking a pointer tag
1 parent dadcbeb commit 3856f96

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/diagnostics.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use log::trace;
77
use rustc_middle::ty::{self, TyCtxt};
88
use rustc_span::{source_map::DUMMY_SP, Span, SpanData, Symbol};
99

10+
use crate::stacked_borrows::{AccessKind, SbTag};
1011
use crate::*;
1112

1213
/// Details of premature program termination.
@@ -58,7 +59,7 @@ impl MachineStopType for TerminationInfo {}
5859
/// Miri specific diagnostics
5960
pub enum NonHaltingDiagnostic {
6061
CreatedPointerTag(NonZeroU64),
61-
PoppedPointerTag(Item),
62+
PoppedPointerTag(Item, AccessKind, Option<SbTag>),
6263
CreatedCallId(CallId),
6364
CreatedAlloc(AllocId),
6465
FreedAlloc(AllocId),
@@ -321,7 +322,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
321322
use NonHaltingDiagnostic::*;
322323
let msg = match e {
323324
CreatedPointerTag(tag) => format!("created tag {:?}", tag),
324-
PoppedPointerTag(item) => format!("popped tracked tag for item {:?}", item),
325+
PoppedPointerTag(item, access, tag) =>
326+
match tag {
327+
None => format!("popped tracked tag for item {:?}", item),
328+
Some(tag) => {
329+
format!(
330+
"popped tracked tag for item {:?} due to {:?} access for {:?}",
331+
item, access, tag
332+
)
333+
}
334+
},
325335
CreatedCallId(id) => format!("function call with id {}", id),
326336
CreatedAlloc(AllocId(id)) => format!("created allocation with id {}", id),
327337
FreedAlloc(AllocId(id)) => format!("freed allocation with id {}", id),

src/stacked_borrows.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub struct GlobalState {
111111
pub type MemoryExtra = RefCell<GlobalState>;
112112

113113
/// Indicates which kind of access is being performed.
114-
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
114+
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
115115
pub enum AccessKind {
116116
Read,
117117
Write,
@@ -300,10 +300,15 @@ impl<'tcx> Stack {
300300
item: &Item,
301301
tag: Option<SbTag>,
302302
global: &GlobalState,
303+
cause: AccessKind,
303304
) -> InterpResult<'tcx> {
304305
if let SbTag::Tagged(id) = item.tag {
305306
if Some(id) == global.tracked_pointer_tag {
306-
register_diagnostic(NonHaltingDiagnostic::PoppedPointerTag(item.clone()));
307+
register_diagnostic(NonHaltingDiagnostic::PoppedPointerTag(
308+
item.clone(),
309+
cause,
310+
tag,
311+
));
307312
}
308313
}
309314
if let Some(call) = item.protector {
@@ -348,7 +353,7 @@ impl<'tcx> Stack {
348353
let first_incompatible_idx = self.find_first_write_incompatible(granting_idx);
349354
for item in self.borrows.drain(first_incompatible_idx..).rev() {
350355
trace!("access: popping item {:?}", item);
351-
Stack::check_protector(&item, Some(tag), global)?;
356+
Stack::check_protector(&item, Some(tag), global, access)?;
352357
}
353358
} else {
354359
// On a read, *disable* all `Unique` above the granting item. This ensures U2 for read accesses.
@@ -363,7 +368,7 @@ impl<'tcx> Stack {
363368
let item = &mut self.borrows[idx];
364369
if item.perm == Permission::Unique {
365370
trace!("access: disabling item {:?}", item);
366-
Stack::check_protector(item, Some(tag), global)?;
371+
Stack::check_protector(item, Some(tag), global, access)?;
367372
item.perm = Permission::Disabled;
368373
}
369374
}
@@ -391,7 +396,7 @@ impl<'tcx> Stack {
391396

392397
// Step 2: Remove all items. Also checks for protectors.
393398
for item in self.borrows.drain(..).rev() {
394-
Stack::check_protector(&item, None, global)?;
399+
Stack::check_protector(&item, None, global, AccessKind::Write)?;
395400
}
396401

397402
Ok(())

0 commit comments

Comments
 (0)