May snapshots bug with -O2, __inline__, const (Linux/ia32)

Paul Kimoto kimoto@lightlink.com
Wed May 31 13:03:00 GMT 2000


I am using Linux (Debian frozen "potato") on i586.  The May snapshots
(20000508 and 20000530) miscompile the appended function when I use
"-O2".  (The result returned by dfdx() is wrong; this doesn't depend
on which branch of the if/else construct is taken.)

Any of the following measures give me the right result:
 - use gcc-2.95.2
 - use -O1 instead of -O2
 - change "const double df0" to "double df0"
 - remove __inline__ (although the result is still wrong if I use "-O3")

	-Paul <kimoto@lightlink.com>


/* begin C code */

double dfdx (double (*f)(double *), double **u, double x, double dx);

static __inline__ double
dfdxj (double (*f)(double *), double **u, int j, double dx)
{
   return (f(u[j+1]) - f(u[j-1]))/(2.0*dx);
}

double
dfdx (double (*f)(double *), double **u, double x, double dx)
{
   const int j = x/dx + 0.5;
   const double df0 = dfdxj (f, u, j, dx);

   if (x == j*dx)
      return df0;
   else {
      double df1 = dfdxj (f, u, j+1, dx);
      return 0.5*(df0 + df1);
   }
}

/* end C code */


More information about the Gcc-bugs mailing list