Skip to content

Commit

Permalink
Auto merge of #2105 - thomcc:flip-failure-rate, r=RalfJung
Browse files Browse the repository at this point in the history
Fix backwards `cmpxchg_weak_failure_rate` check

Uh, I guess I got this backwards a long time ago 😓.
  • Loading branch information
bors committed May 23, 2022
2 parents d60aa47 + fdfbd7a commit 72e11d3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/data_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f64>() < 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(),
Expand Down

0 comments on commit 72e11d3

Please sign in to comment.