You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a sequential context, the update is always sucessful so we assume the second value to be true.
Is this true? Consider the program cas.rs:
use std::sync::atomic::{AtomicU8,Ordering};fnmain(){let x = AtomicU8::new(0);let r = x.compare_exchange(1,2,Ordering::Relaxed,Ordering::Relaxed);println!("{}", r.is_err());}#[cfg(kani)]#[kani::proof]fncheck_is_err(){let x = AtomicU8::new(0);let r = x.compare_exchange(1,2,Ordering::Relaxed,Ordering::Relaxed);assert!(r.is_err());}
$ rustc cas.rs && ./cas
true
$ kani cas.rs --harness check_is_err
...
SUMMARY:
** 1 of 101 failed (1 unreachable)
Failed Checks: assertion failed: r.is_err()
File: "cas.rs", line 17, in check_is_err
VERIFICATION:- FAILED
It seems like the claim is true assuming the sequential code is correct. But assuming that the code is correct kind of defeats the purpose of using Kani.
This issue also affects the compare_exchange_weak method.
Activity
tautschnig commentedon Feb 10, 2026
Thank you for the detailed report. We'll take a look at this (and also the others that you filed) shortly.
Fix atomic compare_exchange to return correct failure status
Fix atomic compare_exchange to return correct failure status (#4542)