The attached C++ code converts a floating point number from our internal representation to IEEE format. When run, the program should print a value of 144. This works with gcc-3.3.6 at any optimization level (-O1 -- -O3). With gcc-3.4.x and optimization level -O2 or -O3, it prints 42 instead. I.e., it seems the "iFloat" variable in CMdilFloat::AsFloat() is never modified. Here's the output of the code with various vanilla gcc's, along with their configuration: $ uname -a Linux xxx.xxx.com 2.6.9-22.0.2.ELsmp #1 SMP Thu Jan 5 17:13:01 EST 2006 i686 i686 i386 GNU/Linux $ gcc-3.3.6/bin/g++ -v Reading specs from /home/steffenz/gcc/install/gcc-3.3.6/lib/gcc-lib/i686-pc-linux-gnu/3.3.6/specs Configured with: ../gcc-3.3.6/configure --prefix=/home/steffenz/gcc/install/gcc-3.3.6 --disable-nls --enable-languages=c,c++ Thread model: posix gcc version 3.3.6 $ gcc-3.3.6/bin/g++ -O1 -o test test.cpp && ./test 144 $ gcc-3.3.6/bin/g++ -O2 -o test test.cpp && ./test 144 $ gcc-3.3.6/bin/g++ -O3 -o test test.cpp && ./test 144 $ gcc-3.4.0/bin/g++ -v Reading specs from /home/steffenz/gcc/install/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/specs Configured with: ../gcc-3.4.0/configure --prefix=/home/steffenz/gcc/install/gcc-3.4.0 --disable-nls --enable-languages=c,c++ Thread model: posix gcc version 3.4.0 $ gcc-3.4.0/bin/g++ -O1 -o test test.cpp && ./test 144 $ gcc-3.4.0/bin/g++ -O2 -o test test.cpp && ./test 42 $ gcc-3.4.0/bin/g++ -O3 -o test test.cpp && ./test 42 $ gcc-3.4.6/bin/g++ -v Reading specs from /home/steffenz/gcc/install/gcc-3.4.6/lib/gcc/i686-pc-linux-gnu/3.4.6/specs Configured with: ../gcc-3.4.6/configure --prefix=/home/steffenz/gcc/install/gcc-3.4.6 --disable-nls --enable-languages=c,c++ Thread model: posix gcc version 3.4.6 $ gcc-3.4.6/bin/g++ -O1 -o test test.cpp && ./test 144 $ gcc-3.4.6/bin/g++ -O2 -o test test.cpp && ./test 42 $ gcc-3.4.6/bin/g++ -O3 -o test test.cpp && ./test 42
Created attachment 11038 [details] C++ source code to reproduce the bug
This is invalid as it violates C/C++ aliasing rules. *** This bug has been marked as a duplicate of 21920 ***
* (u_32 *) pFloat = 0x7FFFFFFF; // NaN That is violating C/C++ aliasing rules.
Subject: Re: Wrong generated code with gcc-3.4.x -O2 (ok with -O1 or gcc-3.3.6) Please take me off the CC list for this distribution. I don't need the "encouragement" of knowing that many people experience similar frustrations with gcc's poor (or shall I say, uninformative) warning messages in the case of aliasing rule violations. Thanks, Jonathan pinskia at gcc dot gnu dot org wrote: >------- Comment #3 from pinskia at gcc dot gnu dot org 2006-03-13 14:15 ------- > * (u_32 *) pFloat = 0x7FFFFFFF; // NaN >That is violating C/C++ aliasing rules. > > > >