[Bug c++/11423] New: IA-32 optimization bug w/ 64 bit parameters

Mirko dot Luedde at SAP dot com gcc-bugzilla@gcc.gnu.org
Thu Jul 3 14:00:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11423

           Summary: IA-32 optimization bug w/ 64 bit parameters
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Mirko dot Luedde at SAP dot com
                CC: gcc-bugs at gcc dot gnu dot org

Access to 64 bit parameters on the stack is broken from optimization -O2 
onwards. This occurs in one form or the other in all 3.2 releases, and even in 
3.3. The command output (see below) should read "x: 4294967296\ny1: 1\ny2: 1
\ny3: 1". I paste the command output and the source file here, since I do not 
see how I could upload the ".ii" file (as is suggested in the"BUGS" file). 

Regards, Mirko. 
-----------------------------------------------------------------------------
$ g++-3-2-3 -v -save-temps -Wall -O2 gcc-3-2-3-bug.cpp; ./a.out 0x100000000
Reading specs from /priv/d022609/lib/gcc-3-2-3/lib/gcc-lib/i686-pc-linux-
gnu/3.2.3/specs
Configured with: ../gcc-3.2.3/configure --prefix=/priv/d022609/lib/gcc-3-2-3
Thread model: posix
gcc version 3.2.3
 /priv/d022609/lib/gcc-3-2-3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/cpp0 -lang-
c++ -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -v -D__GNUC__=3 -
D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GXX_ABI_VERSION=102 -D__ELF__ -
Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -
D__unix -D__linux -Asystem=posix -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -
D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -
D__tune_i686__ -D__tune_pentiumpro__ gcc-3-2-3-bug.cpp -Wall gcc-3-2-3-bug.ii
GNU CPP version 3.2.3 (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/priv/d022609/lib/gcc-3-2-3/i686-pc-linux-
gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /priv/d022609/lib/gcc-3-2-3/include/c++/3.2.3
 /priv/d022609/lib/gcc-3-2-3/include/c++/3.2.3/i686-pc-linux-gnu
 /priv/d022609/lib/gcc-3-2-3/include/c++/3.2.3/backward
 /usr/local/include
 /priv/d022609/lib/gcc-3-2-3/include
 /priv/d022609/lib/gcc-3-2-3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/include
 /usr/include
End of search list.
 /priv/d022609/lib/gcc-3-2-3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/cc1plus -
fpreprocessed gcc-3-2-3-bug.ii -quiet -dumpbase gcc-3-2-3-bug.cpp -O2 -Wall -
version -o gcc-3-2-3-bug.s
GNU CPP version 3.2.3 (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2.3 (i686-pc-linux-gnu)
	compiled by GNU C version 3.2.3.
 as -V -Qy -o gcc-3-2-3-bug.o gcc-3-2-3-bug.s
GNU assembler version 2.12.90.0.15 (i486-suse-linux) using BFD version 
2.12.90.0.15 20020717 (SuSE)
 /priv/d022609/lib/gcc-3-2-3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/collect2 --eh-
frame-hdr -m elf_i386 -dynamic-linker /lib/ld-
linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /priv/d022609/lib/gcc-3-2-3/lib/gcc-
lib/i686-pc-linux-gnu/3.2.3/crtbegin.o -L/priv/d022609/lib/gcc-3-2-3/lib/gcc-
lib/i686-pc-linux-gnu/3.2.3 -L/priv/d022609/lib/gcc-3-2-3/lib/gcc-lib/i686-pc-
linux-gnu/3.2.3/../../.. gcc-3-2-3-bug.o -lstdc++ -lm -lgcc_s -lgcc -lc -
lgcc_s -lgcc /priv/d022609/lib/gcc-3-2-3/lib/gcc-lib/i686-pc-linux-
gnu/3.2.3/crtend.o /usr/lib/crtn.o
x: 4294967296
y1: 718027984
y2: 718027984
y3: 718027984
-------------------------------------------------------------------------------
/* 

   topic {

      A C++ program revealing an optimization bug in gcc 3.2 and gcc
      3.2.3 on Linux / IA-32.  The bug does not occur with gcc 2.95.3.

      We have 

      $ uname -a
      Linux ls3026 2.4.19-cst-4GB-SMP #2 SMP Wed Nov 20 14:58:16 CET 2002 i686 
unknown

      $ g++-2-95-3 -v
      Reading specs from /sapmnt/appl_sw/ugcc.v3/lib/gcc-lib/i486-suse-
linux/2.95.3/specs
      gcc version 2.95.3 20010315 (SuSE) (SAP UTF16)

      $ g++-3-2 -v
      Reading specs from /usr/lib/gcc-lib/i486-suse-linux/3.2/specs
      Configured with: ../configure --enable-threads=posix --prefix=/usr --with-
local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --
libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --enable-libgcj --
with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --
enable-shared --enable-__cxa_atexit i486-suse-linux
      Thread model: posix
      gcc version 3.2

      $ g++-3-2-3 -v
      Reading specs from /priv/d022609/lib/gcc-3-2-3/lib/gcc-lib/i686-pc-linux-
gnu/3.2.3/specs
      Configured with: ../gcc-3.2.3/configure --prefix=/priv/d022609/lib/gcc-3-
2-3
      Thread model: posix
      gcc version 3.2.3

      $ g++-2-95-3 -Wall -O4 gcc-3-2-3-bug.cpp; ./a.out 0x100000000
      x: 4294967296
      y1: 1
      y2: 1
      y3: 1

      $ g++-3-2 -Wall -O gcc-3-2-3-bug.cpp; ./a.out 0x100000000
      x: 4294967296
      y1: 1
      y2: 1
      y3: 1

      $ g++-3-2 -Wall -O2 gcc-3-2-3-bug.cpp; ./a.out 0x100000000
      x: 4294967296
      y1: 718027984
      y2: 718027984
      y3: 718027984

      $ g++-3-2 -Wall -O4 gcc-3-2-3-bug.cpp; ./a.out 0x100000000
      x: 4294967296
      y1: 1
      y2: 1
      y3: 718027984

      $ g++-3-2-3 -Wall -O gcc-3-2-3-bug.cpp; ./a.out 0x100000000
      x: 4294967296
      y1: 1
      y2: 1
      y3: 1

      $ g++-3-2-3 -Wall -O2 gcc-3-2-3-bug.cpp; ./a.out 0x100000000
      x: 4294967296
      y1: 718027984
      y2: 718027984
      y3: 718027984

      $ g++-3-2-3 -Wall -O4 gcc-3-2-3-bug.cpp; ./a.out 0x100000000
      x: 4294967296
      y1: 134514885
      y2: 134514885
      y3: 65535

      }

   date {2003-07-02T23:04:04+0200}

   author {Mirko.Luedde@SAP.com}
*/

#include <iostream>
#include <stdio.h>
using namespace std;

int hi(long long x)
{
   int y = *(1+(int*)&x); // does not work, see above. 
//   int y = x >> 32;     // works with all tested versions.
   return y;
}

int main(int argc, char* argv[])
{
   long long x; 
   sscanf(argv[1], "%Lx", &(x));
   int y1 = hi(x);       // correct with "g++-3-2 -O4 gcc-3-2-3-bug.cpp"
   long long y2 = y1;    // correct with "g++-3-2 -O4 gcc-3-2-3-bug.cpp"
   long long y3 = hi(x); // wrong with   "g++-3-2 -O4 gcc-3-2-3-bug.cpp"
   cout
     << "x: "  << x  << endl
     << "y1: " << y1 << endl
     << "y2: " << y2 << endl
     << "y3: " << y3 << endl;
}
--------------------------------------------------------------------------------



More information about the Gcc-bugs mailing list