Optimizer bug

Karl Dahlke eklhad@comcast.net
Tue Oct 21 11:42:00 GMT 2008


Here is a 16 line program that works fine without the optimizer,
but prints the word "bug" with gcc -O
No other flags, no headers included.
Linux fedora 9.
gcc -v is:

Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-cpu=generic --build=i386-redhat-linux
Thread model: posix
gcc version 4.3.0 20080428 (Red Hat 4.3.0-8) (GCC) 

The program is:

struct rating {
int z: 20;
unsigned char probe: 1;
unsigned char val: 3;
};
static struct rating foo;
int main(int argc, char **argv)
{
foo.z = 83778;
foo.probe = 0;
foo.val = 4;
if(foo.val > 0 && foo.val < 4)
puts("bug");
else
puts("ok");
}

Thanks.

Karl Dahlke


More information about the Gcc-bugs mailing list