Sorry, not sure if this is a real bug or whether the code is broken and relying
on undefined behaviour when an integer overflows. The test case is very simple:

#include <stdio.h>

int main( int argc, char *argv[] )
{
   int bit;
   for( bit = 1; bit; bit *= 2 ) {
      printf( "%d\n", bit );
   }
   return 0;
}

Compiling this with just the argument '-O2' on GCC 4.3.1 will cause this loop
to run forever, printing out an endless stream of zeros. Lower levels of
optimization don't hit this problem. Changing the type of 'bit' to unsigned
also prevents an infinite loop. Earlier GCCs (GCC 4.2.3 and earlier) did not
have this behaviour.


-- 
           Summary: Optimization O2 causes infinite loop
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ben at zeus dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36862

Reply via email to