On this page
B4101: overflow check might fail
Catalog status: active. Default severity: error. Stable name: overflow-check. Family: Executable checks.
An arithmetic operation might produce a value outside its type's base range, which raises Constraint_Error at run time. The prover could not show that it stays in range for every input allowed by the subprogram's precondition and the subtypes of its parameters. When a counterexample replays on the program and reaches the check, the title says "fails"; a less conclusive result is read with its notes (a replay that runs through points to a loop invariant or a called operation's contract that is too weak, rather than to an input that overflows).
Example (Vada)
function Increment (Value : Natural) return Natural is
begin
return Value + 1; -- overflows when Value is Natural'Last
end Increment;Example (Varc)
pub fn increment(value: Natural) -> Natural
ensures result == value + 1
{
return value + 1; // overflows when value is Natural::Last
}
Example (Vibe)
def increment(value: Natural) -> Natural:
ensures(result == value + 1)
return value + 1 # overflows when value is Natural.lastWhat to do
If the operation is meant to reject the largest input, narrow its inputs: the precondition Value < Natural'Last in Vada, requires value < Natural::Last in Varc, requires(value < Natural.last) in Vibe, or a parameter subtype. Every caller must then establish it. If the operation must accept that input, compute in a way that cannot overflow (A + (B - A) / 2 when A <= B), or use a wider type for the intermediate result: widening the destination alone does not widen the arithmetic that computes its value.
Overflow is not a subtype range failure: 0 - 1 fits in Integer and fails only where a Natural result is required, which is B4102. B5115 is a check the budget could not decide, not one shown to overflow. The first proof works through this example in each syntax, and integer ranges gives the rules.
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See executable checks, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.