make the new option actually do something
This commit is contained in:
parent
d82d701360
commit
ade4c4e733
3 changed files with 11 additions and 1 deletions
|
|
@ -180,6 +180,8 @@ Several `-Z` flags are relevant for Miri:
|
|||
is popped from a borrow stack (which is where the tag becomes invalid and any
|
||||
future use of it will error). This helps you in finding out why UB is
|
||||
happening and where in your code would be a good place to look for it.
|
||||
* `-Zmiri-track-alloc-id=<id>` shows a backtrace when the given allocation is
|
||||
being allocated. This helps in debugging memory leaks.
|
||||
|
||||
Moreover, Miri recognizes some environment variables:
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::*;
|
|||
/// Miri specific diagnostics
|
||||
pub enum NonHaltingDiagnostic {
|
||||
PoppedTrackedPointerTag(Item),
|
||||
CreatedAlloc(AllocId),
|
||||
}
|
||||
|
||||
/// Emit a custom diagnostic without going through the miri-engine machinery
|
||||
|
|
@ -97,9 +98,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let this = self.eval_context_ref();
|
||||
DIAGNOSTICS.with(|diagnostics| {
|
||||
for e in diagnostics.borrow_mut().drain(..) {
|
||||
use NonHaltingDiagnostic::*;
|
||||
let msg = match e {
|
||||
NonHaltingDiagnostic::PoppedTrackedPointerTag(item) =>
|
||||
PoppedTrackedPointerTag(item) =>
|
||||
format!("popped tracked tag for item {:?}", item),
|
||||
CreatedAlloc(AllocId(id)) =>
|
||||
format!("created allocation with id {}", id),
|
||||
};
|
||||
report_msg(this, msg, false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,6 +334,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
|
|||
alloc: Cow<'b, Allocation>,
|
||||
kind: Option<MemoryKind<Self::MemoryKinds>>,
|
||||
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag) {
|
||||
if Some(id) == memory_extra.tracked_alloc_id {
|
||||
register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id));
|
||||
}
|
||||
|
||||
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
|
||||
let alloc = alloc.into_owned();
|
||||
let (stacks, base_tag) =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue