public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11423] New: IA-32 optimization bug w/ 64 bit parameters
@ 2003-07-03 14:00 Mirko dot Luedde at SAP dot com
  2003-07-03 14:04 ` [Bug c++/11423] " Mirko dot Luedde at SAP dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Mirko dot Luedde at SAP dot com @ 2003-07-03 14:00 UTC (permalink / raw)
  To: gcc-bugs

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;
}
--------------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/11423] IA-32 optimization bug w/ 64 bit parameters
  2003-07-03 14:00 [Bug c++/11423] New: IA-32 optimization bug w/ 64 bit parameters Mirko dot Luedde at SAP dot com
@ 2003-07-03 14:04 ` Mirko dot Luedde at SAP dot com
  2003-07-03 14:12 ` falk at debian dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Mirko dot Luedde at SAP dot com @ 2003-07-03 14:04 UTC (permalink / raw)
  To: gcc-bugs

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 Mirko dot Luedde at SAP dot com  2003-07-03 14:04 -------
Created an attachment (id=4338)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=4338&action=view)
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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/11423] IA-32 optimization bug w/ 64 bit parameters
  2003-07-03 14:00 [Bug c++/11423] New: IA-32 optimization bug w/ 64 bit parameters Mirko dot Luedde at SAP dot com
  2003-07-03 14:04 ` [Bug c++/11423] " Mirko dot Luedde at SAP dot com
@ 2003-07-03 14:12 ` falk at debian dot org
  2003-07-03 14:15 ` falk at debian dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: falk at debian dot org @ 2003-07-03 14:12 UTC (permalink / raw)
  To: gcc-bugs

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


falk at debian dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


------- Additional Comments From falk at debian dot org  2003-07-03 14:12 -------
The code is not valid C, because the pointer arithmetic leaves the valid
range. Additionally, there's an type aliasing problem.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/11423] IA-32 optimization bug w/ 64 bit parameters
  2003-07-03 14:00 [Bug c++/11423] New: IA-32 optimization bug w/ 64 bit parameters Mirko dot Luedde at SAP dot com
  2003-07-03 14:04 ` [Bug c++/11423] " Mirko dot Luedde at SAP dot com
  2003-07-03 14:12 ` falk at debian dot org
@ 2003-07-03 14:15 ` falk at debian dot org
  2003-07-03 17:15 ` Mirko dot Luedde at SAP dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: falk at debian dot org @ 2003-07-03 14:15 UTC (permalink / raw)
  To: gcc-bugs

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 :)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/11423] IA-32 optimization bug w/ 64 bit parameters
  2003-07-03 14:00 [Bug c++/11423] New: IA-32 optimization bug w/ 64 bit parameters Mirko dot Luedde at SAP dot com
                   ` (2 preceding siblings ...)
  2003-07-03 14:15 ` falk at debian dot org
@ 2003-07-03 17:15 ` Mirko dot Luedde at SAP dot com
  2005-06-05  8:24 ` pinskia at gcc dot gnu dot org
  2005-06-05  8:25 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: Mirko dot Luedde at SAP dot com @ 2003-07-03 17:15 UTC (permalink / raw)
  To: gcc-bugs

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 Mirko dot Luedde at SAP dot com  2003-07-03 17:15 -------
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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/11423] IA-32 optimization bug w/ 64 bit parameters
  2003-07-03 14:00 [Bug c++/11423] New: IA-32 optimization bug w/ 64 bit parameters Mirko dot Luedde at SAP dot com
                   ` (3 preceding siblings ...)
  2003-07-03 17:15 ` Mirko dot Luedde at SAP dot com
@ 2005-06-05  8:24 ` pinskia at gcc dot gnu dot org
  2005-06-05  8:25 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-05  8:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-05 08:24 -------
Reopening to ...

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/11423] IA-32 optimization bug w/ 64 bit parameters
  2003-07-03 14:00 [Bug c++/11423] New: IA-32 optimization bug w/ 64 bit parameters Mirko dot Luedde at SAP dot com
                   ` (4 preceding siblings ...)
  2005-06-05  8:24 ` pinskia at gcc dot gnu dot org
@ 2005-06-05  8:25 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-05  8:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-05 08:25 -------
Mark as a dup of bug 21920.

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

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-06-05  8:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-03 14:00 [Bug c++/11423] New: IA-32 optimization bug w/ 64 bit parameters Mirko dot Luedde at SAP dot com
2003-07-03 14:04 ` [Bug c++/11423] " Mirko dot Luedde at SAP dot com
2003-07-03 14:12 ` falk at debian dot org
2003-07-03 14:15 ` falk at debian dot org
2003-07-03 17:15 ` Mirko dot Luedde at SAP dot com
2005-06-05  8:24 ` pinskia at gcc dot gnu dot org
2005-06-05  8:25 ` pinskia at gcc dot gnu dot org

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).