User account creation filtered due to spam.

Bug 11423 - IA-32 optimization bug w/ 64 bit parameters
Summary: IA-32 optimization bug w/ 64 bit parameters
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.3
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-03 13:59 UTC by Mirko Luedde
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
compressed "ii" file revealing a bug on g++ 3.2.3 -O2 (74.04 KB, application/octet-stream)
2003-07-03 14:04 UTC, Mirko Luedde
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mirko Luedde 2003-07-03 13:59:59 UTC
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;
}
--------------------------------------------------------------------------------
Comment 1 Mirko Luedde 2003-07-03 14:04:35 UTC
Created attachment 4338 [details]
compressed "ii" file revealing a bug on g++ 3.2.3 -O2

This is the "ii" file generated from my source using the buggy gcc 3.2.3 / IA32
/ Linux.
Comment 2 Falk Hueffner 2003-07-03 14:12:33 UTC
The code is not valid C, because the pointer arithmetic leaves the valid
range. Additionally, there's an type aliasing problem.
Comment 3 Falk Hueffner 2003-07-03 14:15:04 UTC
Oops, I misread it. The pointer range is OK, there's only an aliasing violation.
But still invalid :)
Comment 4 Mirko Luedde 2003-07-03 17:15:54 UTC
Subject: RE:  IA-32 optimization bug w/ 64 bit parameters

thanks!
mirko

-----Original Message-----
From: falk at debian dot org [mailto:gcc-bugzilla@gcc.gnu.org]
Sent: Donnerstag, 3. Juli 2003 16:15
To: Luedde, Mirko
Subject: [Bug c++/11423] IA-32 optimization bug w/ 64 bit parameters


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



------- Additional Comments From falk at debian dot org  2003-07-03 14:15 -------
Oops, I misread it. The pointer range is OK, there's only an aliasing violation.
But still invalid :)




------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.
Comment 5 Andrew Pinski 2005-06-05 08:24:56 UTC
Reopening to ...
Comment 6 Andrew Pinski 2005-06-05 08:25:12 UTC
Mark as a dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***