@@ -75,15 +75,19 @@ pub struct MemoryExtra {
7575 pub intptrcast : intptrcast:: MemoryExtra ,
7676
7777 /// Mapping extern static names to their canonical allocation.
78- pub ( crate ) extern_statics : FxHashMap < Symbol , AllocId > ,
78+ extern_statics : FxHashMap < Symbol , AllocId > ,
7979
8080 /// The random number generator used for resolving non-determinism.
8181 /// Needs to be queried by ptr_to_int, hence needs interior mutability.
8282 pub ( crate ) rng : RefCell < StdRng > ,
83+
84+ /// An allocation ID to report when it is being allocated
85+ /// (helps for debugging memory leaks).
86+ tracked_alloc_id : Option < AllocId > ,
8387}
8488
8589impl MemoryExtra {
86- pub fn new ( rng : StdRng , stacked_borrows : bool , tracked_pointer_tag : Option < PtrId > ) -> Self {
90+ pub fn new ( rng : StdRng , stacked_borrows : bool , tracked_pointer_tag : Option < PtrId > , tracked_alloc_id : Option < AllocId > ) -> Self {
8791 let stacked_borrows = if stacked_borrows {
8892 Some ( Rc :: new ( RefCell :: new ( stacked_borrows:: GlobalState :: new ( tracked_pointer_tag) ) ) )
8993 } else {
@@ -94,6 +98,7 @@ impl MemoryExtra {
9498 intptrcast : Default :: default ( ) ,
9599 extern_statics : FxHashMap :: default ( ) ,
96100 rng : RefCell :: new ( rng) ,
101+ tracked_alloc_id,
97102 }
98103 }
99104
@@ -329,6 +334,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
329334 alloc : Cow < ' b , Allocation > ,
330335 kind : Option < MemoryKind < Self :: MemoryKinds > > ,
331336 ) -> ( Cow < ' b , Allocation < Self :: PointerTag , Self :: AllocExtra > > , Self :: PointerTag ) {
337+ if Some ( id) == memory_extra. tracked_alloc_id {
338+ register_diagnostic ( NonHaltingDiagnostic :: CreatedAlloc ( id) ) ;
339+ }
340+
332341 let kind = kind. expect ( "we set our STATIC_KIND so this cannot be None" ) ;
333342 let alloc = alloc. into_owned ( ) ;
334343 let ( stacks, base_tag) =
0 commit comments