From fdfbd7a658b58f1f579ad677a73a516668b35ed6 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Sat, 7 May 2022 10:37:20 -0700 Subject: [PATCH] Fix backwards `cmpxchg_weak_failure_rate` check --- src/data_race.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/data_race.rs b/src/data_race.rs index 5a6dd1d81d..c52b840184 100644 --- a/src/data_race.rs +++ b/src/data_race.rs @@ -623,10 +623,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { // `binary_op` will bail if either of them is not a scalar. let eq = this.binary_op(mir::BinOp::Eq, &old, expect_old)?; // If the operation would succeed, but is "weak", fail some portion - // of the time, based on `rate`. - let rate = this.machine.cmpxchg_weak_failure_rate; + // of the time, based on `success_rate`. + let success_rate = 1.0 - this.machine.cmpxchg_weak_failure_rate; let cmpxchg_success = eq.to_scalar()?.to_bool()? - && (!can_fail_spuriously || this.machine.rng.get_mut().gen::() < rate); + && if can_fail_spuriously { + this.machine.rng.get_mut().gen_bool(success_rate) + } else { + true + }; let res = Immediate::ScalarPair( old.to_scalar_or_uninit(), Scalar::from_bool(cmpxchg_success).into(),