diff mbox series

float.h: C2x NaN and Inf macros

Message ID alpine.DEB.2.22.394.2010270043510.102486@digraph.polyomino.org.uk
State New
Headers show
Series float.h: C2x NaN and Inf macros | expand

Commit Message

Joseph Myers Oct. 27, 2020, 12:44 a.m. UTC
C2x adds macros for NaNs and infinities to <float.h>, some of them
previously in <math.h> (and some still in <math.h> as well in C2x as
an obsolescent feature).  Add these macros to GCC's <float.h>
implementation.

This omits the macros for DFP signaling NaNs, leaving those to be
added in a separate patch which will also need to add corresponding
built-in functions (GCC doesn't currently have built-in functions for
DFP signaling NaNs, only quiet ones).  However, it includes the
_FloatN / _FloatNx macros (conditional on
__STDC_WANT_IEC_60559_TYPES_EXT__) in the current draft version of the
integration of TS 18661-3 into C2x as an Annex.

As GCC allows duplicate macro definitions with different expansions in
system headers, it should be OK if <math.h> defines INFINITY or NAN
with a slightly different expansion (e.g. different choice of whether
there is whitespace between tokens); tests are added including
<float.h> and <math.h> in either order.  Because <float.h> uses #undef
on all macros before defining them, even with -Wsystem-headers there
could only ever be issues when <math.h> is included after <float.h>.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.  OK to
commit?

gcc/
2020-10-27  Joseph Myers  <joseph@codesourcery.com>

	* ginclude/float.h (INFINITY, NAN, FLT_SNAN, DBL_SNAN, LDBL_SNAN)
	(FLT16_SNAN, FLT32_SNAN, FLT64_SNAN, FLT128_SNAN, FLT32X_SNAN)
	(FLT64X_SNAN, FLT128X_SNAN, DEC_INFINITY, DEC_NAN): New C2x
	macros.
	* doc/sourcebuild.texi (Effective-Target Keywords): Document inff.

gcc/testsuite/
2020-10-27  Joseph Myers  <joseph@codesourcery.com>

	* lib/target-supports.exp (check_effective_target_inff): New.
	* gcc.dg/c11-float-4.c, gcc.dg/c11-float-5.c,
	gcc.dg/c11-float-dfp-2.c, gcc.dg/c2x-float-2.c,
	gcc.dg/c2x-float-3.c, gcc.dg/c2x-float-4.c, gcc.dg/c2x-float-5.c,
	gcc.dg/c2x-float-6.c, gcc.dg/c2x-float-7.c, gcc.dg/c2x-float-8.c,
	gcc.dg/c2x-float-9.c, gcc.dg/c2x-float-no-dfp-3.c,
	gcc.dg/c2x-float-no-dfp-4.c, gcc.dg/dfp/c2x-float-dfp-4.c,
	gcc.dg/dfp/c2x-float-dfp-5.c, gcc.dg/dfp/c2x-float-dfp-6.c,
	gcc.dg/torture/float128-nan-floath.c,
	gcc.dg/torture/float128x-nan-floath.c,
	gcc.dg/torture/float16-nan-floath.c,
	gcc.dg/torture/float32-nan-floath.c,
	gcc.dg/torture/float32x-nan-floath.c,
	gcc.dg/torture/float64-nan-floath.c,
	gcc.dg/torture/float64x-nan-floath.c,
	gcc.dg/torture/floatn-nan-floath.h: New tests.

Comments

Joseph Myers Nov. 2, 2020, 4:12 p.m. UTC | #1
Ping.  This patch 
<https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557136.html> is 
pending review.
Joseph Myers Nov. 9, 2020, 3:48 p.m. UTC | #2
Ping^2.  This patch 
<https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557136.html> is 
still pending review (the DFP sNaN followup has been approved).
Joseph Myers Nov. 16, 2020, 4:09 p.m. UTC | #3
Ping^3.  This patch 
<https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557136.html> is 
still pending review (the DFP sNaN followup has been approved).  (The 
independent C2x <float.h> patches 
<https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559043.html> and 
<https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559077.html> are 
also pending review.)
Jeff Law Nov. 17, 2020, 12:22 a.m. UTC | #4
On 10/26/20 6:44 PM, Joseph Myers wrote:
> C2x adds macros for NaNs and infinities to <float.h>, some of them
> previously in <math.h> (and some still in <math.h> as well in C2x as
> an obsolescent feature).  Add these macros to GCC's <float.h>
> implementation.
>
> This omits the macros for DFP signaling NaNs, leaving those to be
> added in a separate patch which will also need to add corresponding
> built-in functions (GCC doesn't currently have built-in functions for
> DFP signaling NaNs, only quiet ones).  However, it includes the
> _FloatN / _FloatNx macros (conditional on
> __STDC_WANT_IEC_60559_TYPES_EXT__) in the current draft version of the
> integration of TS 18661-3 into C2x as an Annex.
>
> As GCC allows duplicate macro definitions with different expansions in
> system headers, it should be OK if <math.h> defines INFINITY or NAN
> with a slightly different expansion (e.g. different choice of whether
> there is whitespace between tokens); tests are added including
> <float.h> and <math.h> in either order.  Because <float.h> uses #undef
> on all macros before defining them, even with -Wsystem-headers there
> could only ever be issues when <math.h> is included after <float.h>.
>
> Bootstrapped with no regressions on x86_64-pc-linux-gnu.  OK to
> commit?
>
> gcc/
> 2020-10-27  Joseph Myers  <joseph@codesourcery.com>
>
> 	* ginclude/float.h (INFINITY, NAN, FLT_SNAN, DBL_SNAN, LDBL_SNAN)
> 	(FLT16_SNAN, FLT32_SNAN, FLT64_SNAN, FLT128_SNAN, FLT32X_SNAN)
> 	(FLT64X_SNAN, FLT128X_SNAN, DEC_INFINITY, DEC_NAN): New C2x
> 	macros.
> 	* doc/sourcebuild.texi (Effective-Target Keywords): Document inff.
>
> gcc/testsuite/
> 2020-10-27  Joseph Myers  <joseph@codesourcery.com>
>
> 	* lib/target-supports.exp (check_effective_target_inff): New.
> 	* gcc.dg/c11-float-4.c, gcc.dg/c11-float-5.c,
> 	gcc.dg/c11-float-dfp-2.c, gcc.dg/c2x-float-2.c,
> 	gcc.dg/c2x-float-3.c, gcc.dg/c2x-float-4.c, gcc.dg/c2x-float-5.c,
> 	gcc.dg/c2x-float-6.c, gcc.dg/c2x-float-7.c, gcc.dg/c2x-float-8.c,
> 	gcc.dg/c2x-float-9.c, gcc.dg/c2x-float-no-dfp-3.c,
> 	gcc.dg/c2x-float-no-dfp-4.c, gcc.dg/dfp/c2x-float-dfp-4.c,
> 	gcc.dg/dfp/c2x-float-dfp-5.c, gcc.dg/dfp/c2x-float-dfp-6.c,
> 	gcc.dg/torture/float128-nan-floath.c,
> 	gcc.dg/torture/float128x-nan-floath.c,
> 	gcc.dg/torture/float16-nan-floath.c,
> 	gcc.dg/torture/float32-nan-floath.c,
> 	gcc.dg/torture/float32x-nan-floath.c,
> 	gcc.dg/torture/float64-nan-floath.c,
> 	gcc.dg/torture/float64x-nan-floath.c,
> 	gcc.dg/torture/floatn-nan-floath.h: New tests.
>
> diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi

OK

Jeff
Richard Biener Nov. 17, 2020, 8:02 a.m. UTC | #5
On Mon, Nov 16, 2020 at 5:10 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> Ping^3.  This patch
> <https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557136.html> is
> still pending review (the DFP sNaN followup has been approved).  (The
> independent C2x <float.h> patches
> <https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559043.html> and
> <https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559077.html> are
> also pending review.)

These patches are all OK.

Thanks,
Richard.

>
> --
> Joseph S. Myers
> joseph@codesourcery.com
diff mbox series

Patch

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 49316a5d0ff..726f1c96dab 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1443,6 +1443,10 @@  Target has runtime support for any options added with
 @item inf
 Target supports floating point infinite (@code{inf}) for type
 @code{double}.
+
+@item inff
+Target supports floating point infinite (@code{inf}) for type
+@code{float}.
 @end table
 @subsubsection Fortran-specific attributes
 
diff --git a/gcc/ginclude/float.h b/gcc/ginclude/float.h
index 9c4b0385568..77446995515 100644
--- a/gcc/ginclude/float.h
+++ b/gcc/ginclude/float.h
@@ -248,6 +248,32 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define DBL_NORM_MAX	__DBL_NORM_MAX__
 #define LDBL_NORM_MAX	__LDBL_NORM_MAX__
 
+/* Infinity in type float, or overflow if infinity not supported.  */
+#undef INFINITY
+#define INFINITY	(__builtin_inff ())
+
+/* Quiet NaN, if supported for float.  */
+#if __FLT_HAS_QUIET_NAN__
+#undef NAN
+#define NAN		(__builtin_nanf (""))
+#endif
+
+/* Signaling NaN, if supported for each type.  All formats supported
+   by GCC support either both quiet and signaling NaNs, or neither
+   kind of NaN.  */
+#if __FLT_HAS_QUIET_NAN__
+#undef FLT_SNAN
+#define FLT_SNAN	(__builtin_nansf (""))
+#endif
+#if __DBL_HAS_QUIET_NAN__
+#undef DBL_SNAN
+#define DBL_SNAN	(__builtin_nans (""))
+#endif
+#if __LDBL_HAS_QUIET_NAN__
+#undef LDBL_SNAN
+#define LDBL_SNAN	(__builtin_nansl (""))
+#endif
+
 #endif /* C2X */
 
 #ifdef __STDC_WANT_IEC_60559_BFP_EXT__
@@ -284,6 +310,10 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define FLT16_DECIMAL_DIG	__FLT16_DECIMAL_DIG__
 #undef FLT16_TRUE_MIN
 #define FLT16_TRUE_MIN		__FLT16_DENORM_MIN__
+#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
+#undef FLT16_SNAN
+#define FLT16_SNAN	(__builtin_nansf16 (""))
+#endif /* C2X */
 #endif /* __FLT16_MANT_DIG__.  */
 
 #ifdef __FLT32_MANT_DIG__
@@ -309,6 +339,10 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define FLT32_DECIMAL_DIG	__FLT32_DECIMAL_DIG__
 #undef FLT32_TRUE_MIN
 #define FLT32_TRUE_MIN		__FLT32_DENORM_MIN__
+#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
+#undef FLT32_SNAN
+#define FLT32_SNAN	(__builtin_nansf32 (""))
+#endif /* C2X */
 #endif /* __FLT32_MANT_DIG__.  */
 
 #ifdef __FLT64_MANT_DIG__
@@ -334,6 +368,10 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define FLT64_DECIMAL_DIG	__FLT64_DECIMAL_DIG__
 #undef FLT64_TRUE_MIN
 #define FLT64_TRUE_MIN		__FLT64_DENORM_MIN__
+#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
+#undef FLT64_SNAN
+#define FLT64_SNAN	(__builtin_nansf64 (""))
+#endif /* C2X */
 #endif /* __FLT64_MANT_DIG__.  */
 
 #ifdef __FLT128_MANT_DIG__
@@ -359,6 +397,10 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define FLT128_DECIMAL_DIG	__FLT128_DECIMAL_DIG__
 #undef FLT128_TRUE_MIN
 #define FLT128_TRUE_MIN		__FLT128_DENORM_MIN__
+#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
+#undef FLT128_SNAN
+#define FLT128_SNAN	(__builtin_nansf128 (""))
+#endif /* C2X */
 #endif /* __FLT128_MANT_DIG__.  */
 
 #ifdef __FLT32X_MANT_DIG__
@@ -384,6 +426,10 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define FLT32X_DECIMAL_DIG	__FLT32X_DECIMAL_DIG__
 #undef FLT32X_TRUE_MIN
 #define FLT32X_TRUE_MIN		__FLT32X_DENORM_MIN__
+#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
+#undef FLT32X_SNAN
+#define FLT32X_SNAN	(__builtin_nansf32x (""))
+#endif /* C2X */
 #endif /* __FLT32X_MANT_DIG__.  */
 
 #ifdef __FLT64X_MANT_DIG__
@@ -409,6 +455,10 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define FLT64X_DECIMAL_DIG	__FLT64X_DECIMAL_DIG__
 #undef FLT64X_TRUE_MIN
 #define FLT64X_TRUE_MIN		__FLT64X_DENORM_MIN__
+#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
+#undef FLT64X_SNAN
+#define FLT64X_SNAN	(__builtin_nansf64x (""))
+#endif /* C2X */
 #endif /* __FLT64X_MANT_DIG__.  */
 
 #ifdef __FLT128X_MANT_DIG__
@@ -434,6 +484,10 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define FLT128X_DECIMAL_DIG	__FLT128X_DECIMAL_DIG__
 #undef FLT128X_TRUE_MIN
 #define FLT128X_TRUE_MIN	__FLT128X_DENORM_MIN__
+#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
+#undef FLT128X_SNAN
+#define FLT128X_SNAN	(__builtin_nansf128x (""))
+#endif /* C2X */
 #endif /* __FLT128X_MANT_DIG__.  */
 
 #endif /* __STDC_WANT_IEC_60559_TYPES_EXT__.  */
@@ -537,6 +591,18 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #endif /* __STDC_WANT_IEC_60559_DFP_EXT__ || C2X.  */
 
+#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
+
+/* Infinity in type _Decimal32.  */
+#undef DEC_INFINITY
+#define DEC_INFINITY	(__builtin_infd32 ())
+
+/* Quiet NaN in type _Decimal32.  */
+#undef DEC_NAN
+#define DEC_NAN		(__builtin_nand32 (""))
+
+#endif /* C2X */
+
 #endif /* __DEC32_MANT_DIG__ */
 
 #endif /* _FLOAT_H___ */
diff --git a/gcc/testsuite/gcc.dg/c11-float-4.c b/gcc/testsuite/gcc.dg/c11-float-4.c
new file mode 100644
index 00000000000..ceac6ef5063
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-float-4.c
@@ -0,0 +1,25 @@ 
+/* Test infinity and NaN macros not defined for C11.  */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+#include <float.h>
+
+#ifdef INFINITY
+#error "INFINITY defined"
+#endif
+
+#ifdef NAN
+#error "NAN defined"
+#endif
+
+#ifdef FLT_SNAN
+#error "FLT_SNAN defined"
+#endif
+
+#ifdef DBL_SNAN
+#error "DBL_SNAN defined"
+#endif
+
+#ifdef LDBL_SNAN
+#error "LDBL_SNAN defined"
+#endif
diff --git a/gcc/testsuite/gcc.dg/c11-float-5.c b/gcc/testsuite/gcc.dg/c11-float-5.c
new file mode 100644
index 00000000000..bb48695599b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-float-5.c
@@ -0,0 +1,35 @@ 
+/* Test sNaN macros for _FloatN and _FloatNx not defined for C11 with
+   __STDC_WANT_IEC_60559_TYPES_EXT__.  */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+#define __STDC_WANT_IEC_60559_TYPES_EXT__
+#include <float.h>
+
+#ifdef FLT16_SNAN
+#error "FLT16_SNAN defined"
+#endif
+
+#ifdef FLT32_SNAN
+#error "FLT32_SNAN defined"
+#endif
+
+#ifdef FLT64_SNAN
+#error "FLT64_SNAN defined"
+#endif
+
+#ifdef FLT128_SNAN
+#error "FLT128_SNAN defined"
+#endif
+
+#ifdef FLT32X_SNAN
+#error "FLT32X_SNAN defined"
+#endif
+
+#ifdef FLT64X_SNAN
+#error "FLT64X_SNAN defined"
+#endif
+
+#ifdef FLT128X_SNAN
+#error "FLT128X_SNAN defined"
+#endif
diff --git a/gcc/testsuite/gcc.dg/c11-float-dfp-2.c b/gcc/testsuite/gcc.dg/c11-float-dfp-2.c
new file mode 100644
index 00000000000..e63ebbcb0f2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-float-dfp-2.c
@@ -0,0 +1,6 @@ 
+/* Test DFP macros not defined in <float.h> for C11.  Infinity and NaN
+   macros.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c11" } */
+
+#include "c2x-float-no-dfp-3.c"
diff --git a/gcc/testsuite/gcc.dg/c2x-float-2.c b/gcc/testsuite/gcc.dg/c2x-float-2.c
new file mode 100644
index 00000000000..4f669fd39bc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-2.c
@@ -0,0 +1,23 @@ 
+/* Test INFINITY macro.  Generic test even if infinities not
+   supported.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -w" } */
+/* { dg-add-options ieee } */
+
+#include <float.h>
+
+#ifndef INFINITY
+#error "INFINITY undefined"
+#endif
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  (void) _Generic (INFINITY, float : 0);
+  if (!(INFINITY >= FLT_MAX))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-float-3.c b/gcc/testsuite/gcc.dg/c2x-float-3.c
new file mode 100644
index 00000000000..7c6298b8efb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-3.c
@@ -0,0 +1,27 @@ 
+/* Test INFINITY macro.  Test when infinities supported.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target inff } */
+
+#include <float.h>
+
+#ifndef INFINITY
+#error "INFINITY undefined"
+#endif
+
+volatile float f = INFINITY;
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  (void) _Generic (INFINITY, float : 0);
+  if (!(INFINITY > FLT_MAX))
+    abort ();
+  if (!(f > FLT_MAX))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-float-4.c b/gcc/testsuite/gcc.dg/c2x-float-4.c
new file mode 100644
index 00000000000..bca843547c5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-4.c
@@ -0,0 +1,33 @@ 
+/* Test NAN macro.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+/* { dg-add-options ieee } */
+
+#include <float.h>
+
+/* This should be defined if and only if quiet NaNs are supported for
+   type float.  If the testsuite gains effective-target support for
+   targets not supporting NaNs, or not supporting them for all types,
+   this test should be split into versions for targets with and
+   without NaNs for float.  */
+#ifndef NAN
+#error "NAN undefined"
+#endif
+
+volatile float f = NAN;
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  (void) _Generic (NAN, float : 0);
+  if (!__builtin_isnan (NAN))
+    abort ();
+  if (!__builtin_isnan (f))
+    abort ();
+  if (!__builtin_isnan (f + f))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-float-5.c b/gcc/testsuite/gcc.dg/c2x-float-5.c
new file mode 100644
index 00000000000..477f9cf09c6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-5.c
@@ -0,0 +1,32 @@ 
+/* Test NAN macro.  Runtime exceptions test, to verify NaN is quiet
+   not signaling.  */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv_exceptions } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+/* { dg-add-options ieee } */
+
+#include <fenv.h>
+#include <float.h>
+
+/* This should be defined if and only if quiet NaNs are supported for
+   type float.  If the testsuite gains effective-target support for
+   targets not supporting NaNs, or not supporting them for all types,
+   this test should only be run for targets supporting quiet NaNs for
+   float.  */
+#ifndef NAN
+#error "NAN undefined"
+#endif
+
+volatile float f = NAN;
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  f += f;
+  if (fetestexcept (FE_INVALID))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-float-6.c b/gcc/testsuite/gcc.dg/c2x-float-6.c
new file mode 100644
index 00000000000..573540b0381
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-6.c
@@ -0,0 +1,49 @@ 
+/* Test SNAN macros.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -pedantic-errors -fsignaling-nans" } */
+/* { dg-add-options ieee } */
+
+#include <float.h>
+
+/* These should be defined if and only if signaling NaNs are supported
+   for the given types.  If the testsuite gains effective-target
+   support for targets not supporting signaling NaNs, or not
+   supporting them for all types, this test should be made
+   appropriately conditional.  */
+#ifndef FLT_SNAN
+#error "FLT_SNAN undefined"
+#endif
+#ifndef DBL_SNAN
+#error "DBL_SNAN undefined"
+#endif
+#ifndef LDBL_SNAN
+#error "LDBL_SNAN undefined"
+#endif
+
+volatile float f = FLT_SNAN;
+volatile double d = DBL_SNAN;
+volatile long double ld = LDBL_SNAN;
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  (void) _Generic (FLT_SNAN, float : 0);
+  (void) _Generic (DBL_SNAN, double : 0);
+  (void) _Generic (LDBL_SNAN, long double : 0);
+  if (!__builtin_isnan (FLT_SNAN))
+    abort ();
+  if (!__builtin_isnan (f))
+    abort ();
+  if (!__builtin_isnan (DBL_SNAN))
+    abort ();
+  if (!__builtin_isnan (d))
+    abort ();
+  if (!__builtin_isnan (LDBL_SNAN))
+    abort ();
+  if (!__builtin_isnan (ld))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-float-7.c b/gcc/testsuite/gcc.dg/c2x-float-7.c
new file mode 100644
index 00000000000..0c90ff24165
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-7.c
@@ -0,0 +1,49 @@ 
+/* Test SNAN macros.  Runtime exceptions test, to verify NaN is
+   signaling.  */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv_exceptions } */
+/* { dg-options "-std=c2x -pedantic-errors -fsignaling-nans" } */
+/* { dg-add-options ieee } */
+
+#include <fenv.h>
+#include <float.h>
+
+/* These should be defined if and only if signaling NaNs are supported
+   for the given types.  If the testsuite gains effective-target
+   support for targets not supporting signaling NaNs, or not
+   supporting them for all types, this test should be made
+   appropriately conditional.  */
+#ifndef FLT_SNAN
+#error "FLT_SNAN undefined"
+#endif
+#ifndef DBL_SNAN
+#error "DBL_SNAN undefined"
+#endif
+#ifndef LDBL_SNAN
+#error "LDBL_SNAN undefined"
+#endif
+
+volatile float f = FLT_SNAN;
+volatile double d = DBL_SNAN;
+volatile long double ld = LDBL_SNAN;
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  feclearexcept (FE_ALL_EXCEPT);
+  f += f;
+  if (!fetestexcept (FE_INVALID))
+    abort ();
+  feclearexcept (FE_ALL_EXCEPT);
+  d += d;
+  if (!fetestexcept (FE_INVALID))
+    abort ();
+  feclearexcept (FE_ALL_EXCEPT);
+  ld += ld;
+  if (!fetestexcept (FE_INVALID))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-float-8.c b/gcc/testsuite/gcc.dg/c2x-float-8.c
new file mode 100644
index 00000000000..b10cb850091
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-8.c
@@ -0,0 +1,7 @@ 
+/* Test including <math.h> then <float.h> does not result in errors
+   from duplicate NAN and INFINITY macros.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+#include <math.h>
+#include <float.h>
diff --git a/gcc/testsuite/gcc.dg/c2x-float-9.c b/gcc/testsuite/gcc.dg/c2x-float-9.c
new file mode 100644
index 00000000000..0a54bc2ad4c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-9.c
@@ -0,0 +1,7 @@ 
+/* Test including <float.h> then <math.h> does not result in errors
+   from duplicate NAN and INFINITY macros.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+#include <float.h>
+#include <math.h>
diff --git a/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c
new file mode 100644
index 00000000000..d8a239c787e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c
@@ -0,0 +1,14 @@ 
+/* Test DFP macros not defined in <float.h> if no DFP support.
+   Infinity and NaN macros.  */
+/* { dg-do compile { target { ! dfp } } } */
+/* { dg-options "-std=c2x" } */
+
+#include <float.h>
+
+#ifdef DEC_INFINITY
+# error "DEC_INFINITY defined"
+#endif
+
+#ifdef DEC_NAN
+# error "DEC_NAN defined"
+#endif
diff --git a/gcc/testsuite/gcc.dg/c2x-float-no-dfp-4.c b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-4.c
new file mode 100644
index 00000000000..855922a47b6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-4.c
@@ -0,0 +1,10 @@ 
+/* Test DFP macros not defined in <float.h> if no DFP support.
+   Infinity and NaN macros.  Test with feature test macros
+   defined.  */
+/* { dg-do compile { target { ! dfp } } } */
+/* { dg-options "-std=c2x" } */
+
+#define __STDC_WANT_DEC_FP__
+#define __STDC_WANT_IEC_60559_DFP_EXT__
+
+#include "c2x-float-no-dfp-3.c"
diff --git a/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-4.c b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-4.c
new file mode 100644
index 00000000000..58ee74db484
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-4.c
@@ -0,0 +1,25 @@ 
+/* Test DEC_INFINITY defined in <float.h> with DFP support.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x" } */
+
+#include <float.h>
+
+#ifndef DEC_INFINITY
+# error "DEC_INFINITY not defined"
+#endif
+
+volatile _Decimal32 d = DEC_INFINITY;
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  (void) _Generic (DEC_INFINITY, _Decimal32 : 0);
+  if (!(DEC_INFINITY > DEC32_MAX))
+    abort ();
+  if (!(d > DEC32_MAX))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-5.c b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-5.c
new file mode 100644
index 00000000000..8d097255e0e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-5.c
@@ -0,0 +1,25 @@ 
+/* Test DEC_NAN defined in <float.h> with DFP support.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x" } */
+
+#include <float.h>
+
+#ifndef DEC_NAN
+# error "DEC_NAN not defined"
+#endif
+
+volatile _Decimal32 d = DEC_NAN;
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  (void) _Generic (DEC_NAN, _Decimal32 : 0);
+  if (!__builtin_isnan (DEC_NAN))
+    abort ();
+  if (!__builtin_isnan (d))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-6.c b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-6.c
new file mode 100644
index 00000000000..4533c61e8e9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-6.c
@@ -0,0 +1,28 @@ 
+/* Test DEC_NAN macro.  Runtime exceptions test, to verify NaN is
+   quiet not signaling.  (This would only actually fail for a
+   signaling NaN in the hardware DFP case, because the software DFP
+   support in libgcc does not integrate with hardware exceptions.)  */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv_exceptions } */
+/* { dg-options "-std=c2x" } */
+
+#include <fenv.h>
+#include <float.h>
+
+#ifndef DEC_NAN
+# error "DEC_NAN not defined"
+#endif
+
+volatile _Decimal32 d = DEC_NAN;
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  d += d;
+  if (fetestexcept (FE_INVALID))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/torture/float128-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float128-nan-floath.c
new file mode 100644
index 00000000000..69fd45a6375
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float128-nan-floath.c
@@ -0,0 +1,11 @@ 
+/* Test _Float128 NaNs in <float.h>.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -fsignaling-nans" } */
+/* { dg-add-options float128 } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target float128_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 128
+#define EXT 0
+#include "floatn-nan-floath.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float128x-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float128x-nan-floath.c
new file mode 100644
index 00000000000..5be4c07787d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float128x-nan-floath.c
@@ -0,0 +1,11 @@ 
+/* Test _Float128x NaNs in <float.h>.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -fsignaling-nans" } */
+/* { dg-add-options float128x } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target float128x_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 128
+#define EXT 1
+#include "floatn-nan-floath.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float16-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float16-nan-floath.c
new file mode 100644
index 00000000000..cf03b45a34b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float16-nan-floath.c
@@ -0,0 +1,11 @@ 
+/* Test _Float16 NaNs in <float.h>.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -fsignaling-nans" } */
+/* { dg-add-options float16 } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target float16_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 16
+#define EXT 0
+#include "floatn-nan-floath.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float32-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float32-nan-floath.c
new file mode 100644
index 00000000000..2976a40aec4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float32-nan-floath.c
@@ -0,0 +1,11 @@ 
+/* Test _Float32 NaNs in <float.h>.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -fsignaling-nans" } */
+/* { dg-add-options float32 } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target float32_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 32
+#define EXT 0
+#include "floatn-nan-floath.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float32x-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float32x-nan-floath.c
new file mode 100644
index 00000000000..0aab4be26ca
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float32x-nan-floath.c
@@ -0,0 +1,11 @@ 
+/* Test _Float32x NaNs in <float.h>.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -fsignaling-nans" } */
+/* { dg-add-options float32x } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target float32x_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 32
+#define EXT 1
+#include "floatn-nan-floath.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float64-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float64-nan-floath.c
new file mode 100644
index 00000000000..1f5298bd399
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float64-nan-floath.c
@@ -0,0 +1,11 @@ 
+/* Test _Float64 NaNs in <float.h>.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -fsignaling-nans" } */
+/* { dg-add-options float64 } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target float64_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 64
+#define EXT 0
+#include "floatn-nan-floath.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float64x-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float64x-nan-floath.c
new file mode 100644
index 00000000000..fbc86766d8e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float64x-nan-floath.c
@@ -0,0 +1,11 @@ 
+/* Test _Float64x NaNs in <float.h>.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -fsignaling-nans" } */
+/* { dg-add-options float64x } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target float64x_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 64
+#define EXT 1
+#include "floatn-nan-floath.h"
diff --git a/gcc/testsuite/gcc.dg/torture/floatn-nan-floath.h b/gcc/testsuite/gcc.dg/torture/floatn-nan-floath.h
new file mode 100644
index 00000000000..9892fd0cf63
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/floatn-nan-floath.h
@@ -0,0 +1,36 @@ 
+/* Tests for _FloatN / _FloatNx types: compile and execution tests for
+   NaNs, SNAN macros in <float.h>.  Before including this file, define
+   WIDTH as the value N; define EXT to 1 for _FloatNx and 0 for
+   _FloatN.  */
+
+#define CONCATX(X, Y) X ## Y
+#define CONCAT(X, Y) CONCATX (X, Y)
+#define CONCAT3(X, Y, Z) CONCAT (CONCAT (X, Y), Z)
+#define CONCAT4(W, X, Y, Z) CONCAT (CONCAT (CONCAT (W, X), Y), Z)
+
+#if EXT
+# define TYPE CONCAT3 (_Float, WIDTH, x)
+# define SNAN CONCAT3 (FLT, WIDTH, X_SNAN)
+#else
+# define TYPE CONCAT (_Float, WIDTH)
+# define SNAN CONCAT3 (FLT, WIDTH, _SNAN)
+#endif
+
+#define __STDC_WANT_IEC_60559_TYPES_EXT__
+#include <fenv.h>
+#include <float.h>
+
+extern void exit (int);
+extern void abort (void);
+
+volatile TYPE nans_cst = SNAN;
+
+int
+main (void)
+{
+  volatile TYPE r;
+  r = nans_cst + nans_cst;
+  if (!fetestexcept (FE_INVALID))
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 8439720baea..cbf618f7b37 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10301,6 +10301,13 @@  proc check_effective_target_inf { } {
     }]
 }
 
+# Return 1 if target supports floating point "infinite" for float.
+proc check_effective_target_inff { } {
+    return [check_no_compiler_messages supports_inff assembly {
+        const float pinf = __builtin_inff ();
+    }]
+}
+
 # Return 1 if the target supports ARMv8.3 Adv.SIMD Complex instructions
 # instructions, 0 otherwise.  The test is valid for ARM and for AArch64.
 # Record the command line options needed.