This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Floating point exception trapping does not always work with log ()
- From: Harald Anlauf <anlauf at gmx dot de>
- To: fortran at gcc dot gnu dot org
- Date: Wed, 19 Nov 2008 23:24:41 +0100
- Subject: Floating point exception trapping does not always work with log ()
Hi,
floating point exception trapping using the option
"-ffpe-trap=..." does not always work as expected.
Also the -fbacktrace option does not always give a
useful backtrace. As I get different behavior on
i386 and on x86_64, I would like to get some feedback
before opening an appropriate bug report.
Consider:
% cat gfcbug81.f90
program gfcbug81
a = -1.0
b = log (a)
print *, b
end program gfcbug81
On i386:
% gfc --version
GNU Fortran (GCC) 4.4.0 20081019 (experimental) [trunk revision 141218]
% gfc gfcbug81.f90 -ffpe-trap=invalid,zero,overflow -g -fbacktrace
% ./a.out
Program received signal 8 (SIGFPE): Floating-point exception.
Backtrace for this error:
+ /lib/libc.so.6 [0x4007cbf8]
+ function gfcbug81 (0x8049533)
at line 3 of file gfcbug81.f90
+ /lib/libc.so.6(__libc_start_main+0xce) [0x40068d3e]
This looks ok.
% gfc gfcbug81.f90 -ffpe-trap=invalid,zero,overflow -g -fbacktrace
-ffast-math
% ./a.out
Program received signal 8 (SIGFPE): Floating-point exception.
Backtrace for this error:
+ /lib/libc.so.6 [0x4007cbf8]
+ /lib/libc.so.6(__libc_start_main+0xce) [0x40068d3e]
Note that the line number is missing from the backtrace.
Is this expected behavior?
On an AMD64 system with openSUSE 11.0 (X86-64) but with
% gfc --version
GNU Fortran (GCC) 4.4.0 20081106 (experimental) [trunk revision 141636]
it appears that I need to use -mfpmath=387:
% gfc gfcbug81.f90 -ffpe-trap=invalid,zero,overflow -ffast-math
-mfpmath=387 -fbacktrace
% ./a.out
Program received signal 8 (SIGFPE): Floating-point exception.
Backtrace for this error:
+ /lib64/libc.so.6 [0x2b46928f3660]
+ in the main program
+ /lib64/libc.so.6(__libc_start_main+0xe6) [0x2b46928df436]
Well, no useful backtrace.
% gfc gfcbug81.f90 -ffpe-trap=invalid,zero,overflow -fno-fast-math
-mfpmath=387 -fbacktrace
% ./a.out
NaN
No trapping. :-(
Since there may be reasons to avoid the option -ffast-math,
I would like to ask for opinions to a solution of the
above problem.
Cheers,
Harald