summaryrefslogtreecommitdiffstats
path: root/libgfortran
diff options
context:
space:
mode:
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>2022-01-02 11:36:23 +0100
committerFrancois-Xavier Coudert <fxcoudert@gmail.com>2022-01-10 12:28:46 +0100
commit492954263e39346287a5a2a32bcc5312466a0ee1 (patch)
tree839dd37ee7e5d1ef72ae09a908ddb9bf55035282 /libgfortran
parentmiddle-end/101530 - fix shufflevector lowering (diff)
downloadgcc-492954263e39346287a5a2a32bcc5312466a0ee1.tar.gz
gcc-492954263e39346287a5a2a32bcc5312466a0ee1.tar.bz2
gcc-492954263e39346287a5a2a32bcc5312466a0ee1.tar.xz
Fortran: Allow IEEE_CLASS to identify signaling NaNs
We use the issignaling macro, present in some libc's (notably glibc), when it is available. Compile all IEEE-related files in the library (both C and Fortran sources) with -fsignaling-nans to ensure maximum compatibility. libgfortran/ChangeLog: PR fortran/82207 * Makefile.am: Pass -fsignaling-nans for IEEE files. * Makefile.in: Regenerate. * ieee/ieee_helper.c: Use issignaling macro to recognized signaling NaNs. gcc/testsuite/ChangeLog: PR fortran/82207 * gfortran.dg/ieee/signaling_1.f90: New test. * gfortran.dg/ieee/signaling_1_c.c: New file.
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/Makefile.am8
-rw-r--r--libgfortran/Makefile.in6
-rw-r--r--libgfortran/ieee/ieee_helper.c15
3 files changed, 25 insertions, 4 deletions
diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index 008f2e7549c..b7ef912a440 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -185,6 +185,8 @@ endif
185 185
186if IEEE_SUPPORT 186if IEEE_SUPPORT
187 187
188gfor_ieee_helper_src=ieee/ieee_helper.c
189
188gfor_helper_src+=ieee/ieee_helper.c 190gfor_helper_src+=ieee/ieee_helper.c
189 191
190gfor_ieee_src= \ 192gfor_ieee_src= \
@@ -991,9 +993,13 @@ selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-unders
991 993
992if IEEE_SUPPORT 994if IEEE_SUPPORT
993# Add flags for IEEE modules 995# Add flags for IEEE modules
994$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore 996$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore -fsignaling-nans
997
998# Add flags for IEEE helper code
999$(patsubst %.c,%.lo,$(notdir $(gfor_ieee_helper_src))): AM_CFLAGS += -fsignaling-nans
995endif 1000endif
996 1001
1002
997# Dependencies between IEEE_ARITHMETIC and IEEE_EXCEPTIONS 1003# Dependencies between IEEE_ARITHMETIC and IEEE_EXCEPTIONS
998ieee_arithmetic.lo: ieee/ieee_arithmetic.F90 ieee_exceptions.lo 1004ieee_arithmetic.lo: ieee/ieee_arithmetic.F90 ieee_exceptions.lo
999 $(LTPPFCCOMPILE) -c -o $@ $< 1005 $(LTPPFCCOMPILE) -c -o $@ $<
diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in
index 5dac04e171e..3684b2aaa75 100644
--- a/libgfortran/Makefile.in
+++ b/libgfortran/Makefile.in
@@ -779,6 +779,7 @@ gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \
779 intrinsics/selected_real_kind.f90 intrinsics/trigd.c \ 779 intrinsics/selected_real_kind.f90 intrinsics/trigd.c \
780 intrinsics/unpack_generic.c runtime/in_pack_generic.c \ 780 intrinsics/unpack_generic.c runtime/in_pack_generic.c \
781 runtime/in_unpack_generic.c $(am__append_3) $(am__append_4) 781 runtime/in_unpack_generic.c $(am__append_3) $(am__append_4)
782@IEEE_SUPPORT_TRUE@gfor_ieee_helper_src = ieee/ieee_helper.c
782@IEEE_SUPPORT_FALSE@gfor_ieee_src = 783@IEEE_SUPPORT_FALSE@gfor_ieee_src =
783@IEEE_SUPPORT_TRUE@gfor_ieee_src = \ 784@IEEE_SUPPORT_TRUE@gfor_ieee_src = \
784@IEEE_SUPPORT_TRUE@ieee/ieee_arithmetic.F90 \ 785@IEEE_SUPPORT_TRUE@ieee/ieee_arithmetic.F90 \
@@ -6999,7 +7000,10 @@ $(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM
6999selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore 7000selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore
7000 7001
7001# Add flags for IEEE modules 7002# Add flags for IEEE modules
7002@IEEE_SUPPORT_TRUE@$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore 7003@IEEE_SUPPORT_TRUE@$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore -fsignaling-nans
7004
7005# Add flags for IEEE helper code
7006@IEEE_SUPPORT_TRUE@$(patsubst %.c,%.lo,$(notdir $(gfor_ieee_helper_src))): AM_CFLAGS += -fsignaling-nans
7003 7007
7004# Dependencies between IEEE_ARITHMETIC and IEEE_EXCEPTIONS 7008# Dependencies between IEEE_ARITHMETIC and IEEE_EXCEPTIONS
7005ieee_arithmetic.lo: ieee/ieee_arithmetic.F90 ieee_exceptions.lo 7009ieee_arithmetic.lo: ieee/ieee_arithmetic.F90 ieee_exceptions.lo
diff --git a/libgfortran/ieee/ieee_helper.c b/libgfortran/ieee/ieee_helper.c
index d70728c5b79..7a103df58f0 100644
--- a/libgfortran/ieee/ieee_helper.c
+++ b/libgfortran/ieee/ieee_helper.c
@@ -25,6 +25,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 25
26#include "libgfortran.h" 26#include "libgfortran.h"
27 27
28
29/* Check support for issignaling macro.
30 TODO: In the future, provide fallback implementations for IEEE types,
31 because many libc's do not have issignaling yet. */
32#ifndef issignaling
33# define issignaling(X) 0
34#endif
35
36
28/* Prototypes. */ 37/* Prototypes. */
29 38
30extern int ieee_class_helper_4 (GFC_REAL_4 *); 39extern int ieee_class_helper_4 (GFC_REAL_4 *);
@@ -86,8 +95,10 @@ enum {
86 \ 95 \
87 if (res == IEEE_QUIET_NAN) \ 96 if (res == IEEE_QUIET_NAN) \
88 { \ 97 { \
89 /* TODO: Handle signaling NaNs */ \ 98 if (issignaling (*value)) \
90 return res; \ 99 return IEEE_SIGNALING_NAN; \
100 else \
101 return IEEE_QUIET_NAN; \
91 } \ 102 } \
92 \ 103 \
93 return res; \ 104 return res; \