Skip to content

Commit f9e0cf4

Browse files
committed
Auto merge of #2295 - RalfJung:better-alloc-tracking, r=RalfJung
allocation tracking: also print size, alignment, kind of the allocation
2 parents 38effb3 + 7f3fbbd commit f9e0cf4

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/diagnostics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use log::trace;
66

77
use rustc_middle::ty;
88
use rustc_span::{source_map::DUMMY_SP, Span, SpanData, Symbol};
9+
use rustc_target::abi::{Align, Size};
910

1011
use crate::helpers::HexRange;
1112
use crate::stacked_borrows::{diagnostics::TagHistory, AccessKind};
@@ -71,7 +72,7 @@ pub enum NonHaltingDiagnostic {
7172
/// a deallocation when the second argument is `None`.
7273
PoppedPointerTag(Item, Option<(SbTagExtra, AccessKind)>),
7374
CreatedCallId(CallId),
74-
CreatedAlloc(AllocId),
75+
CreatedAlloc(AllocId, Size, Align, MemoryKind<MiriMemoryKind>),
7576
FreedAlloc(AllocId),
7677
RejectedIsolatedOp(String),
7778
ProgressReport,
@@ -463,7 +464,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
463464
}
464465
},
465466
CreatedCallId(id) => format!("function call with id {id}"),
466-
CreatedAlloc(AllocId(id)) => format!("created allocation with id {id}"),
467+
CreatedAlloc(AllocId(id), size, align, kind) =>
468+
format!("created {kind} allocation of {} bytes (alignment {} bytes) with id {id}", size.bytes(), align.bytes()),
467469
FreedAlloc(AllocId(id)) => format!("freed allocation with id {id}"),
468470
RejectedIsolatedOp(ref op) =>
469471
format!("{op} was made to return an error due to isolation"),

src/machine.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,16 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
624624
alloc: Cow<'b, Allocation>,
625625
kind: Option<MemoryKind<Self::MemoryKind>>,
626626
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>> {
627+
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
627628
if ecx.machine.tracked_alloc_ids.contains(&id) {
628-
register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id));
629+
register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(
630+
id,
631+
alloc.size(),
632+
alloc.align,
633+
kind,
634+
));
629635
}
630636

631-
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
632637
let alloc = alloc.into_owned();
633638
let stacks = if let Some(stacked_borrows) = &ecx.machine.stacked_borrows {
634639
Some(Stacks::new_allocation(

tests/pass/track-alloc-1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
// Early allocations are probably part of the runtime and therefore uninteresting, but they
33
// shouldn't cause a crash.
44
// compile-flags: -Zmiri-track-alloc-id=1
5+
// normalize-stderr-test: "[48] bytes" -> "SIZE bytes"
56
fn main() {}

tests/pass/track-alloc-1.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
note: tracking was triggered
22
|
3-
= note: created allocation with id 1
3+
= note: created extern static allocation of SIZE bytes (alignment ALIGN bytes) with id 1
44
= note: (no span available)
55

0 commit comments

Comments
 (0)