public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Mailing List <gcc@gcc.gnu.org>
Subject: Re: Can gcc.dg/torture/pr67828.c be an infinite loop?
Date: Fri, 24 Sep 2021 10:59:34 +0200	[thread overview]
Message-ID: <3d8e40f3-20e8-f265-85d8-d667aa65052a@redhat.com> (raw)
In-Reply-To: <CAFiYyc3oKQENp7O7arPniTpSgSn1UPe7Y2LY04V-S5uhm_Ck=A@mail.gmail.com>



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	other threads:[~2021-09-24  8:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-24  8:03 Aldy Hernandez
2021-09-24  8:08 ` Richard Biener
2021-09-24  8:59   ` Aldy Hernandez [this message]
2021-09-24 11:30     ` David Brown
2021-09-24  9:29 ` Andrew Pinski
2021-09-24  9:35   ` Aldy Hernandez
2021-09-24  9:38     ` Andrew Pinski
2021-09-24 10:49       ` Aldy Hernandez
2021-09-24 11:33       ` David Brown
2021-09-24 11:08   ` Richard Earnshaw
2021-09-24 11:37 ` David Brown
2021-09-24 11:41   ` Aldy Hernandez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3d8e40f3-20e8-f265-85d8-d667aa65052a@redhat.com \
    --to=aldyh@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).