summaryrefslogtreecommitdiff
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
parentbe59671c5624fe8bf21ddb0192e97ebdfa4db381 (diff)
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
if IEEE_SUPPORT
+gfor_ieee_helper_src=ieee/ieee_helper.c
+
gfor_helper_src+=ieee/ieee_helper.c
gfor_ieee_src= \
@@ -991,9 +993,13 @@ selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-unders
if IEEE_SUPPORT
# Add flags for IEEE modules
-$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore
+$(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
+
+# Add flags for IEEE helper code
+$(patsubst %.c,%.lo,$(notdir $(gfor_ieee_helper_src))): AM_CFLAGS += -fsignaling-nans
endif
+
# Dependencies between IEEE_ARITHMETIC and IEEE_EXCEPTIONS
ieee_arithmetic.lo: ieee/ieee_arithmetic.F90 ieee_exceptions.lo
$(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 \
intrinsics/selected_real_kind.f90 intrinsics/trigd.c \
intrinsics/unpack_generic.c runtime/in_pack_generic.c \
runtime/in_unpack_generic.c $(am__append_3) $(am__append_4)
+@IEEE_SUPPORT_TRUE@gfor_ieee_helper_src = ieee/ieee_helper.c
@IEEE_SUPPORT_FALSE@gfor_ieee_src =
@IEEE_SUPPORT_TRUE@gfor_ieee_src = \
@IEEE_SUPPORT_TRUE@ieee/ieee_arithmetic.F90 \
@@ -6999,7 +7000,10 @@ $(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM
selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore
# Add flags for IEEE modules
-@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
+@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
+
+# Add flags for IEEE helper code
+@IEEE_SUPPORT_TRUE@$(patsubst %.c,%.lo,$(notdir $(gfor_ieee_helper_src))): AM_CFLAGS += -fsignaling-nans
# Dependencies between IEEE_ARITHMETIC and IEEE_EXCEPTIONS
ieee_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
#include "libgfortran.h"
+
+/* Check support for issignaling macro.
+ TODO: In the future, provide fallback implementations for IEEE types,
+ because many libc's do not have issignaling yet. */
+#ifndef issignaling
+# define issignaling(X) 0
+#endif
+
+
/* Prototypes. */
extern int ieee_class_helper_4 (GFC_REAL_4 *);
@@ -86,8 +95,10 @@ enum {
\
if (res == IEEE_QUIET_NAN) \
{ \
- /* TODO: Handle signaling NaNs */ \
- return res; \
+ if (issignaling (*value)) \
+ return IEEE_SIGNALING_NAN; \
+ else \
+ return IEEE_QUIET_NAN; \
} \
\
return res; \