From 7f3fbbdee7cea0b165bd3620d971b78ca35362e7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 30 Jun 2022 18:41:32 -0400 Subject: [PATCH] allocation tracking: also print size, alignment, kind of the allocation --- src/diagnostics.rs | 6 ++++-- src/machine.rs | 9 +++++++-- tests/pass/track-alloc-1.rs | 1 + tests/pass/track-alloc-1.stderr | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 55598c19ef6..1ffcdc799ed 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -6,6 +6,7 @@ use rustc_middle::ty; use rustc_span::{source_map::DUMMY_SP, Span, SpanData, Symbol}; +use rustc_target::abi::{Align, Size}; use crate::helpers::HexRange; use crate::stacked_borrows::{diagnostics::TagHistory, AccessKind}; @@ -71,7 +72,7 @@ pub enum NonHaltingDiagnostic { /// a deallocation when the second argument is `None`. PoppedPointerTag(Item, Option<(SbTagExtra, AccessKind)>), CreatedCallId(CallId), - CreatedAlloc(AllocId), + CreatedAlloc(AllocId, Size, Align, MemoryKind), FreedAlloc(AllocId), RejectedIsolatedOp(String), ProgressReport, @@ -463,7 +464,8 @@ fn process_diagnostics(&self, info: TopFrameInfo<'tcx>) { } }, CreatedCallId(id) => format!("function call with id {id}"), - CreatedAlloc(AllocId(id)) => format!("created allocation with id {id}"), + CreatedAlloc(AllocId(id), size, align, kind) => + format!("created {kind} allocation of {} bytes (alignment {} bytes) with id {id}", size.bytes(), align.bytes()), FreedAlloc(AllocId(id)) => format!("freed allocation with id {id}"), RejectedIsolatedOp(ref op) => format!("{op} was made to return an error due to isolation"), diff --git a/src/machine.rs b/src/machine.rs index 4aeb42d3d0f..abc55cde737 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -624,11 +624,16 @@ fn init_allocation_extra<'b>( alloc: Cow<'b, Allocation>, kind: Option>, ) -> InterpResult<'tcx, Cow<'b, Allocation>> { + let kind = kind.expect("we set our STATIC_KIND so this cannot be None"); if ecx.machine.tracked_alloc_ids.contains(&id) { - register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id)); + register_diagnostic(NonHaltingDiagnostic::CreatedAlloc( + id, + alloc.size(), + alloc.align, + kind, + )); } - let kind = kind.expect("we set our STATIC_KIND so this cannot be None"); let alloc = alloc.into_owned(); let stacks = if let Some(stacked_borrows) = &ecx.machine.stacked_borrows { Some(Stacks::new_allocation( diff --git a/tests/pass/track-alloc-1.rs b/tests/pass/track-alloc-1.rs index 7bb217309f9..bbd88ed5d53 100644 --- a/tests/pass/track-alloc-1.rs +++ b/tests/pass/track-alloc-1.rs @@ -2,4 +2,5 @@ // Early allocations are probably part of the runtime and therefore uninteresting, but they // shouldn't cause a crash. // compile-flags: -Zmiri-track-alloc-id=1 +// normalize-stderr-test: "[48] bytes" -> "SIZE bytes" fn main() {} diff --git a/tests/pass/track-alloc-1.stderr b/tests/pass/track-alloc-1.stderr index be96b729838..7206edbb701 100644 --- a/tests/pass/track-alloc-1.stderr +++ b/tests/pass/track-alloc-1.stderr @@ -1,5 +1,5 @@ note: tracking was triggered | - = note: created allocation with id 1 + = note: created extern static allocation of SIZE bytes (alignment ALIGN bytes) with id 1 = note: (no span available)