This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/43242] New: Infinite loop created when using -O2 optimization
- From: "gcc dot eugaia at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Mar 2010 03:11:35 -0000
- Subject: [Bug c/43242] New: Infinite loop created when using -O2 optimization
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following C code caused an infinite loop to be created when using -O2
optimization:
------------------
#include <stdio.h>
int
main (void)
{
int x=0, y=0;
long z=0;
for (; y<10000000; y++) {
if (y%7 == 0)
continue;
x = 0;
while (x<10000000000) { // KEY LINE - see below
x++;
z+=1;
}
}
printf ("%li\n", z);
return 0;
}
---------------
If the line indicated by 'key line' above is changed by removing one of the
zeroes, i.e. having 9 zeroes instead of 10, then the infinite loop is not
created (tested by looking at the generated assembly).
If the -02 optimization is not used, then no infinite loop is created.
compiled using:
gcc -O2 -o inf_loop inf_loop.c
gcc -v:
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu9'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror
--with-arch-32=i486 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)
Marcus.
--
Summary: Infinite loop created when using -O2 optimization
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gcc dot eugaia at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43242