@@ -275,20 +275,20 @@ impl MemoryCellClocks {
275275 /// not used previously as atomic memory.
276276 fn load_acquire (
277277 & mut self ,
278- clocks : & mut ThreadClockSet ,
278+ thread_clocks : & mut ThreadClockSet ,
279279 index : VectorIdx ,
280280 ) -> Result < ( ) , DataRace > {
281- self . atomic_read_detect ( clocks , index) ?;
281+ self . atomic_read_detect ( thread_clocks , index) ?;
282282 if let Some ( atomic) = self . atomic ( ) {
283- clocks . clock . join ( & atomic. sync_vector ) ;
283+ thread_clocks . clock . join ( & atomic. sync_vector ) ;
284284 }
285285 Ok ( ( ) )
286286 }
287287
288288 /// Checks if the memory cell access is ordered with all prior atomic reads and writes
289- fn race_free_with_atomic ( & self , clocks : & ThreadClockSet ) -> bool {
289+ fn race_free_with_atomic ( & self , thread_clocks : & ThreadClockSet ) -> bool {
290290 if let Some ( atomic) = self . atomic ( ) {
291- atomic. read_vector <= clocks . clock && atomic. write_vector <= clocks . clock
291+ atomic. read_vector <= thread_clocks . clock && atomic. write_vector <= thread_clocks . clock
292292 } else {
293293 true
294294 }
@@ -299,81 +299,97 @@ impl MemoryCellClocks {
299299 /// not used previously as atomic memory.
300300 fn load_relaxed (
301301 & mut self ,
302- clocks : & mut ThreadClockSet ,
302+ thread_clocks : & mut ThreadClockSet ,
303303 index : VectorIdx ,
304304 ) -> Result < ( ) , DataRace > {
305- self . atomic_read_detect ( clocks , index) ?;
305+ self . atomic_read_detect ( thread_clocks , index) ?;
306306 if let Some ( atomic) = self . atomic ( ) {
307- clocks . fence_acquire . join ( & atomic. sync_vector ) ;
307+ thread_clocks . fence_acquire . join ( & atomic. sync_vector ) ;
308308 }
309309 Ok ( ( ) )
310310 }
311311
312312 /// Update the memory cell data-race tracking for atomic
313313 /// store release semantics.
314- fn store_release ( & mut self , clocks : & ThreadClockSet , index : VectorIdx ) -> Result < ( ) , DataRace > {
315- self . atomic_write_detect ( clocks, index) ?;
314+ fn store_release (
315+ & mut self ,
316+ thread_clocks : & ThreadClockSet ,
317+ index : VectorIdx ,
318+ ) -> Result < ( ) , DataRace > {
319+ self . atomic_write_detect ( thread_clocks, index) ?;
316320 let atomic = self . atomic_mut ( ) ;
317- atomic. sync_vector . clone_from ( & clocks . clock ) ;
321+ atomic. sync_vector . clone_from ( & thread_clocks . clock ) ;
318322 Ok ( ( ) )
319323 }
320324
321325 /// Update the memory cell data-race tracking for atomic
322326 /// store relaxed semantics.
323- fn store_relaxed ( & mut self , clocks : & ThreadClockSet , index : VectorIdx ) -> Result < ( ) , DataRace > {
324- self . atomic_write_detect ( clocks, index) ?;
327+ fn store_relaxed (
328+ & mut self ,
329+ thread_clocks : & ThreadClockSet ,
330+ index : VectorIdx ,
331+ ) -> Result < ( ) , DataRace > {
332+ self . atomic_write_detect ( thread_clocks, index) ?;
325333
326334 // The handling of release sequences was changed in C++20 and so
327335 // the code here is different to the paper since now all relaxed
328336 // stores block release sequences. The exception for same-thread
329337 // relaxed stores has been removed.
330338 let atomic = self . atomic_mut ( ) ;
331- atomic. sync_vector . clone_from ( & clocks . fence_release ) ;
339+ atomic. sync_vector . clone_from ( & thread_clocks . fence_release ) ;
332340 Ok ( ( ) )
333341 }
334342
335343 /// Update the memory cell data-race tracking for atomic
336344 /// store release semantics for RMW operations.
337- fn rmw_release ( & mut self , clocks : & ThreadClockSet , index : VectorIdx ) -> Result < ( ) , DataRace > {
338- self . atomic_write_detect ( clocks, index) ?;
345+ fn rmw_release (
346+ & mut self ,
347+ thread_clocks : & ThreadClockSet ,
348+ index : VectorIdx ,
349+ ) -> Result < ( ) , DataRace > {
350+ self . atomic_write_detect ( thread_clocks, index) ?;
339351 let atomic = self . atomic_mut ( ) ;
340- atomic. sync_vector . join ( & clocks . clock ) ;
352+ atomic. sync_vector . join ( & thread_clocks . clock ) ;
341353 Ok ( ( ) )
342354 }
343355
344356 /// Update the memory cell data-race tracking for atomic
345357 /// store relaxed semantics for RMW operations.
346- fn rmw_relaxed ( & mut self , clocks : & ThreadClockSet , index : VectorIdx ) -> Result < ( ) , DataRace > {
347- self . atomic_write_detect ( clocks, index) ?;
358+ fn rmw_relaxed (
359+ & mut self ,
360+ thread_clocks : & ThreadClockSet ,
361+ index : VectorIdx ,
362+ ) -> Result < ( ) , DataRace > {
363+ self . atomic_write_detect ( thread_clocks, index) ?;
348364 let atomic = self . atomic_mut ( ) ;
349- atomic. sync_vector . join ( & clocks . fence_release ) ;
365+ atomic. sync_vector . join ( & thread_clocks . fence_release ) ;
350366 Ok ( ( ) )
351367 }
352368
353369 /// Detect data-races with an atomic read, caused by a non-atomic write that does
354370 /// not happen-before the atomic-read.
355371 fn atomic_read_detect (
356372 & mut self ,
357- clocks : & ThreadClockSet ,
373+ thread_clocks : & ThreadClockSet ,
358374 index : VectorIdx ,
359375 ) -> Result < ( ) , DataRace > {
360- log:: trace!( "Atomic read with vectors: {:#?} :: {:#?}" , self , clocks ) ;
376+ log:: trace!( "Atomic read with vectors: {:#?} :: {:#?}" , self , thread_clocks ) ;
361377 let atomic = self . atomic_mut ( ) ;
362- atomic. read_vector . set_at_index ( & clocks . clock , index) ;
363- if self . write <= clocks . clock [ self . write_index ] { Ok ( ( ) ) } else { Err ( DataRace ) }
378+ atomic. read_vector . set_at_index ( & thread_clocks . clock , index) ;
379+ if self . write <= thread_clocks . clock [ self . write_index ] { Ok ( ( ) ) } else { Err ( DataRace ) }
364380 }
365381
366382 /// Detect data-races with an atomic write, either with a non-atomic read or with
367383 /// a non-atomic write.
368384 fn atomic_write_detect (
369385 & mut self ,
370- clocks : & ThreadClockSet ,
386+ thread_clocks : & ThreadClockSet ,
371387 index : VectorIdx ,
372388 ) -> Result < ( ) , DataRace > {
373- log:: trace!( "Atomic write with vectors: {:#?} :: {:#?}" , self , clocks ) ;
389+ log:: trace!( "Atomic write with vectors: {:#?} :: {:#?}" , self , thread_clocks ) ;
374390 let atomic = self . atomic_mut ( ) ;
375- atomic. write_vector . set_at_index ( & clocks . clock , index) ;
376- if self . write <= clocks . clock [ self . write_index ] && self . read <= clocks . clock {
391+ atomic. write_vector . set_at_index ( & thread_clocks . clock , index) ;
392+ if self . write <= thread_clocks . clock [ self . write_index ] && self . read <= thread_clocks . clock {
377393 Ok ( ( ) )
378394 } else {
379395 Err ( DataRace )
@@ -384,21 +400,21 @@ impl MemoryCellClocks {
384400 /// returns true if a data-race is detected.
385401 fn read_race_detect (
386402 & mut self ,
387- clocks : & mut ThreadClockSet ,
403+ thread_clocks : & mut ThreadClockSet ,
388404 index : VectorIdx ,
389405 current_span : Span ,
390406 ) -> Result < ( ) , DataRace > {
391- log:: trace!( "Unsynchronized read with vectors: {:#?} :: {:#?}" , self , clocks ) ;
407+ log:: trace!( "Unsynchronized read with vectors: {:#?} :: {:#?}" , self , thread_clocks ) ;
392408 if !current_span. is_dummy ( ) {
393- clocks . clock [ index] . span = current_span;
409+ thread_clocks . clock [ index] . span = current_span;
394410 }
395- if self . write <= clocks . clock [ self . write_index ] {
411+ if self . write <= thread_clocks . clock [ self . write_index ] {
396412 let race_free = if let Some ( atomic) = self . atomic ( ) {
397- atomic. write_vector <= clocks . clock
413+ atomic. write_vector <= thread_clocks . clock
398414 } else {
399415 true
400416 } ;
401- self . read . set_at_index ( & clocks . clock , index) ;
417+ self . read . set_at_index ( & thread_clocks . clock , index) ;
402418 if race_free { Ok ( ( ) ) } else { Err ( DataRace ) }
403419 } else {
404420 Err ( DataRace )
@@ -409,22 +425,23 @@ impl MemoryCellClocks {
409425 /// returns true if a data-race is detected.
410426 fn write_race_detect (
411427 & mut self ,
412- clocks : & mut ThreadClockSet ,
428+ thread_clocks : & mut ThreadClockSet ,
413429 index : VectorIdx ,
414430 write_type : WriteType ,
415431 current_span : Span ,
416432 ) -> Result < ( ) , DataRace > {
417- log:: trace!( "Unsynchronized write with vectors: {:#?} :: {:#?}" , self , clocks ) ;
433+ log:: trace!( "Unsynchronized write with vectors: {:#?} :: {:#?}" , self , thread_clocks ) ;
418434 if !current_span. is_dummy ( ) {
419- clocks . clock [ index] . span = current_span;
435+ thread_clocks . clock [ index] . span = current_span;
420436 }
421- if self . write <= clocks . clock [ self . write_index ] && self . read <= clocks . clock {
437+ if self . write <= thread_clocks . clock [ self . write_index ] && self . read <= thread_clocks . clock {
422438 let race_free = if let Some ( atomic) = self . atomic ( ) {
423- atomic. write_vector <= clocks. clock && atomic. read_vector <= clocks. clock
439+ atomic. write_vector <= thread_clocks. clock
440+ && atomic. read_vector <= thread_clocks. clock
424441 } else {
425442 true
426443 } ;
427- self . write = clocks . clock [ index] ;
444+ self . write = thread_clocks . clock [ index] ;
428445 self . write_index = index;
429446 self . write_type = write_type;
430447 if race_free {
@@ -764,24 +781,24 @@ impl VClockAlloc {
764781 fn report_data_race < ' tcx > (
765782 global : & GlobalState ,
766783 thread_mgr : & ThreadManager < ' _ , ' _ > ,
767- range : & MemoryCellClocks ,
784+ mem_clocks : & MemoryCellClocks ,
768785 action : & str ,
769786 is_atomic : bool ,
770787 ptr_dbg : Pointer < AllocId > ,
771788 ) -> InterpResult < ' tcx > {
772789 let ( current_index, current_clocks) = global. current_thread_state ( thread_mgr) ;
773790 let write_clock;
774- let ( other_action, other_thread, other_clock) = if range . write
775- > current_clocks. clock [ range . write_index ]
791+ let ( other_action, other_thread, other_clock) = if mem_clocks . write
792+ > current_clocks. clock [ mem_clocks . write_index ]
776793 {
777794 // Convert the write action into the vector clock it
778795 // represents for diagnostic purposes.
779- write_clock = VClock :: new_with_index ( range . write_index , range . write ) ;
780- ( range . write_type . get_descriptor ( ) , range . write_index , & write_clock)
781- } else if let Some ( idx) = Self :: find_gt_index ( & range . read , & current_clocks. clock ) {
782- ( "Read" , idx, & range . read )
796+ write_clock = VClock :: new_with_index ( mem_clocks . write_index , mem_clocks . write ) ;
797+ ( mem_clocks . write_type . get_descriptor ( ) , mem_clocks . write_index , & write_clock)
798+ } else if let Some ( idx) = Self :: find_gt_index ( & mem_clocks . read , & current_clocks. clock ) {
799+ ( "Read" , idx, & mem_clocks . read )
783800 } else if !is_atomic {
784- if let Some ( atomic) = range . atomic ( ) {
801+ if let Some ( atomic) = mem_clocks . atomic ( ) {
785802 if let Some ( idx) = Self :: find_gt_index ( & atomic. write_vector , & current_clocks. clock )
786803 {
787804 ( "Atomic Store" , idx, & atomic. write_vector )
@@ -832,10 +849,10 @@ impl VClockAlloc {
832849 thread_mgr : & ThreadManager < ' _ , ' _ > ,
833850 ) -> bool {
834851 if global. race_detecting ( ) {
835- let ( _, clocks ) = global. current_thread_state ( thread_mgr) ;
852+ let ( _, thread_clocks ) = global. current_thread_state ( thread_mgr) ;
836853 let alloc_ranges = self . alloc_ranges . borrow ( ) ;
837- for ( _, range ) in alloc_ranges. iter ( range. start , range. size ) {
838- if !range . race_free_with_atomic ( & clocks ) {
854+ for ( _, mem_clocks ) in alloc_ranges. iter ( range. start , range. size ) {
855+ if !mem_clocks . race_free_with_atomic ( & thread_clocks ) {
839856 return false ;
840857 }
841858 }
@@ -857,16 +874,18 @@ impl VClockAlloc {
857874 let current_span = machine. current_span ( ) ;
858875 let global = machine. data_race . as_ref ( ) . unwrap ( ) ;
859876 if global. race_detecting ( ) {
860- let ( index, mut clocks ) = global. current_thread_state_mut ( & machine. threads ) ;
877+ let ( index, mut thread_clocks ) = global. current_thread_state_mut ( & machine. threads ) ;
861878 let mut alloc_ranges = self . alloc_ranges . borrow_mut ( ) ;
862- for ( offset, range) in alloc_ranges. iter_mut ( range. start , range. size ) {
863- if let Err ( DataRace ) = range. read_race_detect ( & mut clocks, index, current_span) {
864- drop ( clocks) ;
879+ for ( offset, mem_clocks) in alloc_ranges. iter_mut ( range. start , range. size ) {
880+ if let Err ( DataRace ) =
881+ mem_clocks. read_race_detect ( & mut thread_clocks, index, current_span)
882+ {
883+ drop ( thread_clocks) ;
865884 // Report data-race.
866885 return Self :: report_data_race (
867886 global,
868887 & machine. threads ,
869- range ,
888+ mem_clocks ,
870889 "Read" ,
871890 false ,
872891 Pointer :: new ( alloc_id, offset) ,
@@ -890,17 +909,22 @@ impl VClockAlloc {
890909 let current_span = machine. current_span ( ) ;
891910 let global = machine. data_race . as_mut ( ) . unwrap ( ) ;
892911 if global. race_detecting ( ) {
893- let ( index, mut clocks) = global. current_thread_state_mut ( & machine. threads ) ;
894- for ( offset, range) in self . alloc_ranges . get_mut ( ) . iter_mut ( range. start , range. size ) {
895- if let Err ( DataRace ) =
896- range. write_race_detect ( & mut clocks, index, write_type, current_span)
897- {
898- drop ( clocks) ;
912+ let ( index, mut thread_clocks) = global. current_thread_state_mut ( & machine. threads ) ;
913+ for ( offset, mem_clocks) in
914+ self . alloc_ranges . get_mut ( ) . iter_mut ( range. start , range. size )
915+ {
916+ if let Err ( DataRace ) = mem_clocks. write_race_detect (
917+ & mut thread_clocks,
918+ index,
919+ write_type,
920+ current_span,
921+ ) {
922+ drop ( thread_clocks) ;
899923 // Report data-race
900924 return Self :: report_data_race (
901925 global,
902926 & machine. threads ,
903- range ,
927+ mem_clocks ,
904928 write_type. get_descriptor ( ) ,
905929 false ,
906930 Pointer :: new ( alloc_id, offset) ,
@@ -1125,16 +1149,17 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
11251149 data_race. maybe_perform_sync_operation (
11261150 & this. machine . threads ,
11271151 current_span,
1128- |index, mut clocks | {
1129- for ( offset, range ) in
1152+ |index, mut thread_clocks | {
1153+ for ( offset, mem_clocks ) in
11301154 alloc_meta. alloc_ranges . borrow_mut ( ) . iter_mut ( base_offset, size)
11311155 {
1132- if let Err ( DataRace ) = op ( range, & mut clocks, index, atomic) {
1133- mem:: drop ( clocks) ;
1156+ if let Err ( DataRace ) = op ( mem_clocks, & mut thread_clocks, index, atomic)
1157+ {
1158+ mem:: drop ( thread_clocks) ;
11341159 return VClockAlloc :: report_data_race (
11351160 data_race,
11361161 & this. machine . threads ,
1137- range ,
1162+ mem_clocks ,
11381163 description,
11391164 true ,
11401165 Pointer :: new ( alloc_id, offset) ,
@@ -1150,13 +1175,14 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
11501175
11511176 // Log changes to atomic memory.
11521177 if log:: log_enabled!( log:: Level :: Trace ) {
1153- for ( _offset, range) in alloc_meta. alloc_ranges . borrow ( ) . iter ( base_offset, size)
1178+ for ( _offset, mem_clocks) in
1179+ alloc_meta. alloc_ranges . borrow ( ) . iter ( base_offset, size)
11541180 {
11551181 log:: trace!(
11561182 "Updated atomic memory({:?}, size={}) to {:#?}" ,
11571183 place. ptr,
11581184 size. bytes( ) ,
1159- range . atomic_ops
1185+ mem_clocks . atomic_ops
11601186 ) ;
11611187 }
11621188 }
0 commit comments