[fpc-devel] Debugging Loop Unroll Optimization

Jonas Maebe jonas at freepascal.org
Mon May 21 17:59:51 CEST 2018


On 18/05/18 13:28, Marco van de Voort wrote:
> In our previous episode, Mattias Gaertner said:
>>> ISO7185: "After a for-statement is executed, other than being left by a goto-statement, the
>>> control-variable shall be undefined"
>>>
>>> http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Declarations_and_Statements_(Delphi)#For_Statements:
>>> "After the for statement terminates (provided this was not forced by a Break or an Exit procedure),
>>> the value of counter is undefined."
>>>
>>> So this shall not be unrolled, but is still error prone, if Result is not set after the regular end of the for loop.
>> To avoid misunderstandings:
>> The above clearly says, that using break/goto/exit is safe:
> 
> Well, well, clearly. One could interpret it that it says that the for
> statement terminates naturally if not forced by break or exit.  It doesn't
> say what happens with break or exit.
>   
> The fact that this exception is not documented with an example makes it very
> ambiguous IMHO.

To make it unambiguous: the value of the counter variable of a for-loop 
is well-defined after interrupting the for-loop using exit or break, 
also in FPC.


Jonas




More information about the fpc-devel mailing list