Bug 39314 - -ffpe-trap=invalid gives no FPE for acos(-5.0)
Summary: -ffpe-trap=invalid gives no FPE for acos(-5.0)
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-26 15:27 UTC by janus
Modified: 2009-03-28 12:23 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-unknown-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2009-02-26 15:27:47 UTC
The following produces an FPE when compiled with -ffpe-trap=invalid:

real :: x = 1.0
print *, sqrt(-1.0*x)

However, using acos or asin does not:

real :: x = 1.0
print *, acos(5.0*x)
print *, asin(5.0*x)

Instead it just prints out "NaN". The FPE is missing both in 4.3 and on trunk.
Comment 1 kargls 2009-02-26 15:35:34 UTC
What target?

Works for me on FreeBSD.

laptop:kargl[23] ~/work/bin/gfortran -static -o z -ffpe-trap=invalid j.f90
laptop:kargl[24] ./z
Floating exception (core dumped)
laptop:kargl[25] cat j.f90
real :: x = 1.0
print *, acos(5.0*x)
print *, asin(5.0*x)

end
Comment 2 janus 2009-02-26 15:45:08 UTC
Sorry, forgot to specify the target: x86_64-unknown-linux-gnu.
Comment 3 Tobias Burnus 2009-02-26 18:03:50 UTC
Confirm: Here, I get the same result with -m64 on Linux (NaN and no SIGFPE), but with -m32 (with both -mfpmath=sse and -mfpmath=387) I get the SIGFPE.

The FPE settings are used in libgfortran/config/*; maybe fpu-387.h does something wrong in the x86-64 mode?
Comment 4 Andrew Pinski 2009-02-26 18:05:21 UTC
Or maybe libc's acos is broken ....  In which case this is not a GCC bug.
Comment 5 janus 2009-02-26 19:22:29 UTC
Also on i386-apple-darwin9.6.0 the FPEs are thrown correctly.
Comment 6 janus 2009-02-27 09:01:43 UTC
On x86_64-unknown-linux-gnu I *do* get the ICE when I compile with -ffast-math -mfpmath=387. Cf. http://gcc.gnu.org/ml/fortran/2008-11/msg00250.html.
Comment 7 janus 2009-02-27 09:13:41 UTC
Note that the problem also appears for log, while it does not for acosh and atanh:

real :: x = -5.0

! FPE is not thrown
print *, log(x)
print *, log10(x)
print *, acos(x)
print *, asin(x)

! FPE is thrown
!print *, sqrt(x)
!print *, atanh(x)
!print *, acosh(x)

end 
Comment 8 Tobias Burnus 2009-02-27 10:49:18 UTC
> Note that the problem also appears for log, while it does not for acosh and
> atanh:

If it works with some but not all libm routines, it sounds more like a GLIBC than like a GCC problem.
Comment 9 janus 2009-02-27 13:15:15 UTC
(In reply to comment #8)
> If it works with some but not all libm routines, it sounds more like a GLIBC
> than like a GCC problem.

Can someone reproduce this with C code?
Comment 10 Tobias Burnus 2009-03-10 15:29:42 UTC
> Can someone reproduce this with C code?

Yes: The following gives a SIGFPE with -m32 (logf, sqrtf) and with -m64 and "sqrtf" but not with -m64 with "logf". (Compile with "-fsignaling-nans" and "-lm".)

-----------------<cut>--------------------

#ifndef __SUPPORT_SNAN__
#  error No SNAN support - use "-fsignaling-nans"
#endif
#define _WANT_SNAN 1
#include <stdio.h>
#include <math.h>
#include <fenv.h>

int main()
{
  float x = -5.0, y;
  feenableexcept(FE_ALL_EXCEPT);
  y = logf(x);
  printf("%e\n",y);
  return 0;
}
Comment 11 Francois-Xavier Coudert 2009-03-28 08:44:41 UTC
The x86_64 FPE code in libgfortran works fine, as evidenced by the fact that it works with some glibcs (RedHat's glibc-2.5 for example) and on Mac OS 10.5.6 (which uses the same FPE setter). Closing as INVALID, please report to glibc or distro vendor (Tobias did it with Novell here: https://bugzilla.novell.com/show_bug.cgi?id=487576)
Comment 12 Tobias Burnus 2009-03-28 12:23:48 UTC
On #gcc it was confirmed to give a SIGFPE on gentoo with glibc 2.9 on x86-64. I think it is one of the @amd.com patches for x86-64 which fixes some performance problems but has the side effect that it doesn't honour the FPE.