@@ -482,16 +482,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
482
482
// the *value* (including the associated provenance if this is an AtomicPtr) at this location.
483
483
// Only metadata on the location itself is used.
484
484
let scalar = this. allow_data_races_ref ( move |this| this. read_scalar ( & place. into ( ) ) ) ?;
485
- if atomic == AtomicReadOp :: SeqCst {
486
- if let Some ( global) = & this. memory . extra . data_race {
487
- global. sc_read ( ) ;
488
- }
489
- }
490
485
491
486
if let Some ( global) = & this. memory . extra . data_race {
492
487
let ( alloc_id, base_offset, ..) = this. memory . ptr_get_alloc ( place. ptr ) ?;
493
488
if let Some ( alloc_buffers) = this. memory . get_alloc_extra ( alloc_id) ?. weak_memory . as_ref ( )
494
489
{
490
+ if atomic == AtomicReadOp :: SeqCst {
491
+ global. sc_read ( ) ;
492
+ }
495
493
let mut rng = this. memory . extra . rng . borrow_mut ( ) ;
496
494
let loaded = alloc_buffers. buffered_read (
497
495
alloc_range ( base_offset, place. layout . size ) ,
@@ -519,19 +517,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
519
517
let this = self . eval_context_mut ( ) ;
520
518
this. allow_data_races_mut ( move |this| this. write_scalar ( val, & ( * dest) . into ( ) ) ) ?;
521
519
522
- if atomic == AtomicWriteOp :: SeqCst {
523
- if let Some ( global) = this. memory . extra . data_race . as_ref ( ) {
524
- global. sc_write ( ) ;
525
- }
526
- }
527
-
528
520
this. validate_atomic_store ( dest, atomic) ?;
529
521
let ( alloc_id, base_offset, ..) = this. memory . ptr_get_alloc ( dest. ptr ) ?;
530
522
if let (
531
523
crate :: AllocExtra { weak_memory : Some ( alloc_buffers) , .. } ,
532
524
crate :: MemoryExtra { data_race : Some ( global) , .. } ,
533
525
) = this. memory . get_alloc_extra_mut ( alloc_id) ?
534
526
{
527
+ if atomic == AtomicWriteOp :: SeqCst {
528
+ global. sc_write ( ) ;
529
+ }
535
530
let size = dest. layout . size ;
536
531
alloc_buffers. buffered_write (
537
532
val,
@@ -562,12 +557,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
562
557
let val = if neg { this. unary_op ( mir:: UnOp :: Not , & val) ? } else { val } ;
563
558
this. allow_data_races_mut ( |this| this. write_immediate ( * val, & ( * place) . into ( ) ) ) ?;
564
559
565
- if atomic == AtomicRwOp :: SeqCst {
566
- if let Some ( global) = & this. memory . extra . data_race {
567
- global. sc_read ( ) ;
568
- global. sc_write ( ) ;
569
- }
570
- }
571
560
this. validate_atomic_rmw ( place, atomic) ?;
572
561
573
562
this. buffered_atomic_rmw ( val. to_scalar_or_uninit ( ) , place, atomic) ?;
@@ -586,12 +575,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
586
575
587
576
let old = this. allow_data_races_mut ( |this| this. read_scalar ( & place. into ( ) ) ) ?;
588
577
this. allow_data_races_mut ( |this| this. write_scalar ( new, & ( * place) . into ( ) ) ) ?;
589
- if atomic == AtomicRwOp :: SeqCst {
590
- if let Some ( global) = & this. memory . extra . data_race {
591
- global. sc_read ( ) ;
592
- global. sc_write ( ) ;
593
- }
594
- }
578
+
595
579
this. validate_atomic_rmw ( place, atomic) ?;
596
580
597
581
this. buffered_atomic_rmw ( new, place, atomic) ?;
@@ -620,12 +604,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
620
604
621
605
this. allow_data_races_mut ( |this| this. write_immediate ( * * new_val, & ( * place) . into ( ) ) ) ?;
622
606
623
- if atomic == AtomicRwOp :: SeqCst {
624
- if let Some ( global) = & this. memory . extra . data_race {
625
- global. sc_read ( ) ;
626
- global. sc_write ( ) ;
627
- }
628
- }
629
607
this. validate_atomic_rmw ( & place, atomic) ?;
630
608
631
609
this. buffered_atomic_rmw ( new_val. to_scalar_or_uninit ( ) , place, atomic) ?;
@@ -674,27 +652,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
674
652
// otherwise treat this as an atomic load with the fail ordering.
675
653
if cmpxchg_success {
676
654
this. allow_data_races_mut ( |this| this. write_scalar ( new, & ( * place) . into ( ) ) ) ?;
677
- if success == AtomicRwOp :: SeqCst {
678
- if let Some ( global) = & this. memory . extra . data_race {
679
- global. sc_read ( ) ;
680
- global. sc_write ( ) ;
681
- }
682
- }
683
655
this. validate_atomic_rmw ( place, success) ?;
684
656
this. buffered_atomic_rmw ( new, place, success) ?;
685
657
} else {
686
- if fail == AtomicReadOp :: SeqCst {
687
- if let Some ( global) = & this. memory . extra . data_race {
688
- global. sc_read ( ) ;
689
- }
690
- }
691
-
692
658
this. validate_atomic_load ( place, fail) ?;
693
659
// A failed compare exchange is equivalent to a load, reading from the latest store
694
660
// in the modification order.
695
661
// Since `old` is only a value and not the store element, we need to separately
696
662
// find it in our store buffer and perform load_impl on it.
697
663
if let Some ( global) = & this. memory . extra . data_race {
664
+ if fail == AtomicReadOp :: SeqCst {
665
+ global. sc_read ( ) ;
666
+ }
698
667
let size = place. layout . size ;
699
668
let ( alloc_id, base_offset, ..) = this. memory . ptr_get_alloc ( place. ptr ) ?;
700
669
if let Some ( alloc_buffers) =
@@ -724,6 +693,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
724
693
crate :: MemoryExtra { data_race : Some ( global) , .. } ,
725
694
) = this. memory . get_alloc_extra_mut ( alloc_id) ?
726
695
{
696
+ if atomic == AtomicRwOp :: SeqCst {
697
+ global. sc_read ( ) ;
698
+ global. sc_write ( ) ;
699
+ }
727
700
let size = place. layout . size ;
728
701
let range = alloc_range ( base_offset, size) ;
729
702
alloc_buffers. read_from_last_store ( range, global) ;
0 commit comments