From 202be58655a1964581facd2e514c7d3431258fe8 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 3 Oct 2019 00:50:58 +0100 Subject: [PATCH] Define WIDTH macros for C2x. As part of the integration of TS 18661-1 into C2x, many features became unconditional features not depending on any feature test macro being defined. This patch updates the conditionals on the *_WIDTH macros in limits.h and stdint.h accordingly so that they are defined for C2x. The macro CR_DECIMAL_DIG in float.h does still require __STDC_WANT_IEC_60559_BFP_EXT__ to be defined, and a test for this is added. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc: * ginclude/stdint-gcc.h [__STDC_WANT_IEC_60559_BFP_EXT__]: Change condition on WIDTH macros to [__STDC_WANT_IEC_60559_BFP_EXT__ || (__STDC_VERSION__ && __STDC_VERSION__ > 201710L)]. * glimits.h: Likewise. gcc/testsuite: * gcc.dg/cr-decimal-dig-2.c: New test. * gcc.dg/limits-width-2.c: New test. Based on limits-width-1.c. * gcc.dg/stdint-width-2.c: New test. Based on stdint-width-1.c. From-SVN: r276497 --- gcc/ChangeLog | 7 + gcc/ginclude/stdint-gcc.h | 5 +- gcc/glimits.h | 5 +- gcc/testsuite/ChangeLog | 6 + gcc/testsuite/gcc.dg/cr-decimal-dig-2.c | 10 ++ gcc/testsuite/gcc.dg/limits-width-2.c | 54 ++++++++ gcc/testsuite/gcc.dg/stdint-width-2.c | 175 ++++++++++++++++++++++++ 7 files changed, 258 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cr-decimal-dig-2.c create mode 100644 gcc/testsuite/gcc.dg/limits-width-2.c create mode 100644 gcc/testsuite/gcc.dg/stdint-width-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6aff2cd4371..26c5c427b94 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-10-02 Joseph Myers + + * ginclude/stdint-gcc.h [__STDC_WANT_IEC_60559_BFP_EXT__]: Change + condition on WIDTH macros to [__STDC_WANT_IEC_60559_BFP_EXT__ || + (__STDC_VERSION__ && __STDC_VERSION__ > 201710L)]. + * glimits.h: Likewise. + 2019-10-03 Jakub Jelinek PR rtl-optimization/91976 diff --git a/gcc/ginclude/stdint-gcc.h b/gcc/ginclude/stdint-gcc.h index 83b03b26ee6..e9dc04e71e4 100644 --- a/gcc/ginclude/stdint-gcc.h +++ b/gcc/ginclude/stdint-gcc.h @@ -260,8 +260,9 @@ typedef __UINTMAX_TYPE__ uintmax_t; #endif /* (!defined __cplusplus || __cplusplus >= 201103L || defined __STDC_CONSTANT_MACROS) */ -#ifdef __STDC_WANT_IEC_60559_BFP_EXT__ -/* TS 18661-1 widths of integer types. */ +#if (defined __STDC_WANT_IEC_60559_BFP_EXT__ \ + || (defined (__STDC_VERSION__) && __STDC_VERSION__ > 201710L)) +/* TS 18661-1 / C2X widths of integer types. */ #ifdef __INT8_TYPE__ # undef INT8_WIDTH diff --git a/gcc/glimits.h b/gcc/glimits.h index 0cddf0f9dcc..1909344293d 100644 --- a/gcc/glimits.h +++ b/gcc/glimits.h @@ -123,8 +123,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see # define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1ULL) #endif -#ifdef __STDC_WANT_IEC_60559_BFP_EXT__ -/* TS 18661-1 widths of integer types. */ +#if (defined __STDC_WANT_IEC_60559_BFP_EXT__ \ + || (defined (__STDC_VERSION__) && __STDC_VERSION__ > 201710L)) +/* TS 18661-1 / C2X widths of integer types. */ # undef CHAR_WIDTH # define CHAR_WIDTH __SCHAR_WIDTH__ # undef SCHAR_WIDTH diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 27659f4bb4e..e57cc72b894 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-10-02 Joseph Myers + + * gcc.dg/cr-decimal-dig-2.c: New test. + * gcc.dg/limits-width-2.c: New test. Based on limits-width-1.c. + * gcc.dg/stdint-width-2.c: New test. Based on stdint-width-1.c. + 2019-10-03 Paolo Carlini * g++.dg/diagnostic/integral-array-size-1.C: New. diff --git a/gcc/testsuite/gcc.dg/cr-decimal-dig-2.c b/gcc/testsuite/gcc.dg/cr-decimal-dig-2.c new file mode 100644 index 00000000000..42e79d545cd --- /dev/null +++ b/gcc/testsuite/gcc.dg/cr-decimal-dig-2.c @@ -0,0 +1,10 @@ +/* Test TS 18661-1 CR_DECIMAL_DIG: not in C2X without + __STDC_WANT_IEC_60559_BFP_EXT__ defined. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x" } */ + +#include + +#ifdef CR_DECIMAL_DIG +#error "CR_DECIMAL_DIG defined" +#endif diff --git a/gcc/testsuite/gcc.dg/limits-width-2.c b/gcc/testsuite/gcc.dg/limits-width-2.c new file mode 100644 index 00000000000..a3c38958ae4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/limits-width-2.c @@ -0,0 +1,54 @@ +/* Test C2X width macros in . */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x" } */ + +#include + +#define CHECK_WIDTH(TYPE, MAX, WIDTH) \ + _Static_assert ((MAX >> ((TYPE) -1 < 0 ? (WIDTH - 2) : (WIDTH - 1))) == 1, \ + "width must match type") + +#ifndef CHAR_WIDTH +# error "missing CHAR_WIDTH" +#endif +CHECK_WIDTH (char, CHAR_MAX, CHAR_WIDTH); +#ifndef SCHAR_WIDTH +# error "missing SCHAR_WIDTH" +#endif +CHECK_WIDTH (signed char, SCHAR_MAX, SCHAR_WIDTH); +#ifndef UCHAR_WIDTH +# error "missing UCHAR_WIDTH" +#endif +CHECK_WIDTH (unsigned char, UCHAR_MAX, UCHAR_WIDTH); +#ifndef SHRT_WIDTH +# error "missing SHRT_WIDTH" +#endif +CHECK_WIDTH (signed short, SHRT_MAX, SHRT_WIDTH); +#ifndef USHRT_WIDTH +# error "missing USHRT_WIDTH" +#endif +CHECK_WIDTH (unsigned short, USHRT_MAX, USHRT_WIDTH); +#ifndef INT_WIDTH +# error "missing INT_WIDTH" +#endif +CHECK_WIDTH (signed int, INT_MAX, INT_WIDTH); +#ifndef UINT_WIDTH +# error "missing UINT_WIDTH" +#endif +CHECK_WIDTH (unsigned int, UINT_MAX, UINT_WIDTH); +#ifndef LONG_WIDTH +# error "missing LONG_WIDTH" +#endif +CHECK_WIDTH (signed long, LONG_MAX, LONG_WIDTH); +#ifndef ULONG_WIDTH +# error "missing ULONG_WIDTH" +#endif +CHECK_WIDTH (unsigned long, ULONG_MAX, ULONG_WIDTH); +#ifndef LLONG_WIDTH +# error "missing LLONG_WIDTH" +#endif +CHECK_WIDTH (signed long long, LLONG_MAX, LLONG_WIDTH); +#ifndef ULLONG_WIDTH +# error "missing ULLONG_WIDTH" +#endif +CHECK_WIDTH (unsigned long long, ULLONG_MAX, ULLONG_WIDTH); diff --git a/gcc/testsuite/gcc.dg/stdint-width-2.c b/gcc/testsuite/gcc.dg/stdint-width-2.c new file mode 100644 index 00000000000..9838cb27612 --- /dev/null +++ b/gcc/testsuite/gcc.dg/stdint-width-2.c @@ -0,0 +1,175 @@ +/* Test C2X width macros in . */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -ffreestanding" } */ +/* { dg-additional-options "-DSIGNAL_SUPPRESS" { target { ! signal } } } */ + +#include +#include +#ifndef SIGNAL_SUPPRESS +#include +#endif +typedef __WINT_TYPE__ wint_t; + +#define CHECK_WIDTH(TYPE, MAX, WIDTH) \ + _Static_assert ((MAX >> ((TYPE) -1 < 0 ? (WIDTH - 2) : (WIDTH - 1))) == 1, \ + "width must match type") + +#ifdef INT8_MAX +# ifndef INT8_WIDTH +# error "missing INT8_WIDTH" +# endif +CHECK_WIDTH (int8_t, INT8_MAX, INT8_WIDTH); +#endif +#ifdef INT16_MAX +# ifndef INT16_WIDTH +# error "missing INT16_WIDTH" +# endif +CHECK_WIDTH (int16_t, INT16_MAX, INT16_WIDTH); +#endif +#ifdef INT32_MAX +# ifndef INT32_WIDTH +# error "missing INT32_WIDTH" +# endif +CHECK_WIDTH (int32_t, INT32_MAX, INT32_WIDTH); +#endif +#ifdef INT64_MAX +# ifndef INT64_WIDTH +# error "missing INT64_WIDTH" +# endif +CHECK_WIDTH (int64_t, INT64_MAX, INT64_WIDTH); +#endif +#ifdef UINT8_MAX +# ifndef UINT8_WIDTH +# error "missing UINT8_WIDTH" +# endif +CHECK_WIDTH (uint8_t, UINT8_MAX, UINT8_WIDTH); +#endif +#ifdef UINT16_MAX +# ifndef UINT16_WIDTH +# error "missing UINT16_WIDTH" +# endif +CHECK_WIDTH (uint16_t, UINT16_MAX, UINT16_WIDTH); +#endif +#ifdef UINT32_MAX +# ifndef UINT32_WIDTH +# error "missing UINT32_WIDTH" +# endif +CHECK_WIDTH (uint32_t, UINT32_MAX, UINT32_WIDTH); +#endif +#ifdef UINT64_MAX +# ifndef UINT64_WIDTH +# error "missing UINT64_WIDTH" +# endif +CHECK_WIDTH (uint64_t, UINT64_MAX, UINT64_WIDTH); +#endif + +#ifndef INT_LEAST8_WIDTH +# error "missing INT_LEAST8_WIDTH" +#endif +CHECK_WIDTH (int_least8_t, INT_LEAST8_MAX, INT_LEAST8_WIDTH); +#ifndef INT_LEAST16_WIDTH +# error "missing INT_LEAST16_WIDTH" +#endif +CHECK_WIDTH (int_least16_t, INT_LEAST16_MAX, INT_LEAST16_WIDTH); +#ifndef INT_LEAST32_WIDTH +# error "missing INT_LEAST32_WIDTH" +#endif +CHECK_WIDTH (int_least32_t, INT_LEAST32_MAX, INT_LEAST32_WIDTH); +#ifndef INT_LEAST64_WIDTH +# error "missing INT_LEAST64_WIDTH" +#endif +CHECK_WIDTH (int_least64_t, INT_LEAST64_MAX, INT_LEAST64_WIDTH); +#ifndef INT_LEAST8_WIDTH +# error "missing INT_LEAST8_WIDTH" +#endif +CHECK_WIDTH (uint_least8_t, UINT_LEAST8_MAX, UINT_LEAST8_WIDTH); +#ifndef UINT_LEAST16_WIDTH +# error "missing UINT_LEAST16_WIDTH" +#endif +CHECK_WIDTH (uint_least16_t, UINT_LEAST16_MAX, UINT_LEAST16_WIDTH); +#ifndef UINT_LEAST32_WIDTH +# error "missing UINT_LEAST32_WIDTH" +#endif +CHECK_WIDTH (uint_least32_t, UINT_LEAST32_MAX, UINT_LEAST32_WIDTH); +#ifndef UINT_LEAST64_WIDTH +# error "missing UINT_LEAST64_WIDTH" +#endif +CHECK_WIDTH (uint_least64_t, UINT_LEAST64_MAX, UINT_LEAST64_WIDTH); + +#ifndef INT_FAST8_WIDTH +# error "missing INT_FAST8_WIDTH" +#endif +CHECK_WIDTH (int_fast8_t, INT_FAST8_MAX, INT_FAST8_WIDTH); +#ifndef INT_FAST16_WIDTH +# error "missing INT_FAST16_WIDTH" +#endif +CHECK_WIDTH (int_fast16_t, INT_FAST16_MAX, INT_FAST16_WIDTH); +#ifndef INT_FAST32_WIDTH +# error "missing INT_FAST32_WIDTH" +#endif +CHECK_WIDTH (int_fast32_t, INT_FAST32_MAX, INT_FAST32_WIDTH); +#ifndef INT_FAST64_WIDTH +# error "missing INT_FAST64_WIDTH" +#endif +CHECK_WIDTH (int_fast64_t, INT_FAST64_MAX, INT_FAST64_WIDTH); +#ifndef INT_FAST8_WIDTH +# error "missing INT_FAST8_WIDTH" +#endif +CHECK_WIDTH (uint_fast8_t, UINT_FAST8_MAX, UINT_FAST8_WIDTH); +#ifndef UINT_FAST16_WIDTH +# error "missing UINT_FAST16_WIDTH" +#endif +CHECK_WIDTH (uint_fast16_t, UINT_FAST16_MAX, UINT_FAST16_WIDTH); +#ifndef UINT_FAST32_WIDTH +# error "missing UINT_FAST32_WIDTH" +#endif +CHECK_WIDTH (uint_fast32_t, UINT_FAST32_MAX, UINT_FAST32_WIDTH); +#ifndef UINT_FAST64_WIDTH +# error "missing UINT_FAST64_WIDTH" +#endif +CHECK_WIDTH (uint_fast64_t, UINT_FAST64_MAX, UINT_FAST64_WIDTH); + +#ifdef INTPTR_MAX +# ifndef INTPTR_WIDTH +# error "missing INTPTR_WIDTH" +# endif +CHECK_WIDTH (intptr_t, INTPTR_MAX, INTPTR_WIDTH); +#endif +#ifdef UINTPTR_MAX +# ifndef UINTPTR_WIDTH +# error "missing UINTPTR_WIDTH" +# endif +CHECK_WIDTH (uintptr_t, UINTPTR_MAX, UINTPTR_WIDTH); +#endif + +#ifndef INTMAX_WIDTH +# error "missing INTMAX_WIDTH" +#endif +CHECK_WIDTH (intmax_t, INTMAX_MAX, INTMAX_WIDTH); +#ifndef UINTMAX_WIDTH +# error "missing UINTMAX_WIDTH" +#endif +CHECK_WIDTH (uintmax_t, UINTMAX_MAX, UINTMAX_WIDTH); + +#ifndef PTRDIFF_WIDTH +# error "missing PTRDIFF_WIDTH" +#endif +CHECK_WIDTH (ptrdiff_t, PTRDIFF_MAX, PTRDIFF_WIDTH); +#ifndef SIGNAL_SUPPRESS +# ifndef SIG_ATOMIC_WIDTH +# error "missing SIG_ATOMIC_WIDTH" +# endif +CHECK_WIDTH (sig_atomic_t, SIG_ATOMIC_MAX, SIG_ATOMIC_WIDTH); +#endif +#ifndef SIZE_WIDTH +# error "missing SIZE_WIDTH" +#endif +CHECK_WIDTH (size_t, SIZE_MAX, SIZE_WIDTH); +#ifndef WCHAR_WIDTH +# error "missing WCHAR_WIDTH" +#endif +CHECK_WIDTH (wchar_t, WCHAR_MAX, WCHAR_WIDTH); +#ifndef WINT_WIDTH +# error "missing WINT_WIDTH" +#endif +CHECK_WIDTH (wint_t, WINT_MAX, WINT_WIDTH); -- 2.30.2