From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1369 invoked by alias); 20 May 2003 01:06:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 1349 invoked by uid 71); 20 May 2003 01:06:00 -0000 Resent-Date: 20 May 2003 01:06:00 -0000 Resent-Message-ID: <20030520010600.1348.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, lloyd@acm.jhu.edu Received: (qmail 19834 invoked by uid 48); 20 May 2003 00:59:43 -0000 Message-Id: <20030520005943.19833.qmail@sources.redhat.com> Date: Tue, 20 May 2003 01:06:00 -0000 From: lloyd@acm.jhu.edu Reply-To: lloyd@acm.jhu.edu To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: optimization/10877: GCC 3.3 miscompiles code with -O3 -fPIC on x86 X-SW-Source: 2003-05/txt/msg02133.txt.bz2 List-Id: >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 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=