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;
   if v=2 then while true do ;

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

fpc-devel maillist  -  fpc-devel@lists.freepascal.org

Reply via email to