]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
float.h: Do not define INFINITY for C2x when infinities not supported
authorJoseph Myers <joseph@codesourcery.com>
Thu, 15 Sep 2022 20:10:42 +0000 (20:10 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Thu, 15 Sep 2022 20:10:42 +0000 (20:10 +0000)
C2x has changed the rules for defining INFINITY in <float.h> so it is
no longer defined when float does not support infinities, instead of
being defined to an expression that overflows at translation time.
Thus, make the definition conditional on __FLT_HAS_INFINITY__ (this is
already inside a C2x-conditional part of <float.h>, because previous C
standard versions only had this macro in <math.h>).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.  Also did a
spot test of the case of no infinities supported by building cc1 for
vax-netbsdelf and testing compiling the new c2x-float-11.c test with
it.

gcc/
* ginclude/float.h (INFINITY): Define only if
[__FLT_HAS_INFINITY__].

gcc/testsuite/
* gcc.dg/c2x-float-2.c: Require inff effective-target.
* gcc.dg/c2x-float-11.c: New test.

gcc/ginclude/float.h
gcc/testsuite/gcc.dg/c2x-float-11.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-float-2.c

index 9d368c4afa57fb6ec43df0dedff13ddebc4a4f09..afe4a712878cfbe661f41e6e855e7af45af2bb75 100644 (file)
@@ -257,9 +257,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define DBL_IS_IEC_60559       __DBL_IS_IEC_60559__
 #define LDBL_IS_IEC_60559      __LDBL_IS_IEC_60559__
 
-/* Infinity in type float, or overflow if infinity not supported.  */
+/* Infinity in type float; not defined if infinity not supported.  */
+#if __FLT_HAS_INFINITY__
 #undef INFINITY
 #define INFINITY       (__builtin_inff ())
+#endif
 
 /* Quiet NaN, if supported for float.  */
 #if __FLT_HAS_QUIET_NAN__
diff --git a/gcc/testsuite/gcc.dg/c2x-float-11.c b/gcc/testsuite/gcc.dg/c2x-float-11.c
new file mode 100644 (file)
index 0000000..0e2f3c0
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test INFINITY macro.  Test when infinities not supported.  */
+/* { dg-do compile { target { ! inff } } } */
+/* { dg-options "-std=c2x" } */
+
+#include <float.h>
+
+#ifdef INFINITY
+#error "INFINITY defined"
+#endif
index 4f669fd39bccf3cd45f1ef825abd6f5d19001755..61a77f6f2db71cbe6b0fd806e1e7e55b49045207 100644 (file)
@@ -1,8 +1,8 @@
-/* Test INFINITY macro.  Generic test even if infinities not
-   supported.  */
+/* Test INFINITY macro.  Generic test.  */
 /* { dg-do run } */
 /* { dg-options "-std=c2x -w" } */
 /* { dg-add-options ieee } */
+/* { dg-require-effective-target inff } */
 
 #include <float.h>