[PATCH v3] Change default to -fno-math-errno

Wilco Dijkstra Wilco.Dijkstra@arm.com
Thu Oct 11 14:54:00 GMT 2018


Hi,

> Note that "will ever set errno" includes possibly setting it in the 
> future, since code may be built with one libm version and used with 
> another.  So it wouldn't be correct to have a "never sets errno" attribute 
> on glibc logb / lround / llround / lrint / llrint / fma / remquo (missing 
> errno setting is a known bug).  

If these functions should set errno, there are many issues both in GCC and
GLIBC. GCC treats fma and remquo always as const/pure, so inlines fma
always even with -fmath-errno. GLIBC targets which support fma as a
single instruction always inline it as a single instruction, as expected.

GCC incorrectly treats many other math functions as const/pure, for 
example GCC "knows" that the C89 sin function will never set errno with
-fmath-errno:

#include <math.h>
#include <errno.h>
int res;
double f(double x)
{
  errno = 0;
  double y = sin (x);
  res = errno;
  return y;
}

So if anything this is good evidence that nobody is using errno in actual
applications, otherwise these bugs would have been found many years ago.

Wilco


More information about the Gcc-patches mailing list