Skip to content

Commit 02c37c1

Browse files
committed
fix ICE in pointer tracking
1 parent 6ba647a commit 02c37c1

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

src/diagnostics.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use log::trace;
66
use rustc_span::{source_map::DUMMY_SP, SpanData, Symbol};
77
use rustc_target::abi::{Align, Size};
88

9-
use crate::stacked_borrows::{diagnostics::TagHistory, AccessKind};
9+
use crate::stacked_borrows::diagnostics::TagHistory;
1010
use crate::*;
1111

1212
/// Details of premature program termination.
@@ -67,9 +67,8 @@ pub enum NonHaltingDiagnostic {
6767
///
6868
/// new_kind is `None` for base tags.
6969
CreatedPointerTag(NonZeroU64, Option<String>, Option<(AllocId, AllocRange, ProvenanceExtra)>),
70-
/// This `Item` was popped from the borrow stack, either due to an access with the given tag or
71-
/// a deallocation when the second argument is `None`.
72-
PoppedPointerTag(Item, Option<(ProvenanceExtra, AccessKind)>),
70+
/// This `Item` was popped from the borrow stack. The string explains the reason.
71+
PoppedPointerTag(Item, String),
7372
CreatedCallId(CallId),
7473
CreatedAlloc(AllocId, Size, Align, MemoryKind<MiriMemoryKind>),
7574
FreedAlloc(AllocId),
@@ -399,15 +398,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
399398
format!(
400399
"created tag {tag:?} for {kind} at {alloc_id:?}{range:?} derived from {orig_tag:?}"
401400
),
402-
PoppedPointerTag(item, tag) =>
403-
match tag {
404-
None => format!("popped tracked tag for item {item:?} due to deallocation",),
405-
Some((tag, access)) => {
406-
format!(
407-
"popped tracked tag for item {item:?} due to {access:?} access for {tag:?}",
408-
)
409-
}
410-
},
401+
PoppedPointerTag(item, cause) => format!("popped tracked tag for item {item:?}{cause}"),
411402
CreatedCallId(id) => format!("function call with id {id}"),
412403
CreatedAlloc(AllocId(id), size, align, kind) =>
413404
format!(

src/stacked_borrows/diagnostics.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -456,23 +456,18 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
456456
if !global.tracked_pointer_tags.contains(&item.tag()) {
457457
return;
458458
}
459-
let summary = match self.operation {
460-
Operation::Dealloc(_) => None,
461-
Operation::Access(AccessOp { kind, tag, .. }) => Some((tag, kind)),
459+
let cause = match self.operation {
460+
Operation::Dealloc(_) => format!("due to deallocation"),
461+
Operation::Access(AccessOp { kind, tag, .. }) =>
462+
format!("due to {kind:?} access for {tag:?}"),
462463
Operation::Retag(RetagOp { orig_tag, permission, .. }) => {
463-
let kind = match permission
464-
.expect("start_grant should set the current permission before popping a tag")
465-
{
466-
Permission::SharedReadOnly => AccessKind::Read,
467-
Permission::Unique => AccessKind::Write,
468-
Permission::SharedReadWrite | Permission::Disabled => {
469-
panic!("Only SharedReadOnly and Unique retags can pop tags");
470-
}
471-
};
472-
Some((orig_tag, kind))
464+
let permission = permission
465+
.expect("start_grant should set the current permission before popping a tag");
466+
format!("due to {permission:?} retag from {orig_tag:?}")
473467
}
474468
};
475-
self.machine.emit_diagnostic(NonHaltingDiagnostic::PoppedPointerTag(*item, summary));
469+
470+
self.machine.emit_diagnostic(NonHaltingDiagnostic::PoppedPointerTag(*item, cause));
476471
}
477472
}
478473

0 commit comments

Comments
 (0)