On Fri, Sep 24, 2021 at 2:35 AM Aldy Hernandez <al...@redhat.com> wrote: > > > > On 9/24/21 11:29 AM, Andrew Pinski wrote: > > On Fri, Sep 24, 2021 at 1:05 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. > > > > Huh about c>=0 being always true? the expression, "c++" is really c= > > (short)(((int)c)+1). So it will definitely wrap over when c is > > SHRT_MAX. > > I see. > > Is this only for C++ or does it affect C as well?
This is standard C code; promotion rules; that is if a type is less than int, it will be promoted to int if all of the values fit into int; otherwise it will be promoted to unsigned int. Thanks, Andrew Pinski > > Aldy >