On 9/24/21 10:08 AM, Richard Biener wrote:
On Fri, Sep 24, 2021 at 10:04 AM Aldy Hernandez via Gcc <gcc@gcc.gnu.org> wrote:

Hi folks.

My upcoming threading improvements turn the test below into an infinite
runtime loop:

int a, b;
short c;

int
main ()
{
    int j, d = 1;
    for (; c >= 0; c++)
      {
BODY:
        a = d;
        d = 0;
        if (b)
         {
           xprintf (0);
           if (j)
             xprintf (0);
         }
      }
    xprintf (d);
    exit (0);
}

On the false edge out of if(b) we thread directly to BODY, eliding the
loop conditional, because we know that c>=0 because it could never overflow.

Since B is globally initialized to 0, this has the effect of turning the
test into an infinite loop.

Is this correct, or did I miss something?

Yes, 'c' will wrap to negative SHORT_MIN and terminate the loop via
the c>=0 test.

Huh, so SHORT_MAX + 1 = SHORT_MIN? I thought that was an overflow, and therefore undefined.

Aldy


Mind c++ is really (short)(((int)c)++) and signed integer truncation
is implementation
defined.

Richard.

Aldy



Reply via email to