(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
stdint-width-1.c
       1  /* Test TS 18661-1 width macros in <stdint.h>.  */
       2  /* { dg-do compile } */
       3  /* { dg-options "-std=c11 -ffreestanding" } */
       4  /* { dg-additional-options "-DSIGNAL_SUPPRESS" { target { ! signal } } } */
       5  
       6  #include <stddef.h>
       7  #define __STDC_WANT_IEC_60559_BFP_EXT__
       8  #include <stdint.h>
       9  #ifndef SIGNAL_SUPPRESS
      10  #include <signal.h>
      11  #endif
      12  typedef __WINT_TYPE__ wint_t;
      13  
      14  #define CHECK_WIDTH(TYPE, MAX, WIDTH)					\
      15    _Static_assert ((MAX >> ((TYPE) -1 < 0 ? (WIDTH - 2) : (WIDTH - 1))) == 1, \
      16  		  "width must match type")
      17  
      18  #ifdef INT8_MAX
      19  # ifndef INT8_WIDTH
      20  #  error "missing INT8_WIDTH"
      21  # endif
      22  CHECK_WIDTH (int8_t, INT8_MAX, INT8_WIDTH);
      23  #endif
      24  #ifdef INT16_MAX
      25  # ifndef INT16_WIDTH
      26  #  error "missing INT16_WIDTH"
      27  # endif
      28  CHECK_WIDTH (int16_t, INT16_MAX, INT16_WIDTH);
      29  #endif
      30  #ifdef INT32_MAX
      31  # ifndef INT32_WIDTH
      32  #  error "missing INT32_WIDTH"
      33  # endif
      34  CHECK_WIDTH (int32_t, INT32_MAX, INT32_WIDTH);
      35  #endif
      36  #ifdef INT64_MAX
      37  # ifndef INT64_WIDTH
      38  #  error "missing INT64_WIDTH"
      39  # endif
      40  CHECK_WIDTH (int64_t, INT64_MAX, INT64_WIDTH);
      41  #endif
      42  #ifdef UINT8_MAX
      43  # ifndef UINT8_WIDTH
      44  #  error "missing UINT8_WIDTH"
      45  # endif
      46  CHECK_WIDTH (uint8_t, UINT8_MAX, UINT8_WIDTH);
      47  #endif
      48  #ifdef UINT16_MAX
      49  # ifndef UINT16_WIDTH
      50  #  error "missing UINT16_WIDTH"
      51  # endif
      52  CHECK_WIDTH (uint16_t, UINT16_MAX, UINT16_WIDTH);
      53  #endif
      54  #ifdef UINT32_MAX
      55  # ifndef UINT32_WIDTH
      56  #  error "missing UINT32_WIDTH"
      57  # endif
      58  CHECK_WIDTH (uint32_t, UINT32_MAX, UINT32_WIDTH);
      59  #endif
      60  #ifdef UINT64_MAX
      61  # ifndef UINT64_WIDTH
      62  #  error "missing UINT64_WIDTH"
      63  # endif
      64  CHECK_WIDTH (uint64_t, UINT64_MAX, UINT64_WIDTH);
      65  #endif
      66  
      67  #ifndef INT_LEAST8_WIDTH
      68  # error "missing INT_LEAST8_WIDTH"
      69  #endif
      70  CHECK_WIDTH (int_least8_t, INT_LEAST8_MAX, INT_LEAST8_WIDTH);
      71  #ifndef INT_LEAST16_WIDTH
      72  # error "missing INT_LEAST16_WIDTH"
      73  #endif
      74  CHECK_WIDTH (int_least16_t, INT_LEAST16_MAX, INT_LEAST16_WIDTH);
      75  #ifndef INT_LEAST32_WIDTH
      76  # error "missing INT_LEAST32_WIDTH"
      77  #endif
      78  CHECK_WIDTH (int_least32_t, INT_LEAST32_MAX, INT_LEAST32_WIDTH);
      79  #ifndef INT_LEAST64_WIDTH
      80  # error "missing INT_LEAST64_WIDTH"
      81  #endif
      82  CHECK_WIDTH (int_least64_t, INT_LEAST64_MAX, INT_LEAST64_WIDTH);
      83  #ifndef INT_LEAST8_WIDTH
      84  # error "missing INT_LEAST8_WIDTH"
      85  #endif
      86  CHECK_WIDTH (uint_least8_t, UINT_LEAST8_MAX, UINT_LEAST8_WIDTH);
      87  #ifndef UINT_LEAST16_WIDTH
      88  # error "missing UINT_LEAST16_WIDTH"
      89  #endif
      90  CHECK_WIDTH (uint_least16_t, UINT_LEAST16_MAX, UINT_LEAST16_WIDTH);
      91  #ifndef UINT_LEAST32_WIDTH
      92  # error "missing UINT_LEAST32_WIDTH"
      93  #endif
      94  CHECK_WIDTH (uint_least32_t, UINT_LEAST32_MAX, UINT_LEAST32_WIDTH);
      95  #ifndef UINT_LEAST64_WIDTH
      96  # error "missing UINT_LEAST64_WIDTH"
      97  #endif
      98  CHECK_WIDTH (uint_least64_t, UINT_LEAST64_MAX, UINT_LEAST64_WIDTH);
      99  
     100  #ifndef INT_FAST8_WIDTH
     101  # error "missing INT_FAST8_WIDTH"
     102  #endif
     103  CHECK_WIDTH (int_fast8_t, INT_FAST8_MAX, INT_FAST8_WIDTH);
     104  #ifndef INT_FAST16_WIDTH
     105  # error "missing INT_FAST16_WIDTH"
     106  #endif
     107  CHECK_WIDTH (int_fast16_t, INT_FAST16_MAX, INT_FAST16_WIDTH);
     108  #ifndef INT_FAST32_WIDTH
     109  # error "missing INT_FAST32_WIDTH"
     110  #endif
     111  CHECK_WIDTH (int_fast32_t, INT_FAST32_MAX, INT_FAST32_WIDTH);
     112  #ifndef INT_FAST64_WIDTH
     113  # error "missing INT_FAST64_WIDTH"
     114  #endif
     115  CHECK_WIDTH (int_fast64_t, INT_FAST64_MAX, INT_FAST64_WIDTH);
     116  #ifndef INT_FAST8_WIDTH
     117  # error "missing INT_FAST8_WIDTH"
     118  #endif
     119  CHECK_WIDTH (uint_fast8_t, UINT_FAST8_MAX, UINT_FAST8_WIDTH);
     120  #ifndef UINT_FAST16_WIDTH
     121  # error "missing UINT_FAST16_WIDTH"
     122  #endif
     123  CHECK_WIDTH (uint_fast16_t, UINT_FAST16_MAX, UINT_FAST16_WIDTH);
     124  #ifndef UINT_FAST32_WIDTH
     125  # error "missing UINT_FAST32_WIDTH"
     126  #endif
     127  CHECK_WIDTH (uint_fast32_t, UINT_FAST32_MAX, UINT_FAST32_WIDTH);
     128  #ifndef UINT_FAST64_WIDTH
     129  # error "missing UINT_FAST64_WIDTH"
     130  #endif
     131  CHECK_WIDTH (uint_fast64_t, UINT_FAST64_MAX, UINT_FAST64_WIDTH);
     132  
     133  #ifdef INTPTR_MAX
     134  # ifndef INTPTR_WIDTH
     135  #  error "missing INTPTR_WIDTH"
     136  # endif
     137  CHECK_WIDTH (intptr_t, INTPTR_MAX, INTPTR_WIDTH);
     138  #endif
     139  #ifdef UINTPTR_MAX
     140  # ifndef UINTPTR_WIDTH
     141  #  error "missing UINTPTR_WIDTH"
     142  # endif
     143  CHECK_WIDTH (uintptr_t, UINTPTR_MAX, UINTPTR_WIDTH);
     144  #endif
     145  
     146  #ifndef INTMAX_WIDTH
     147  # error "missing INTMAX_WIDTH"
     148  #endif
     149  CHECK_WIDTH (intmax_t, INTMAX_MAX, INTMAX_WIDTH);
     150  #ifndef UINTMAX_WIDTH
     151  # error "missing UINTMAX_WIDTH"
     152  #endif
     153  CHECK_WIDTH (uintmax_t, UINTMAX_MAX, UINTMAX_WIDTH);
     154  
     155  #ifndef PTRDIFF_WIDTH
     156  # error "missing PTRDIFF_WIDTH"
     157  #endif
     158  CHECK_WIDTH (ptrdiff_t, PTRDIFF_MAX, PTRDIFF_WIDTH);
     159  #ifndef SIGNAL_SUPPRESS
     160  # ifndef SIG_ATOMIC_WIDTH
     161  #  error "missing SIG_ATOMIC_WIDTH"
     162  # endif
     163  CHECK_WIDTH (sig_atomic_t, SIG_ATOMIC_MAX, SIG_ATOMIC_WIDTH);
     164  #endif
     165  #ifndef SIZE_WIDTH
     166  # error "missing SIZE_WIDTH"
     167  #endif
     168  CHECK_WIDTH (size_t, SIZE_MAX, SIZE_WIDTH);
     169  #ifndef WCHAR_WIDTH
     170  # error "missing WCHAR_WIDTH"
     171  #endif
     172  CHECK_WIDTH (wchar_t, WCHAR_MAX, WCHAR_WIDTH);
     173  #ifndef WINT_WIDTH
     174  # error "missing WINT_WIDTH"
     175  #endif
     176  CHECK_WIDTH (wint_t, WINT_MAX, WINT_WIDTH);