[fpc-devel] Looking for some general clarification on how exactly revision #43175 "fixes" bugtracker issue #0036139

Martin Frb lazarus at mfriebe.de
Sun Oct 13 03:51:29 CEST 2019

On 13/10/2019 01:54, Ben Grasset wrote:
> I guess this doesn't matter too much in the grand scheme of things, 
> but I'm somewhat confused by it, so I thought I'd ask.
> Specifically, the reporter of that issue, calling themselves 
> "Alexander", used the following program as an "example" of what they 
> called "too aggressive optimization":
> program test:
> var v:longword;
> begin
>    if v=2 then while true do ;
> end.
> To me, that just shows a while loop that will very obviously be exited 
> immediately in all cases, because "v" is very obviously *not* equal to 
> 2. Yet they used a (tiny) snippet of assembler from this and deemed it 
> "incorrect", without making any attempt to clarify what they meant.

The fix does not appear to be about the "if v=2" part.
But about the "while constant_expression_with_no_sideeffects do 
{nothing};" empty loop.

Also in the bug report the "cmpl $2" was not removed.

So the compiler detect the dead code. (caused by v <> 2 / which probably 
is not the case in the users real code).

The compile does remove an empty loop.
An empty loop, with a condition that also does nothing, that is a loop 
that does nothing. Except it does: It loops forever, and stops the code 
after it from being executed.

I guess it is just an overlap, that the "if v=2" (which may be needed to 
trigger the issue in a minimal example) could/should/might trigger 
another optimization (which however is not actually triggered).

That at least is what I would figure from the data avail

More information about the fpc-devel mailing list