This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/36862] New: Optimization O2 causes infinite loop
- From: "ben at zeus dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Jul 2008 09:52:18 -0000
- Subject: [Bug c/36862] New: Optimization O2 causes infinite loop
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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