This is the mail archive of the gcc-bugs@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]

egcs 1.0.3 miscompiles inline math from glibc 2.1



The appended test case, when compiled with -O2 by egcs 1.0.3, dumps core. 
It does not dump core when compiled with -O2 -fno-inline.  I did not link
with the math library in either case, so the pow() that gets used is
definitely the one from this file.

gcc 2.7.2.3 behaves the same.

Please let me know if you need more information.

zw

Transcript:

$ egcc -O2 test.i
$ ./a.out
Segmentation fault
$ egcc -O2 -fno-inline test.i
$ ./a.out
4294967296.000000

System information:

$ egcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/egcs-2.90.29/specs
gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)
$ uname -a
Linux midnite 2.0.34 #1 Sun Jun 28 10:51:35 EDT 1998 i586 unknown
$ /lib/libc.so.6
GNU C Library production release version 2.0.7, by Roland McGrath et al.
Compiled by GNU CC version 2.7.2.3.
[...]

Test case:

typedef unsigned long int mp_limb_t;

__inline double pow (double, double);
__inline double 
pow (double __x, double __y)
{
  register long double __value;
  register long double __exponent;
  long long int __p = (long long int) __y;
  if (__x == 0.0 && __y > 0.0)
    return 0.0;
  if (__y == (double) __p)
    {
      long double __r = 1.0;
      if (__p == 0)
	return 1.0;
      if (__p < 0)
	{
	  __p = -__p;
	  __x = 1.0 / __x;
	}
      while (1)
	{
	  if (__p & 1)
	    __r *= __x;
	  __p >>= 1;
	  if (__p == 0)
	    return __r;
	  __x *= __x;
	}
    }

  __asm __volatile__ ("fyl2x" : "=t" (__value): "0" (__x), "u" (1.0):"st(1)");
  __asm __volatile__ (
	"fmul	%%st(1)			# y * log2(x)\n\t"
	"fst	%%st(1)\n\t"
	"frndint			# int(y * log2(x))\n\t"
	"fxch\n\t"
	"fsub	%%st(1)			# fract(y * log2(x))\n\t"
	"f2xm1				# 2^(fract(y * log2(x))) - 1\n\t"
		: "=t" (__value), "=u" (__exponent)
		: "0" (__y), "1" (__value));
  __value += 1.0;
  __asm __volatile__ ("fscale"	: "=t" (__value)
				: "0" (__value), "u" (__exponent));
  return __value;
}

extern int printf (__const char *__format,...);

typedef mp_limb_t mp1[((32 * 4) / (8 * sizeof (mp_limb_t)) + 1)];

int
main (void)
{
  mp1 si, co, x, ox, xt, s2, c2, s3, c3;
  int i;
  int sin_errors = 0, cos_errors = 0;
  int sin_failures = 0, cos_failures = 0;
  mp1 sin_maxerror, cos_maxerror;
  int sin_maxerror_s = 0, cos_maxerror_s = 0;

  const double sf = pow (2, (8 * sizeof (mp_limb_t)));  /* core here */

  printf ("%f\n", sf);
  return 0;
}


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