public inbox for
help / color / mirror / Atom feed
* optimization/10877: GCC 3.3 miscompiles code with -O3 -fPIC on x86
@ 2003-05-20  1:06 lloyd
  0 siblings, 0 replies; only message in thread
From: lloyd @ 2003-05-20  1:06 UTC (permalink / raw)
  To: gcc-gnats

>Number:         10877
>Category:       optimization
>Synopsis:       GCC 3.3 miscompiles code with -O3 -fPIC on x86
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue May 20 01:06:00 UTC 2003
>Originator:     Jack Lloyd
>Release:        3.3
RedHat 7.3, AMD Athlon, glibc 2.2.5, kernel 2.4.19, binutils
GCC 3.3 miscompiles what is (AFAIK) valid C++ code if it is compiled with -O3 -fPIC
on x86. The code in question is attached. I have the following information:

$ g++-3.3 -v
Reading specs from /usr/local/gcc-3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/specs
Configured with: ../gcc-3.3/configure --prefix=/usr/local/gcc-3.3 --enable-threads
Thread model: posix
gcc version 3.3

The code is accepted by GCC 2.95.3, 3.0.4, 3.1, and 3.2. With all of these
versions, the code works correctly with -O3 -fPIC (and various other
combinations of -O and -fPIC). The code works with 3.3 if -O2 or lower is
specified, or if -O3 without -fPIC/-fpic is used.

One interesting thing is that if the variable local_foo is declared as:

   static foo* local_foo;

then it works. It also doesn't work if local_foo is declared as a non-static
global (rather than in an anonymous namespace), presumably because anonymous
namespace members aren't (IIRC) linked as static in GCC.

I only have 3.2, so it's possible this was introduced in later 3.2 versions
rather than the 3.3 branch. BTW, I've checked, and the resulting binary does
use the gcc 3.3 versions of libgcc and libstdc++, so it's not that.
Here is exactly what I'm seeing. This is with a printf that runs right before we exit from main; the version attached has the include of <stdio.h> and the printf call commented out.

     $ g++-3.3 -O3 -fPIC gccbug.cpp 
     $ ./a.out 
     Segmentation fault
     $ g++-3.3 -O2 -fPIC gccbug.cpp 
     $ ./a.out 
     I guess we didn't crash
     $ g++-3.3 -O3 gccbug.cpp 
     $ ./a.out 
     I guess we didn't crash
     $ g++-2.95.3 -O3 -fPIC gccbug.cpp 
     $ ./a.out 
     I guess we didn't crash
     $ g++-3.0.4 -O3 -fPIC gccbug.cpp 
     $ ./a.out 
     I guess we didn't crash
     $ g++-3.1 -O3 -fPIC gccbug.cpp 
     $ ./a.out 
     I guess we didn't crash
     $ g++-3.2 -O3 -fPIC gccbug.cpp 
     $ ./a.out 
     I guess we didn't crash

Content-Type: application/octet-stream; name="gccbug.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="gccbug.cpp"


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-05-20  1:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-20  1:06 optimization/10877: GCC 3.3 miscompiles code with -O3 -fPIC on x86 lloyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).