[cfe-dev] default setting of -fmath-errno
Jay Foad
jay.foad at gmail.com
Fri Nov 11 03:44:23 PST 2011
Hi,
I was surprised by a difference between clang and gcc. On gcc, the
docs for -fno-math-errno say:
"This option is not turned on by any -O option since it can result in
incorrect output for programs which depend on an exact implementation
of IEEE or ISO rules/specifications for math functions."
But with clang, it seems that when I turn on any optimization (-O1 or
higher), I *do* get the effect of -fno-math-errno. Is this
intentional?
There's a test case below. If I compile with "clang -O" and run it, I
get "result -nan, errno 0". I'm using the 3.0rc3 release on
Linux/x86_64.
Thanks,
Jay.
#include <errno.h>
#include <math.h>
#include <stdio.h>
int main(int argc, const char *argv[])
{
double d;
errno = 0;
d = sqrt(argc - 5);
printf("result %g, errno %d\n", d, errno);
return 0;
}
More information about the cfe-dev
mailing list