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
{{ message }}
Repository navigation
#[kani::loop_decreases] combined with #[kani::loop_modifies] causes verification failure #4584
When #[kani::loop_decreases] and #[kani::loop_modifies] are both applied to the same loop, CBMC's goto-instrument produces incorrect instrumentation, causing spurious verification failures. Each attribute works correctly in isolation.
Steps to reproduce
#![feature(proc_macro_hygiene)]#![feature(stmt_expr_attributes)]#[kani::proof]fncheck_decreases_with_modifies(){letmut x:u32 = 10;#[kani::loop_invariant(x <= 10)]#[kani::loop_modifies(&x)]#[kani::loop_decreases(x)]while x > 0{
x -= 1;}assert!(x == 0);}
Expected behavior
Verification succeeds — the loop terminates (decreases x) and only modifies x.
Actual behavior
Verification fails with assigns clause or decreases check failures.
Root cause
The with_loop_decreases and with_loop_modifies builders in stmt.rs each clone the other's field when constructing the annotated Goto statement. However, the order in which goto-instrument processes these annotations may cause conflicts in the instrumented code.
Workaround
Use loop_decreases without loop_modifies, or vice versa. For termination proofs, loop_decreases + loop_invariant (without loop_modifies) is sufficient.
Re-tested with Kani 0.68.0 (CBMC 6.11.0): kani test.rs -Z loop-contracts on the reproducer in this issue now reports ** 0 of 50 failed / VERIFICATION:- SUCCESSFUL. With both attributes on the loop, a non-decreasing measure (loop_decreases(10 - x)) still fails with "Check variant decreases after step", and writing a variable outside loop_modifies still fails with "Check that y is assignable". So combining the two attributes now works and both are enforced. Closing; please reopen if you have a case that still fails.
Activity
Add `#[kani::loop_decreases]` for proving loop termination (model-che…
feliperodri commentedon Sep 25, 2026
Re-tested with Kani 0.68.0 (CBMC 6.11.0):
kani test.rs -Z loop-contractson the reproducer in this issue now reports** 0 of 50 failed/VERIFICATION:- SUCCESSFUL. With both attributes on the loop, a non-decreasing measure (loop_decreases(10 - x)) still fails with "Check variant decreases after step", and writing a variable outsideloop_modifiesstill fails with "Check that y is assignable". So combining the two attributes now works and both are enforced. Closing; please reopen if you have a case that still fails.