@@ -109,15 +109,16 @@ impl fmt::Display for MiriMemoryKind {
109
109
pub struct AllocExtra {
110
110
/// Stacked Borrows state is only added if it is enabled.
111
111
pub stacked_borrows : Option < stacked_borrows:: AllocExtra > ,
112
- /// Data race detection via the use of a vector-clock.
113
- pub data_race : data_race:: AllocExtra ,
112
+ /// Data race detection via the use of a vector-clock,
113
+ /// this is only added if it is enabled.
114
+ pub data_race : Option < data_race:: AllocExtra > ,
114
115
}
115
116
116
117
/// Extra global memory data
117
118
#[ derive( Clone , Debug ) ]
118
119
pub struct MemoryExtra {
119
120
pub stacked_borrows : Option < stacked_borrows:: MemoryExtra > ,
120
- pub data_race : data_race:: MemoryExtra ,
121
+ pub data_race : Option < data_race:: MemoryExtra > ,
121
122
pub intptrcast : intptrcast:: MemoryExtra ,
122
123
123
124
/// Mapping extern static names to their canonical allocation.
@@ -147,7 +148,11 @@ impl MemoryExtra {
147
148
} else {
148
149
None
149
150
} ;
150
- let data_race = Rc :: new ( data_race:: GlobalState :: new ( ) ) ;
151
+ let data_race = if config. data_race_detector {
152
+ Some ( Rc :: new ( data_race:: GlobalState :: new ( ) ) )
153
+ } else {
154
+ None
155
+ } ;
151
156
MemoryExtra {
152
157
stacked_borrows,
153
158
data_race,
@@ -472,7 +477,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
472
477
// No stacks, no tag.
473
478
( None , Tag :: Untagged )
474
479
} ;
475
- let race_alloc = data_race:: AllocExtra :: new_allocation ( & memory_extra. data_race , alloc. size ) ;
480
+ let race_alloc = if let Some ( data_race) = & memory_extra. data_race {
481
+ Some ( data_race:: AllocExtra :: new_allocation ( & data_race, alloc. size ) )
482
+ } else {
483
+ None
484
+ } ;
476
485
let mut stacked_borrows = memory_extra. stacked_borrows . as_ref ( ) . map ( |sb| sb. borrow_mut ( ) ) ;
477
486
let alloc: Allocation < Tag , Self :: AllocExtra > = alloc. with_tags_and_extra (
478
487
|alloc| {
@@ -590,7 +599,9 @@ impl AllocationExtra<Tag> for AllocExtra {
590
599
ptr : Pointer < Tag > ,
591
600
size : Size ,
592
601
) -> InterpResult < ' tcx > {
593
- alloc. extra . data_race . read ( ptr, size) ?;
602
+ if let Some ( data_race) = & alloc. extra . data_race {
603
+ data_race. read ( ptr, size) ?;
604
+ }
594
605
if let Some ( stacked_borrows) = & alloc. extra . stacked_borrows {
595
606
stacked_borrows. memory_read ( ptr, size)
596
607
} else {
@@ -604,7 +615,9 @@ impl AllocationExtra<Tag> for AllocExtra {
604
615
ptr : Pointer < Tag > ,
605
616
size : Size ,
606
617
) -> InterpResult < ' tcx > {
607
- alloc. extra . data_race . write ( ptr, size) ?;
618
+ if let Some ( data_race) = & mut alloc. extra . data_race {
619
+ data_race. write ( ptr, size) ?;
620
+ }
608
621
if let Some ( stacked_borrows) = & mut alloc. extra . stacked_borrows {
609
622
stacked_borrows. memory_written ( ptr, size)
610
623
} else {
@@ -618,7 +631,9 @@ impl AllocationExtra<Tag> for AllocExtra {
618
631
ptr : Pointer < Tag > ,
619
632
size : Size ,
620
633
) -> InterpResult < ' tcx > {
621
- alloc. extra . data_race . deallocate ( ptr, size) ?;
634
+ if let Some ( data_race) = & mut alloc. extra . data_race {
635
+ data_race. deallocate ( ptr, size) ?;
636
+ }
622
637
if let Some ( stacked_borrows) = & mut alloc. extra . stacked_borrows {
623
638
stacked_borrows. memory_deallocated ( ptr, size)
624
639
} else {
0 commit comments