This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: c/2684: gcc 2.95.3 bad optimization corrupts x86 FP stack



This test case does not fail with current gcc sources but it does fail
with gcc-2.95.3 and I think it ought to be represented in the test suite.
The current bad system practice of turning off all the fpu traps has
the effect of hiding x87 fp stack overflows, so bugs like this can lurk
for a long time without being diagnosed.

The version below has been modified slightly to replace the printf by
an abort, and it still fails with 2.95.3.  Could someone please put it
in, for example as gcc/testsuite/gcc.c-torture/execute/regstack-2.c ?

-------

void
get_nums (double d[3])
{
  d[0] = 1;
  d[1] = 2;
  d[2] = 3;
}

void
leave_cruft_on_fpu_stack (double d[2])
{
  double ret[3];
  double f0, f1, f2, f3, f4;
  int t13;

  get_nums (ret);
  f0 = ret[0];
  f1 = ret[1];
  f2 = ret[2];

  f3 = f0 / f2;
  f4 = f1 / f2;
  t13 = printf (" ");
  printf (" ");
  if (f3 == 1.0) goto L1;
  if (f3 == 0.0) goto L1;
  if (f4 == 1.0) goto L1;
  goto L3;
L1:;
  d[0] = f3;
  goto L4;
L3:;
  d[0] = f3;
L4:;
}


volatile double n = 0.5;

int
main (int argc, char *argv[])
{
  double d[2];
  int i;

  for (i = 0; i < 10; i++)
    {
      leave_cruft_on_fpu_stack (d);
      if ((n + n) != 1.0)
	abort ();
    }

  exit (0);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]