target/6087: 3.1 i86 FP stack pop bug
Thu Mar 28 17:03:00 GMT 2002

>Number:         6087
>Category:       target
>Synopsis:       3.1 i86 FP stack pop bug
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 28 16:16:02 PST 2002
>Originator:     scott snyder
>Release:        3.1 20020326 (prerelease)
System: Linux karma 2.4.9-13 #1 Tue Oct 30 20:11:04 EST 2001 i686 unknown
Architecture: i686

host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../egcs/configure --prefix=/usr/local/egcs --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77

The code below executes incorrectly.
Here's what i get:

$ g++ -O0 -o x
$ ./x

What's happening is that the CftRibbon() constructor
is not properly popping the result of foobar5() off the FP stack.
The stack eventually fills up, and we start getting nan's resulting
from FP operations.

Here's the generated code for the call to foobar5():

        call    _Z7foobar5v
        fld     %st(0)
        jmp     .L1

Instead of popping the returned value, this duplicates it.


Compile and link together these two sources.

-- ----------------------------------------------------------
struct d0om_Registerable
  virtual ~d0om_Registerable () {}

struct CftRibbon : public d0om_Registerable
  CftRibbon ();
double foobar5 ();

CftRibbon::CftRibbon ()

int main ()
  new CftRibbon;
  new CftRibbon;
  new CftRibbon;
  new CftRibbon;
  new CftRibbon;
  new CftRibbon;
  return 0;
-- ----------------------------------------------------------
extern "C" int printf(...);
double x = 3;
double y = 4;
double foobar5 ()
  double z = x*x+y*y;
  printf ("%lf\n", z);
  return z;



More information about the Gcc-bugs mailing list