@@ -512,6 +512,8 @@ pub struct MiriMachine<'mir, 'tcx> {
512
512
/// The allocation IDs to report when they are being allocated
513
513
/// (helps for debugging memory leaks and use after free bugs).
514
514
tracked_alloc_ids : FxHashSet < AllocId > ,
515
+ /// For the tracked alloc ids, also report read/write accesses.
516
+ track_alloc_accesses : bool ,
515
517
516
518
/// Controls whether alignment of memory accesses is being checked.
517
519
pub ( crate ) check_alignment : AlignmentCheck ,
@@ -654,6 +656,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
654
656
extern_statics : FxHashMap :: default ( ) ,
655
657
rng : RefCell :: new ( rng) ,
656
658
tracked_alloc_ids : config. tracked_alloc_ids . clone ( ) ,
659
+ track_alloc_accesses : config. track_alloc_accesses ,
657
660
check_alignment : config. check_alignment ,
658
661
cmpxchg_weak_failure_rate : config. cmpxchg_weak_failure_rate ,
659
662
mute_stdout_stderr : config. mute_stdout_stderr ,
@@ -793,6 +796,7 @@ impl VisitProvenance for MiriMachine<'_, '_> {
793
796
local_crates : _,
794
797
rng : _,
795
798
tracked_alloc_ids : _,
799
+ track_alloc_accesses : _,
796
800
check_alignment : _,
797
801
cmpxchg_weak_failure_rate : _,
798
802
mute_stdout_stderr : _,
@@ -1235,6 +1239,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1235
1239
( alloc_id, prov_extra) : ( AllocId , Self :: ProvenanceExtra ) ,
1236
1240
range : AllocRange ,
1237
1241
) -> InterpResult < ' tcx > {
1242
+ if machine. track_alloc_accesses && machine. tracked_alloc_ids . contains ( & alloc_id) {
1243
+ machine
1244
+ . emit_diagnostic ( NonHaltingDiagnostic :: AccessedAlloc ( alloc_id, AccessKind :: Read ) ) ;
1245
+ }
1238
1246
if let Some ( data_race) = & alloc_extra. data_race {
1239
1247
data_race. read ( alloc_id, range, machine) ?;
1240
1248
}
@@ -1255,6 +1263,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1255
1263
( alloc_id, prov_extra) : ( AllocId , Self :: ProvenanceExtra ) ,
1256
1264
range : AllocRange ,
1257
1265
) -> InterpResult < ' tcx > {
1266
+ if machine. track_alloc_accesses && machine. tracked_alloc_ids . contains ( & alloc_id) {
1267
+ machine
1268
+ . emit_diagnostic ( NonHaltingDiagnostic :: AccessedAlloc ( alloc_id, AccessKind :: Write ) ) ;
1269
+ }
1258
1270
if let Some ( data_race) = & mut alloc_extra. data_race {
1259
1271
data_race. write ( alloc_id, range, machine) ?;
1260
1272
}
0 commit comments