B5107: loop variant might not make progress
Catalog status: active. Default severity: error. Stable name: loop-variant. Family: Contracts and termination.
pragma Loop_Variant names values that must change in the stated direction (Decreases or Increases) on every iteration; with several, the first one that changes must move in its direction, as in a dictionary order. Since the values are bounded by their subtypes, the loop then terminates. The prover found an iteration where the variant does not move.
Example (Vada)
while N > 0 loop
pragma Loop_Variant (Decreases => N);
if N > 5 then
N := N - 1; -- when N <= 5 nothing changes, and the loop never ends
end if;
end loop;Example (Varc)
while n > 0 {
decreases n;
if n > 5 {
n -= 1; // when n <= 5 nothing changes, and the loop never ends
}
}
What to do
Fix the loop so that every iteration makes progress, or choose a variant that does change on every path. A loop invariant may be needed for the prover to see why it does.
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See contracts and termination, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.