The following code is expected to print "1." However, with -O1 or -O2 option, it prints "2." (-O0 option yields the correct output "1.")
-------------------------------------------- Source code: #include <stdio.h> int main (void) { int test=1; volatile int a = 1; test += (0 == a); test += ((test + test) <= -69); printf("%d\n",test); return 0; } -------------------------------------------- Compiler command line: "gcc -O1", "gcc -O2" -------------------------------------------- Expected results: 1 -------------------------------------------- Observed results: 2 ------------------------------------------------------------- gcc -v output: Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug Thread model: posix gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) ------------------------------------------------------------- -- Summary: Failed constant folding and propagation in arithmetic expression. Product: gcc Version: 3.4.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hironobu dot awazu at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38972