@@ -75,15 +75,19 @@ pub struct MemoryExtra {
75
75
pub intptrcast : intptrcast:: MemoryExtra ,
76
76
77
77
/// Mapping extern static names to their canonical allocation.
78
- pub ( crate ) extern_statics : FxHashMap < Symbol , AllocId > ,
78
+ extern_statics : FxHashMap < Symbol , AllocId > ,
79
79
80
80
/// The random number generator used for resolving non-determinism.
81
81
/// Needs to be queried by ptr_to_int, hence needs interior mutability.
82
82
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 > ,
83
87
}
84
88
85
89
impl 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 {
87
91
let stacked_borrows = if stacked_borrows {
88
92
Some ( Rc :: new ( RefCell :: new ( stacked_borrows:: GlobalState :: new ( tracked_pointer_tag) ) ) )
89
93
} else {
@@ -94,6 +98,7 @@ impl MemoryExtra {
94
98
intptrcast : Default :: default ( ) ,
95
99
extern_statics : FxHashMap :: default ( ) ,
96
100
rng : RefCell :: new ( rng) ,
101
+ tracked_alloc_id,
97
102
}
98
103
}
99
104
@@ -329,6 +334,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
329
334
alloc : Cow < ' b , Allocation > ,
330
335
kind : Option < MemoryKind < Self :: MemoryKinds > > ,
331
336
) -> ( 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
+
332
341
let kind = kind. expect ( "we set our STATIC_KIND so this cannot be None" ) ;
333
342
let alloc = alloc. into_owned ( ) ;
334
343
let ( stacks, base_tag) =
0 commit comments