Skip to content

Commit 72e11d3

Browse files
committed
Auto merge of #2105 - thomcc:flip-failure-rate, r=RalfJung
Fix backwards `cmpxchg_weak_failure_rate` check Uh, I guess I got this backwards a long time ago 😓.
2 parents d60aa47 + fdfbd7a commit 72e11d3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/data_race.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
623623
// `binary_op` will bail if either of them is not a scalar.
624624
let eq = this.binary_op(mir::BinOp::Eq, &old, expect_old)?;
625625
// If the operation would succeed, but is "weak", fail some portion
626-
// of the time, based on `rate`.
627-
let rate = this.machine.cmpxchg_weak_failure_rate;
626+
// of the time, based on `success_rate`.
627+
let success_rate = 1.0 - this.machine.cmpxchg_weak_failure_rate;
628628
let cmpxchg_success = eq.to_scalar()?.to_bool()?
629-
&& (!can_fail_spuriously || this.machine.rng.get_mut().gen::<f64>() < rate);
629+
&& if can_fail_spuriously {
630+
this.machine.rng.get_mut().gen_bool(success_rate)
631+
} else {
632+
true
633+
};
630634
let res = Immediate::ScalarPair(
631635
old.to_scalar_or_uninit(),
632636
Scalar::from_bool(cmpxchg_success).into(),

0 commit comments

Comments
 (0)