The following C function illustrates a bug I have encountered for gcc 3.4.2 running on x86_64. The problem occurs at any optimization level and for both - m32 and -m64.
#ifndef CONST /* Following constant can be arbitrary */ #define CONST 767 #endif int testd(int x) { return ((x*CONST)/CONST) == x; } The generated assembly code (compiled -O2) is: testd: .LFB2: movl $1, %eax ret i.e., the function always returns 1. Output of gcc -v: Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.2/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/\ usr/share/info --enable-shared --enable-threads=posix --disable-checking --with\ -system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-lang\ uages=c,c++,objc,java,f77 --enable-java-awt=gtk --host=x86_64-redhat-linux Thread model: posix gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3) Here's what's in /proc/version: Linux version 2.6.11-1.35_FC3smp ([EMAIL PROTECTED]) (gcc versio\ n 3.4.3 20050227 (Red Hat 3.4.3-22)) #1 SMP Mon Jun 13 01:16:04 EDT 2005 -- Summary: Invalid code optimization for x*const/const Product: gcc Version: 3.4.2 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Randy dot Bryant at cs dot cmu dot edu CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: x86_64-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23600