This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/64101] New: GCC considers that the erf math function does not set errno
- From: "niva at niisi dot msk.ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 28 Nov 2014 12:54:36 +0000
- Subject: [Bug middle-end/64101] New: GCC considers that the erf math function does not set errno
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64101
Bug ID: 64101
Summary: GCC considers that the erf math function does not set
errno
Product: gcc
Version: 4.7.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: niva at niisi dot msk.ru
Created attachment 34131
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34131&action=edit
The preprocessed source of the test program
We use a cross-conpiler configured as follows:
/home/niva/src/gcc-4.7.4/configure --target=mips64-none-elf --enable-threads=no
--disable-shared --enable-long-long --enable-c99 --enable-languages=c
--enable-multilib --enable-symvers=gnu --disable-libmudflap --disable-libssp
--disable-libgcc_eh --with-newlib --with-dwarf2 --with-system-zlib
--enable-generated-files-in-srcdir --verbose --prefix=/home/niva/local
--enable-cpp
The following program (the preprocessed source is attached)
#include <assert.h>
#include <errno.h>
#include <math.h>
int main ()
{
double res;
errno = 0;
res = erf (-1.2553634935946022721708238314E-308);
assert (errno == ERANGE);
return 0;
}
compiled as
mips64-none-elf-gcc -O1 tst_erf.c
produces an assertion though we use a POSIX-compliant math
library and the erf function sets errno = ERANGE
according to erf description in POSIX Programmer's Manual.
The test program works correctly (i.e. without the assertion)
if we compile it with -fno-builtin-erf.
Apparently GCC treats erf as a "clean" or "pure" function
(see gcc/builtins.def). IMHO this is not correct.
ISO C 99 (see 7.12.8.1) does not state directly whether erf
may set errno. But in 7.12.1 (6) it is stated that
"If the result underflows, the function returns an
implementation-defined value whose magnitude is no greater than the smallest
normalized positive number in the specified type; if the integer expression
math_errhandling & MATH_ERRNO is nonzero, whether errno acquires the
value ERANGE is implementation-defined; if the integer expression
math_errhandling & MATH_ERREXCEPT is nonzero, whether the ââunderflowââ
floating-point exception is raised is implementation-defined."
In many Linux erf man pages we read that
"These functions do not set errno".
But there is a bug report
https://sourceware.org/bugzilla/show_bug.cgi?id=6785 :
"When erf() is given a subnormal argument, it raises an underflow exception.
However errno is not set. It should be set to ERANGE."