B5112: procedure might not terminate
Catalog status: active. Default severity: error. Stable name: procedure-termination. Family: Contracts and termination.
A procedure with Always_Terminates, a finalizer (the Finalize procedure of a Finalizable type, which runs wherever an object dies), and any procedure that a function or one of these calls, must return. Verada proves that the way it proves a function returns: each loop other than a for loop has a Loop_Variant, a recursive procedure has a Subprogram_Variant, and every procedure it calls must return too. When the procedure must terminate only because of a caller, the note names it: "P.Spin must terminate because P.G calls it and must terminate".
Example (Vada)
procedure Settle (X : in out Natural) with Always_Terminates is
begin
while X > 0 loop -- no Loop_Variant
X := X - 1;
end loop;
end Settle;Example (Varc)
fn settle(x: inout Natural) @Always_Terminates {
while x > 0 { // no variant
x = x - 1;
}
}
What to do
Add pragma Loop_Variant (Decreases => X) inside the loop, after its invariant, for a value that shrinks every iteration, and give a recursive procedure a Subprogram_Variant. The procedures it calls are proved to return in the same way. If a procedure is meant to run forever, do not call it from a function or a procedure that must terminate.
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.