[fpc-devel] Debugging Loop Unroll Optimization
J. Gareth Moreton
gareth at moreton-family.com
Thu May 17 23:09:24 CEST 2018
What I've gathered is that with the following routine:
function DoSomething: Integer;
begin
for Result:=alow to ahigh do
if Something(Result) then exit;
end;
The issue occurs if "Something(Result)" always returns False and the
for-loop exits normally. While some languages and compilers will
consistently set Result to "ahigh + 1" after the last cycle, this is not
the case with Free Pascal, hence Result is undefined and the last value of
R/EAX (which may or may not be False from the last call to "Something")
becomes the function return.
I'm not certain, but at the very least, if the variable used in the
for-loop is still live afterwards (that is, it's read from before being
written to again), a compiler warning should be thrown. If this already
happens, then it might need to be modified to handle Result as a special
case.
Gareth aka. Kit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180517/e1c663fb/attachment.html>
More information about the fpc-devel
mailing list