Restore DECIMAL_DIG macro to C99/C11 value.
authorJoseph Myers <joseph@codesourcery.com>
Fri, 17 Feb 2017 23:04:14 +0000 (23:04 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 17 Feb 2017 23:04:14 +0000 (23:04 +0000)
By extending the set of floating types, TS 18661-3 thereby affected
the definition of DECIMAL_DIG, which is defined in terms of the
"widest supported floating type".  This is not conditional on whether
__STDC_WANT_IEC_60559_TYPES_EXT__ is defined when <float.h> is
included.

I raised this possible incompatibility with C11 (an implementation
should be able to conform simultaneously with C11, and with C11 + TS
18661) in DR#501.  This is not yet resolved, but the latest proposal
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2108.pdf> would
obsolete DECIMAL_DIG with the intention of limiting it to the C11
types (so making it equivalent to LDBL_DECIMAL_DIG).  (This proposal
is intended to go along with a corresponding change to TS 18661-3 to
avoid the new types and non-arithmetic interchange encodings affecting
the value of DECIMAL_DIG.)

To avoid releasing GCC 7 with a wider-than-C11 value of DECIMAL_DIG
and possibly reverting back to a C11 value in a future release, this
patch reverts back to the C11 value now.  If the proposed resolution
to DR#501 changes again so that DECIMAL_DIG *should* have a
wider-than-C11 value, we can move back to a wider-than-C11 value in
GCC 8.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.

gcc/c-family:
* c-cppbuiltin.c (builtin_define_float_constants): Define
__DECIMAL_DIG__ to the value for long double.

gcc/testsuite:
* gcc.dg/c11-float-2.c: New test.
* gcc.dg/torture/float128-floath.c,
gcc.dg/torture/float128x-floath.c,
gcc.dg/torture/float16-floath.c, gcc.dg/torture/float32-floath.c,
gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float64-floath.c,
gcc.dg/torture/float64x-floath.c: Do not test comparison of
*_DECIMAL_DIG macros with DECIMAL_DIG.

From-SVN: r245555

gcc/c-family/ChangeLog
gcc/c-family/c-cppbuiltin.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c11-float-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float128-floath.c
gcc/testsuite/gcc.dg/torture/float128x-floath.c
gcc/testsuite/gcc.dg/torture/float16-floath.c
gcc/testsuite/gcc.dg/torture/float32-floath.c
gcc/testsuite/gcc.dg/torture/float32x-floath.c
gcc/testsuite/gcc.dg/torture/float64-floath.c
gcc/testsuite/gcc.dg/torture/float64x-floath.c

index 6256c4d7a8aa0a4c1d0beb865077063d43b88488..4bdd4747a89b7ec8da43a6de9db752bf2c6720e7 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-17  Joseph Myers  <joseph@codesourcery.com>
+
+       * c-cppbuiltin.c (builtin_define_float_constants): Define
+       __DECIMAL_DIG__ to the value for long double.
+
 2017-02-15  Marek Polacek  <polacek@redhat.com>
 
        PR c/79515
index c114bbd6d88614fd420ed07dcb56449d367d8cf8..083d5fdf4cfec15ab1b7aeb9a5787956c3a6f6f3 100644 (file)
@@ -245,11 +245,10 @@ builtin_define_float_constants (const char *name_prefix,
     if (type_decimal_dig < type_d_decimal_dig)
       type_decimal_dig++;
   }
-  /* Arbitrarily, define __DECIMAL_DIG__ when defining macros for long
-     double, although it may be greater than the value for long
-     double.  */
+  /* Define __DECIMAL_DIG__ to the value for long double to be
+     compatible with C99 and C11; see DR#501 and N2108.  */
   if (type == long_double_type_node)
-    builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig);
+    builtin_define_with_int_value ("__DECIMAL_DIG__", type_decimal_dig);
   sprintf (name, "__%s_DECIMAL_DIG__", name_prefix);
   builtin_define_with_int_value (name, type_decimal_dig);
 
index 5511f26b11563e34cc0e1c0a786816ccb9f51ec2..035cf4739c2cc400d18ddbd8e269e50e7256674e 100644 (file)
@@ -1,3 +1,13 @@
+2017-02-17  Joseph Myers  <joseph@codesourcery.com>
+
+       * gcc.dg/c11-float-2.c: New test.
+       * gcc.dg/torture/float128-floath.c,
+       gcc.dg/torture/float128x-floath.c,
+       gcc.dg/torture/float16-floath.c, gcc.dg/torture/float32-floath.c,
+       gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float64-floath.c,
+       gcc.dg/torture/float64x-floath.c: Do not test comparison of
+       *_DECIMAL_DIG macros with DECIMAL_DIG.
+
 2017-02-17  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        PR target/79261
diff --git a/gcc/testsuite/gcc.dg/c11-float-2.c b/gcc/testsuite/gcc.dg/c11-float-2.c
new file mode 100644 (file)
index 0000000..345c2d3
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test DECIMAL_DIG equals LDBL_DECIMAL_DIG; see DR#501 and N2108.  */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+#include <float.h>
+
+#if DECIMAL_DIG != LDBL_DECIMAL_DIG
+# error "DECIMAL_DIG != LDBL_DECIMAL_DIG"
+#endif
index 7b5b046e79f1029a5849eebbd8547b8fbff2ff9c..6015903381db2b9a041c103042518cb4eac8c30f 100644 (file)
 # error "FLT128_TRUE_MIN undefined"
 #endif
 
-#if FLT128_DECIMAL_DIG > DECIMAL_DIG
-# error "FLT128_DECIMAL_DIG > DECIMAL_DIG"
-#endif
-
 #if FLT128_MANT_DIG != 113 || FLT128_MAX_EXP != 16384 || FLT128_MIN_EXP != -16381
 # error "_Float128 bad format"
 #endif
index 3ac96ce3177fd68bbc3dfcba03ec7e1c19a480b8..5c0d94f0600f955c080c212d49b270b0b1a7285b 100644 (file)
 # error "FLT128X_TRUE_MIN undefined"
 #endif
 
-#if FLT128X_DECIMAL_DIG > DECIMAL_DIG
-# error "FLT128X_DECIMAL_DIG > DECIMAL_DIG"
-#endif
-
 #if FLT128X_MANT_DIG < 128 || FLT128X_MAX_EXP < 65536 || FLT128X_MIN_EXP + FLT128X_MAX_EXP != 3
 # error "_Float128x bad format"
 #endif
index 3748f4197dfb5658f8cbc89704db39a08eee4647..91c84e7a55136eeb0316f3d552e37ca9e12719b8 100644 (file)
 # error "FLT16_TRUE_MIN undefined"
 #endif
 
-#if FLT16_DECIMAL_DIG > DECIMAL_DIG
-# error "FLT16_DECIMAL_DIG > DECIMAL_DIG"
-#endif
-
 #if FLT16_MANT_DIG != 11 || FLT16_MAX_EXP != 16 || FLT16_MIN_EXP != -13
 # error "_Float16 bad format"
 #endif
index dd503bef51ff7f1460b7e4c84136110ef877db0a..cada00af1794054f338cabe4881a6485cebe93ca 100644 (file)
 # error "FLT32_TRUE_MIN undefined"
 #endif
 
-#if FLT32_DECIMAL_DIG > DECIMAL_DIG
-# error "FLT32_DECIMAL_DIG > DECIMAL_DIG"
-#endif
-
 #if FLT32_MANT_DIG != 24 || FLT32_MAX_EXP != 128 || FLT32_MIN_EXP != -125
 # error "_Float32 bad format"
 #endif
index ef2005ca74cf879012effb210656cea1976bab6f..6baabf3d0d27c75d9a44ddab2a9c3e9ef412694e 100644 (file)
 # error "FLT32X_TRUE_MIN undefined"
 #endif
 
-#if FLT32X_DECIMAL_DIG > DECIMAL_DIG
-# error "FLT32X_DECIMAL_DIG > DECIMAL_DIG"
-#endif
-
 #if FLT32X_MANT_DIG < 32 || FLT32X_MAX_EXP < 1024 || FLT32X_MIN_EXP + FLT32X_MAX_EXP != 3
 # error "_Float32x bad format"
 #endif
index 3fb443b3726cc5a6a1b228aa1f0f525197367ce0..f10e58e26ca58b1aa8f00184553f0ea9f1ca55c0 100644 (file)
 # error "FLT64_TRUE_MIN undefined"
 #endif
 
-#if FLT64_DECIMAL_DIG > DECIMAL_DIG
-# error "FLT64_DECIMAL_DIG > DECIMAL_DIG"
-#endif
-
 #if FLT64_MANT_DIG != 53 || FLT64_MAX_EXP != 1024 || FLT64_MIN_EXP != -1021
 # error "_Float64 bad format"
 #endif
index 7fce730f3868e5a94507c7139534dcc7ae61b59d..00c36f4dbfd4f51fe10bc2f46015e3bce3d2a54b 100644 (file)
 # error "FLT64X_TRUE_MIN undefined"
 #endif
 
-#if FLT64X_DECIMAL_DIG > DECIMAL_DIG
-# error "FLT64X_DECIMAL_DIG > DECIMAL_DIG"
-#endif
-
 #if FLT64X_MANT_DIG < 64 || FLT64X_MAX_EXP < 16384 || FLT64X_MIN_EXP + FLT64X_MAX_EXP != 3
 # error "_Float64x bad format"
 #endif