[fpc-devel] Const optimization is a serious bug
Martin
fpc at mfriebe.de
Thu Jul 7 17:35:12 CEST 2011
On 07/07/2011 16:27, Alexander Klenin wrote:
>
> 1) That the code you posted would work quite correctly if "const
> string" is fixed,
> including all the optimizations you are suggesting in the rest of
> your message.
No.
As I said: IF the result of constant expressions like "s[a] = '<'" are
cached (in future) depending on optimization level, then it breaks.
The 2nd evaluation, of this expression without optimization returns a
different result from the 1st evaluation. (It may be that the example
would need updating, but there is code where this can happen, including
if ref-counting was done)
So depending on the 2nd evaluation being done, or cached (future
optimization) the program flow differs.
Code which behaves unpredictable is broken.
In this case the none predictability comes from the fact that the code
relies on a randomly observed and undocumented behaviour of todays fpc
implementation. (the fact that today no such optimization is done)
More information about the fpc-devel
mailing list