public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: lloyd@acm.jhu.edu To: gcc-gnats@gcc.gnu.org Subject: optimization/10877: GCC 3.3 miscompiles code with -O3 -fPIC on x86 Date: Tue, 20 May 2003 01:06:00 -0000 [thread overview] Message-ID: <20030520005943.19833.qmail@sources.redhat.com> (raw) >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 >Closed-Date: >Last-Modified: >Originator: Jack Lloyd >Release: 3.3 >Organization: >Environment: RedHat 7.3, AMD Athlon, glibc 2.2.5, kernel 2.4.19, binutils 2.11.93.0.2 >Description: 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. >How-To-Repeat: 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 >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: application/octet-stream; name="gccbug.cpp" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="gccbug.cpp" c3RydWN0IGZvbyB7IH07CgpuYW1lc3BhY2UgewogICBmb28qIGxvY2FsX2ZvbzsKfQoKY29uc3Qg Zm9vJiBnZXRfeCgpCiAgIHsKICAgcmV0dXJuICgqbG9jYWxfZm9vKTsKICAgfQoKLy8jaW5jbHVk ZSA8c3RkaW8uaD4KCmludCBtYWluKCkKICAgewogICBsb2NhbF9mb28gPSBuZXcgZm9vOwogICBm b28geCA9IGdldF94KCk7CiAgIGRlbGV0ZSBsb2NhbF9mb287CgogICAvL3ByaW50ZigiSSBndWVz cyB3ZSBkaWRuJ3QgY3Jhc2hcbiIpOwogICByZXR1cm4gMDsKICAgfQo=
reply other threads:[~2003-05-20 1:06 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20030520005943.19833.qmail@sources.redhat.com \ --to=lloyd@acm.jhu.edu \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).