Skip to content

Commit 7d75cc4

Browse files
committed
Auto merge of rust-lang#2710 - RalfJung:ptr-tracking-ice, r=oli-obk
fix ICE in pointer tracking Fixes rust-lang/miri#2709
2 parents 4a64902 + 0d1e365 commit 7d75cc4

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs

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

src/tools/miri/src/diagnostics.rs

+4-13
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::borrow_tracker::{stacked_borrows::diagnostics::TagHistory, AccessKind};
9+
use crate::borrow_tracker::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!(

0 commit comments

Comments
 (0)