public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow
@ 2013-06-01 8:32 burnus at gcc dot gnu.org
2013-06-01 18:37 ` [Bug fortran/57496] " burnus at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-06-01 8:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57496
Bug ID: 57496
Summary: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives
SIGFPE with -ffpe-trap=overflow
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
CC: jb at gcc dot gnu.org, jvdelisle at gcc dot gnu.org
Reported at http://gcc.gnu.org/ml/fortran/2013-05/msg00136.html /
http://gcc.gnu.org/ml/fortran/2013-05/msg00138.html
The following program gives a floating-point exception when compiled with
-ffpe-trap=overflow:
print *, huge(0.0_10)
print *, huge(0.0_16)
end
The segfault occurs for:
WRITE_FLOAT(10,L)
and
WRITE_FLOAT(16,Q)
in libgfortran/io/write_float.def
I have not debugged the code. However, I realized that the following has to be
done - in addition - as one otherwise calls the wrong functions for __float128.
--- a/libgfortran/io/write_float.def
+++ b/libgfortran/io/write_float.def
@@ -963,0 +964,28 @@ __qmath_(quadmath_snprintf) (buffer, size, "%+-#.*Qf", \
+#if defined(GFC_REAL_16_IS_FLOAT128)
+#define ISFINITE2(prec,val) finiteq(val)
+#endif
+#define ISFINITE2(prec,val) isfinite(val)
+#define ISFINITE2L(prec,val) isfinite(val)
+
+#define ISFINITE(suff,val) TOKENPASTE(ISFINITE2,suff)(val)
+
+
+#if defined(GFC_REAL_16_IS_FLOAT128)
+#define SIGNBIT2(prec,val) signbitq(val)
+#endif
+#define SIGNBIT2(prec,val) signbit(val)
+#define SIGNBIT2L(prec,val) signbit(val)
+
+#define SIGNBIT(suff,val) TOKENPASTE(SIGNBIT2,suff)(val)
+
+
+#if defined(GFC_REAL_16_IS_FLOAT128)
+#define ISNAN2(prec,val) isnanq(val)
+#endif
+#define ISNAN2(prec,val) isnan(val)
+#define ISNAN2L(prec,val) isnan(val)
+
+#define ISNAN(suff,val) TOKENPASTE(ISNAN2,suff)(val)
+
+
+
@@ -1197,2 +1225,2 @@ determine_en_precision (st_parameter_dt *dtp, const fnode
- sign_bit = signbit (tmp);\
- if (!isfinite (tmp))\
+ sign_bit = SIGNBIT (x,tmp);\
+ if (!ISFINITE (x,tmp))\
@@ -1200 +1228 @@ determine_en_precision (st_parameter_dt *dtp, const fnode *f,
- write_infnan (dtp, f, isnan (tmp), sign_bit);\
+ write_infnan (dtp, f, ISNAN (x,tmp), sign_bit);\
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/57496] I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow
2013-06-01 8:32 [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow burnus at gcc dot gnu.org
@ 2013-06-01 18:37 ` burnus at gcc dot gnu.org
2013-06-03 9:29 ` burnus at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-06-01 18:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57496
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
The submitted patch at http://gcc.gnu.org/ml/fortran/2013-06/msg00005.html
actually solves the problem for REAL(16).
NOTE: I forgot to change one "isfinite" to "ISFINITE" in OUTPUT_FLOAT_FMT_G.
* * *
Pre-remark: All the tests below were done on x86-64-gnu-linux with -m64, but I
also tried -m32.
For REAL(10) it fails at the call:
+ if (!__finitel (tmp))
I tried the following simple C example, compiled with "gfortran
-ffpe-trap=overflow file.c file.f90". Result: no failure (and "T" as output).
------------------------------------
#include <math.h>
_Bool myIsFinite (long double x) {
return isfinite (x);
}
------------------------------------
use iso_c_binding
interface
logical(c_bool) function myIsFinite (x) bind(C, name="myIsFinite")
import
real(c_long_double), value :: x
end function myIsFinite
end interface
print *, myIsFinite(huge(0.0_c_long_double))
end
------------------------------------
The __finitel is handled on x86-64 as library call. I tried to set the break
point into __finitel but it seems as if the overflow error occurs before.
If I place a printf in libgfortran before the __finitel call, it prints
"1.189731e+4932" - before failing in the next line.
However, if I compile the file with -ffloat-store, it already fails in the
"printf" line; it also fails in that line if compiled with -O0 (and w/o
-ffloat-store).
For libgfortran's write_float in "case 10:", I now have after manual macro
expansion:
case 10:
{
GFC_REAL_10 tmp;
tmp = * (GFC_REAL_10 *)source;
sign_bit = signbit (tmp);
printf ("DEBUG: %Le\n", tmp); /* Added. */
if (!__finitel (tmp))
The assembler code is (without -ffloat-store):
call printf
.LVL694:
.loc 3 1287 0
fldt -192(%rbp)
fld %st(0)
fstpt (%rsp)
.LVL695:
fstpt -192(%rbp)
call __finitel
.LVL696:
testl %eax, %eax
fldt -192(%rbp)
je .L971
While the simple C test case - which doesn't fail - above gives:
subq $24, %rsp
.cfi_def_cfa_offset 32
fldt 32(%rsp)
fstpt (%rsp)
call __finitel
testl %eax, %eax
setne %al
addq $24, %rsp
.cfi_def_cfa_offset 8
ret
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/57496] I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow
2013-06-01 8:32 [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow burnus at gcc dot gnu.org
2013-06-01 18:37 ` [Bug fortran/57496] " burnus at gcc dot gnu.org
@ 2013-06-03 9:29 ` burnus at gcc dot gnu.org
2013-06-03 9:31 ` [Bug fortran/57496] I/O: WRITE(*,*) HUGE(0._10) gives " burnus at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-06-03 9:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57496
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Author: burnus
Date: Mon Jun 3 09:20:46 2013
New Revision: 199598
URL: http://gcc.gnu.org/viewcvs?rev=199598&root=gcc&view=rev
Log:
2013-06-01 Tobias Burnus <burnus@net-b.de>
PR fortran/57496
* io/write_float.def (ISFINITE2Q, ISFINITE2, ISFINITE2L,
* ISFINITE,
SIGNBIT2Q, SIGNBIT2, SIGNBIT2L, SIGNBIT, ISNAN2Q, ISNAN2,
ISNAN2L, ISNAN): New macros.
(output_float_FMT_G_,WRITE_FLOAT): Use them.
Modified:
trunk/libgfortran/ChangeLog
trunk/libgfortran/io/write_float.def
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/57496] I/O: WRITE(*,*) HUGE(0._10) gives SIGFPE with -ffpe-trap=overflow
2013-06-01 8:32 [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow burnus at gcc dot gnu.org
2013-06-01 18:37 ` [Bug fortran/57496] " burnus at gcc dot gnu.org
2013-06-03 9:29 ` burnus at gcc dot gnu.org
@ 2013-06-03 9:31 ` burnus at gcc dot gnu.org
2013-06-27 9:46 ` dominiq at lps dot ens.fr
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-06-03 9:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57496
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|I/O: WRITE(*,*) HUGE(0_16) |I/O: WRITE(*,*) HUGE(0._10)
|[REAL(10)+REAL(16)]: Gives |gives SIGFPE with
|SIGFPE with |-ffpe-trap=overflow
|-ffpe-trap=overflow |
--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> ---
The commit in comment 3 solved the problem for REAL(16).
For REAL(10) (= long double), there is still a problem:
print *, HUGE(0.0_10)
end
gives a SIGFPE with -ffpe-trap=overflow. See comment 2 for details.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/57496] I/O: WRITE(*,*) HUGE(0._10) gives SIGFPE with -ffpe-trap=overflow
2013-06-01 8:32 [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow burnus at gcc dot gnu.org
` (2 preceding siblings ...)
2013-06-03 9:31 ` [Bug fortran/57496] I/O: WRITE(*,*) HUGE(0._10) gives " burnus at gcc dot gnu.org
@ 2013-06-27 9:46 ` dominiq at lps dot ens.fr
2015-08-16 15:27 ` fxcoudert at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: dominiq at lps dot ens.fr @ 2013-06-27 9:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57496
Dominique d'Humieres <dominiq at lps dot ens.fr> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-06-27
Ever confirmed|0 |1
--- Comment #5 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Still present at revision 200429 for huge(0.0_10).
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/57496] I/O: WRITE(*,*) HUGE(0._10) gives SIGFPE with -ffpe-trap=overflow
2013-06-01 8:32 [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow burnus at gcc dot gnu.org
` (3 preceding siblings ...)
2013-06-27 9:46 ` dominiq at lps dot ens.fr
@ 2015-08-16 15:27 ` fxcoudert at gcc dot gnu.org
2015-08-16 15:31 ` [Bug libfortran/57496] " fxcoudert at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2015-08-16 15:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57496
Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu.org,
| |fxcoudert at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |fxcoudert at gcc dot gnu.org
--- Comment #6 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
On x86_64-apple-darwin14, I can confirm this occurs on 5.2.0 but appears to
have been fixed on trunk.
Also, I don't understand how Tobias' patch worked, because in libgfortran.h we
have for a long time redefined all the type-generic floating-point macros in
terms of "safe to use" GCC builtins:
/* The C99 classification macros isfinite, isinf, isnan, isnormal
and signbit are broken or inconsistent on quite a few targets.
So, we use GCC's builtins instead.
Another advantage for GCC's builtins for these type-generic macros
is that it handles floating-point types that the system headers
may not support (like __float128). */
#undef isnan
#define isnan(x) __builtin_isnan(x)
#undef isfinite
#define isfinite(x) __builtin_isfinite(x)
#undef isinf
#define isinf(x) __builtin_isinf(x)
#undef isnormal
#define isnormal(x) __builtin_isnormal(x)
#undef signbit
#define signbit(x) __builtin_signbit(x)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libfortran/57496] I/O: WRITE(*,*) HUGE(0._10) gives SIGFPE with -ffpe-trap=overflow
2013-06-01 8:32 [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow burnus at gcc dot gnu.org
` (4 preceding siblings ...)
2015-08-16 15:27 ` fxcoudert at gcc dot gnu.org
@ 2015-08-16 15:31 ` fxcoudert at gcc dot gnu.org
2015-08-24 16:32 ` fxcoudert at gcc dot gnu.org
2015-08-24 16:34 ` fxcoudert at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2015-08-16 15:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57496
Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|fortran |libfortran
--- Comment #7 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
(In reply to Francois-Xavier Coudert from comment #6)
> Also, I don't understand how Tobias' patch worked, because in libgfortran.h
> we have for a long time redefined all the type-generic floating-point macros
> in terms of "safe to use" GCC builtins
In fact, I can actually reverse the patch and the testcase does not fail.
Index: io/write_float.def
===================================================================
--- io/write_float.def (revision 226894)
+++ io/write_float.def (working copy)
@@ -958,33 +958,6 @@ __qmath_(quadmath_snprintf) (buffer, siz
#endif
-#if defined(GFC_REAL_16_IS_FLOAT128)
-#define ISFINITE2Q(val) finiteq(val)
-#endif
-#define ISFINITE2(val) isfinite(val)
-#define ISFINITE2L(val) isfinite(val)
-
-#define ISFINITE(suff,val) TOKENPASTE(ISFINITE2,suff)(val)
-
-
-#if defined(GFC_REAL_16_IS_FLOAT128)
-#define SIGNBIT2Q(val) signbitq(val)
-#endif
-#define SIGNBIT2(val) signbit(val)
-#define SIGNBIT2L(val) signbit(val)
-
-#define SIGNBIT(suff,val) TOKENPASTE(SIGNBIT2,suff)(val)
-
-
-#if defined(GFC_REAL_16_IS_FLOAT128)
-#define ISNAN2Q(val) isnanq(val)
-#endif
-#define ISNAN2(val) isnan(val)
-#define ISNAN2L(val) isnan(val)
-
-#define ISNAN(suff,val) TOKENPASTE(ISNAN2,suff)(val)
-
-
/* Generate corresponding I/O format for FMT_G and output.
The rules to translate FMT_G to FMT_E or FMT_F from DEC fortran
@@ -1164,7 +1137,7 @@ OUTPUT_FLOAT_FMT_G(16,L)
{\
volatile GFC_REAL_ ## x tmp, one = 1.0;\
tmp = * (GFC_REAL_ ## x *)source;\
- if (ISFINITE (y,tmp))\
+ if (isfinite (tmp))\
{\
nprinted = DTOA(y,0,tmp);\
int e = atoi (&buffer[4]);\
@@ -1235,10 +1208,10 @@ determine_en_precision (st_parameter_dt
{\
GFC_REAL_ ## x tmp;\
tmp = * (GFC_REAL_ ## x *)source;\
- sign_bit = SIGNBIT (y,tmp);\
- if (!ISFINITE (y,tmp))\
+ sign_bit = signbit (tmp);\
+ if (!isfinite (tmp))\
{ \
- write_infnan (dtp, f, ISNAN (y,tmp), sign_bit);\
+ write_infnan (dtp, f, isnan (tmp), sign_bit);\
return;\
}\
tmp = sign_bit ? -tmp : tmp;\
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libfortran/57496] I/O: WRITE(*,*) HUGE(0._10) gives SIGFPE with -ffpe-trap=overflow
2013-06-01 8:32 [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow burnus at gcc dot gnu.org
` (5 preceding siblings ...)
2015-08-16 15:31 ` [Bug libfortran/57496] " fxcoudert at gcc dot gnu.org
@ 2015-08-24 16:32 ` fxcoudert at gcc dot gnu.org
2015-08-24 16:34 ` fxcoudert at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2015-08-24 16:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57496
--- Comment #8 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
Author: fxcoudert
Date: Mon Aug 24 16:31:47 2015
New Revision: 227136
URL: https://gcc.gnu.org/viewcvs?rev=227136&root=gcc&view=rev
Log:
PR libfortran/57496
* io/write_float.def: Use built-in type-generic functions defined
by libgfortran.h for isfinite, isnan, and signbit.
Modified:
trunk/libgfortran/ChangeLog
trunk/libgfortran/io/write_float.def
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libfortran/57496] I/O: WRITE(*,*) HUGE(0._10) gives SIGFPE with -ffpe-trap=overflow
2013-06-01 8:32 [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow burnus at gcc dot gnu.org
` (6 preceding siblings ...)
2015-08-24 16:32 ` fxcoudert at gcc dot gnu.org
@ 2015-08-24 16:34 ` fxcoudert at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2015-08-24 16:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57496
Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |6.0
--- Comment #9 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
Fixed on trunk.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-08-24 16:34 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-01 8:32 [Bug fortran/57496] New: I/O: WRITE(*,*) HUGE(0_16) [REAL(10)+REAL(16)]: Gives SIGFPE with -ffpe-trap=overflow burnus at gcc dot gnu.org
2013-06-01 18:37 ` [Bug fortran/57496] " burnus at gcc dot gnu.org
2013-06-03 9:29 ` burnus at gcc dot gnu.org
2013-06-03 9:31 ` [Bug fortran/57496] I/O: WRITE(*,*) HUGE(0._10) gives " burnus at gcc dot gnu.org
2013-06-27 9:46 ` dominiq at lps dot ens.fr
2015-08-16 15:27 ` fxcoudert at gcc dot gnu.org
2015-08-16 15:31 ` [Bug libfortran/57496] " fxcoudert at gcc dot gnu.org
2015-08-24 16:32 ` fxcoudert at gcc dot gnu.org
2015-08-24 16:34 ` fxcoudert at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).