Skip to content

Commit 30b5791

Browse files
add test
1 parent 5a6639b commit 30b5791

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/data_race.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
557557

558558
// `binary_op` will bail if either of them is not a scalar.
559559
let cond = if min {
560-
this.overflowing_binary_op(mir::BinOp::Lt, old, rhs)?.0
560+
this.overflowing_binary_op(mir::BinOp::Lt, &old, &rhs)?.0
561561
} else {
562-
this.overflowing_binary_op(mir::BinOp::Gt, old, rhs)?.0
562+
this.overflowing_binary_op(mir::BinOp::Gt, &old, &rhs)?.0
563563
};
564564

565565
if cond.to_bool()? {
566566
this.allow_data_races_mut(|this| this.write_immediate(*rhs, place.into()))?;
567567
}
568568

569-
this.validate_atomic_rmw(place, atomic)?;
569+
this.validate_atomic_rmw(&place, atomic)?;
570570
// Return the old value.
571571
Ok(old)
572572
}

src/shims/intrinsics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,18 +686,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
686686
fn atomic_min_max(
687687
&mut self,
688688
args: &[OpTy<'tcx, Tag>],
689-
dest: PlaceTy<'tcx, Tag>,
689+
dest: &PlaceTy<'tcx, Tag>,
690690
min: bool,
691691
atomic: AtomicRwOp,
692692
) -> InterpResult<'tcx> {
693693
let this = self.eval_context_mut();
694694

695695
let &[place, rhs] = check_arg_count(args)?;
696-
let place = this.deref_operand(place)?;
696+
let place = this.deref_operand(&place)?;
697697
if !place.layout.ty.is_integral() {
698698
bug!("Atomic arithmetic operations only work on integer types");
699699
}
700-
let rhs = this.read_immediate(rhs)?;
700+
let rhs = this.read_immediate(&rhs)?;
701701

702702
// Check alignment requirements. Atomics must always be aligned to their size,
703703
// even if the type they wrap would be less aligned (e.g. AtomicU64 on 32bit must
@@ -706,7 +706,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
706706
this.memory.check_ptr_access(place.ptr, place.layout.size, align)?;
707707

708708
let old = this.atomic_min_max_scalar(place, rhs, min, atomic)?;
709-
this.write_immediate(*old, dest)?; // old value is returned
709+
this.write_immediate(*old, &dest)?; // old value is returned
710710
Ok(())
711711
}
712712

tests/run-pass/atomic.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ fn atomic_u64() {
7474
assert_eq!(ATOMIC.compare_exchange(0, 0x100, AcqRel, Acquire), Err(1));
7575
compare_exchange_weak_loop!(ATOMIC, 1, 0x100, AcqRel, Acquire);
7676
assert_eq!(ATOMIC.load(Relaxed), 0x100);
77+
78+
assert_eq!(ATOMIC.fetch_max(0x10, SeqCst), 0x100);
79+
assert_eq!(ATOMIC.fetch_max(0x100, SeqCst), 0x100);
80+
assert_eq!(ATOMIC.fetch_max(0x1000, SeqCst), 0x100);
81+
assert_eq!(ATOMIC.fetch_max(0x1000, SeqCst), 0x1000);
82+
assert_eq!(ATOMIC.fetch_max(0x2000, SeqCst), 0x1000);
83+
assert_eq!(ATOMIC.fetch_max(0x2000, SeqCst), 0x2000);
84+
85+
assert_eq!(ATOMIC.fetch_min(0x2000, SeqCst), 0x2000);
86+
assert_eq!(ATOMIC.fetch_min(0x2000, SeqCst), 0x2000);
87+
assert_eq!(ATOMIC.fetch_max(0x1000, SeqCst), 0x2000);
88+
assert_eq!(ATOMIC.fetch_max(0x1000, SeqCst), 0x1000);
89+
assert_eq!(ATOMIC.fetch_max(0x100, SeqCst), 0x1000);
90+
assert_eq!(ATOMIC.fetch_max(0x10, SeqCst), 0x100);
7791
}
7892

7993
fn atomic_fences() {

0 commit comments

Comments
 (0)