Two semantically equivalent files output different results using gcc 4.5.0 release,while gcc 4.4.1 produced correct results.
here is the command line option used to compile the files: gcc -O2 MTest-1.c -o MTest-1.exe gcc -O2 MTest-7.c -o MTest-7.exe #and the results ./MTest-1.exe # generate MTest-1.out ./MTest-7.exe # generate MTest-7.out diff MTest-1.out MTest-7.out use gcc -O2 -fno-strict-aliasing or gcc -O2 -fno-strict-pre can avoid this problem. I have read the Non-bugs section in http://gcc.gnu.org/bugs/ and I'm sure our files does not violate the aliasing rule. the gcc 4.4.1 works correctly using fstrict-aliasing: gcc-4.4 -O2 -fstrict-aliasing MTest-1.c -o MTest-1.exe Here is the gcc configure&build options $../exec/gcc -v Using built-in specs. COLLECT_GCC=../exec/bin/gcc COLLECT_LTO_WRAPPER=/sda3/test-gcc-4.5.0/exec/bin/../libexec/gcc/i686-pc-linux-gnu/4.5.0/lto-wrapper Target: i686-pc-linux-gnu Configured with: ../src/configure --prefix=/sda3/test-gcc-4.5.0/obj/../exec --enable-languages=c Thread model: posix gcc version 4.5.0 (GCC) I compiled it with gcc 4.4.1: $gcc -v Using built-in specs. Target: i486-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 --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) -- Summary: miscompile semantically equivalent C source files using -O2 Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: wuwei08 at iscas dot ac dot cn GCC build triplet: x86_32-Ubuntu-Linux GCC host triplet: x86_32-Ubuntu-Linux GCC target triplet: x86_32-Ubuntu-Linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43794