Bug 26663 - Wrong generated code with gcc-3.4.x -O2 (ok with -O1 or gcc-3.3.6)
Summary: Wrong generated code with gcc-3.4.x -O2 (ok with -O1 or gcc-3.3.6)
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.6
: P3 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-13 13:11 UTC by Steffen Zimmermann
Modified: 2006-03-13 14:15 UTC (History)
60 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
C++ source code to reproduce the bug (782 bytes, text/plain)
2006-03-13 13:12 UTC, Steffen Zimmermann
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steffen Zimmermann 2006-03-13 13:11:43 UTC
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
Comment 1 Steffen Zimmermann 2006-03-13 13:12:54 UTC
Created attachment 11038 [details]
C++ source code to reproduce the bug
Comment 2 Richard Biener 2006-03-13 13:37:57 UTC
This is invalid as it violates C/C++ aliasing rules.

*** This bug has been marked as a duplicate of 21920 ***
Comment 3 Andrew Pinski 2006-03-13 14:15:27 UTC
   * (u_32 *) pFloat = 0x7FFFFFFF; // NaN
That is violating C/C++ aliasing rules.
Comment 4 Jonathan Beit-Aharon 2006-03-13 14:40:45 UTC
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.
>
>
>  
>