@@ -109,15 +109,16 @@ impl fmt::Display for MiriMemoryKind {
109109pub struct AllocExtra {
110110 /// Stacked Borrows state is only added if it is enabled.
111111 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 > ,
114115}
115116
116117/// Extra global memory data
117118#[ derive( Clone , Debug ) ]
118119pub struct MemoryExtra {
119120 pub stacked_borrows : Option < stacked_borrows:: MemoryExtra > ,
120- pub data_race : data_race:: MemoryExtra ,
121+ pub data_race : Option < data_race:: MemoryExtra > ,
121122 pub intptrcast : intptrcast:: MemoryExtra ,
122123
123124 /// Mapping extern static names to their canonical allocation.
@@ -147,7 +148,11 @@ impl MemoryExtra {
147148 } else {
148149 None
149150 } ;
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+ } ;
151156 MemoryExtra {
152157 stacked_borrows,
153158 data_race,
@@ -472,7 +477,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
472477 // No stacks, no tag.
473478 ( None , Tag :: Untagged )
474479 } ;
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+ } ;
476485 let mut stacked_borrows = memory_extra. stacked_borrows . as_ref ( ) . map ( |sb| sb. borrow_mut ( ) ) ;
477486 let alloc: Allocation < Tag , Self :: AllocExtra > = alloc. with_tags_and_extra (
478487 |alloc| {
@@ -590,7 +599,9 @@ impl AllocationExtra<Tag> for AllocExtra {
590599 ptr : Pointer < Tag > ,
591600 size : Size ,
592601 ) -> 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+ }
594605 if let Some ( stacked_borrows) = & alloc. extra . stacked_borrows {
595606 stacked_borrows. memory_read ( ptr, size)
596607 } else {
@@ -604,7 +615,9 @@ impl AllocationExtra<Tag> for AllocExtra {
604615 ptr : Pointer < Tag > ,
605616 size : Size ,
606617 ) -> 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+ }
608621 if let Some ( stacked_borrows) = & mut alloc. extra . stacked_borrows {
609622 stacked_borrows. memory_written ( ptr, size)
610623 } else {
@@ -618,7 +631,9 @@ impl AllocationExtra<Tag> for AllocExtra {
618631 ptr : Pointer < Tag > ,
619632 size : Size ,
620633 ) -> 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+ }
622637 if let Some ( stacked_borrows) = & mut alloc. extra . stacked_borrows {
623638 stacked_borrows. memory_deallocated ( ptr, size)
624639 } else {
0 commit comments