fix: detection of whether negative loop iteration will overflow
Rumur emits code to detect whether the final iteration of a for loop would cause
numeric overflow, resulting in an infinite loop or undefined behaviour in C, and
safely handles this situation. However, in the case of a reverse iteration
(negative step) we were incorrectly checking against the “lower bound” of the
loop which actually ends up being the upper bound in a reverse iteration. E.g.
for i := 0 to -127 by 10 do
…
end;
In the above loop, the bound we need to check against for overflow is -127 which
is conceptually the lower bound, but during code generation is actually in the
`ub` variable.
Note that this is only part of the changes required for #211, because this is
only the condition of whether we *could* overflow. The test for whether we are
about to *actually* overflow is also broken.
Github: related to #211 “for loop underflow check incorrect?”
parent
9c898780
Please register or sign in to comment