This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Re-run of loop pass


Joern Rennecke writes:
 > I have the suspicion that this will miscompile this testcase:
 > 
 > int
 > f (unsigned start)
 > {
 >   int i, j;
 > 
 >   for (j = 0, i = start; i < start + 5; i++)
 >     j++;
 >   return j;
 > }
 > 
 > int
 > main ()
 > {
 >   int i;
 > 
 >   i = f (0U-1);
 >   if (i)
 >     abort ();
 >   exit (0);
 > }

The generated code executes correctly on the C4x.

On a 2's complement machine, start is UINT_MAX, start + 5 is 4
due to unsigned arithmetic, i is assigned -1, and j is assigned 0.
The test fails immediately since an unsigned compare is performed
and (unsigned int) -1 is not less than 4.  f() thus returns 0.

Michael.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]