1 // RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fno-signed-char -ffreestanding -fsyntax-only -verify %s
3 // RUN: %clang_cc1 -std=c++11 -ffreestanding -fsyntax-only -verify %s
4 // RUN: %clang_cc1 -std=c17 -ffreestanding -fsyntax-only -verify -x c %s
5 // RUN: %clang_cc1 -std=c2x -ffreestanding -fsyntax-only -verify -x c %s
7 // Specifically test arm64 linux platforms.
8 // RUN: %clang_cc1 -triple arm64-linux -ffreestanding -fsyntax-only -verify -x c %s
10 // Specifically test 16-bit int platforms.
11 // RUN: %clang_cc1 -triple=avr -ffreestanding -fsyntax-only -verify -x c %s
12 // RUN: %clang_cc1 -triple=avr -std=c++11 -ffreestanding -fsyntax-only -verify %s
14 // expected-no-diagnostics
19 #define EXPR_TYPE_IS(EXPR, TYP) __is_same(__typeof(EXPR), TYP)
21 #define EXPR_TYPE_IS(EXPR, TYP) _Generic(EXPR, TYP: 1, default: 0)
24 _Static_assert(SCHAR_MAX
== -(SCHAR_MIN
+1), "");
25 _Static_assert(EXPR_TYPE_IS(SCHAR_MAX
, int), "");
29 _Static_assert(SHRT_MAX
== -(SHRT_MIN
+1), "");
30 _Static_assert(EXPR_TYPE_IS(SHRT_MAX
, int), "");
34 _Static_assert(INT_MAX
== -(INT_MIN
+1), "");
35 _Static_assert(EXPR_TYPE_IS(INT_MAX
, int), "");
39 _Static_assert(LONG_MAX
== -(LONG_MIN
+1L), "");
40 _Static_assert(EXPR_TYPE_IS(LONG_MAX
, long), "");
44 _Static_assert(SCHAR_MAX
== UCHAR_MAX
/2, "");
45 _Static_assert(SHRT_MAX
== USHRT_MAX
/2, "");
46 _Static_assert(INT_MAX
== UINT_MAX
/2, "");
47 _Static_assert(LONG_MAX
== ULONG_MAX
/2, "");
49 _Static_assert(SCHAR_MIN
== -SCHAR_MAX
-1, "");
50 _Static_assert(EXPR_TYPE_IS(SCHAR_MIN
, int), "");
54 _Static_assert(SHRT_MIN
== -SHRT_MAX
-1, "");
55 _Static_assert(EXPR_TYPE_IS(SHRT_MIN
, int), "");
59 _Static_assert(INT_MIN
== -INT_MAX
-1, "");
60 _Static_assert(EXPR_TYPE_IS(INT_MIN
, int), "");
64 _Static_assert(LONG_MIN
== -LONG_MAX
-1L, "");
65 _Static_assert(EXPR_TYPE_IS(LONG_MIN
, long), "");
69 _Static_assert(UCHAR_MAX
== (unsigned char)~0ULL, "");
70 _Static_assert(UCHAR_MAX
<= INT_MAX
?
71 EXPR_TYPE_IS(UCHAR_MAX
, int) :
72 EXPR_TYPE_IS(UCHAR_MAX
, unsigned int), "");
76 _Static_assert(USHRT_MAX
== (unsigned short)~0ULL, "");
77 _Static_assert(USHRT_MAX
<= INT_MAX
?
78 EXPR_TYPE_IS(USHRT_MAX
, int) :
79 EXPR_TYPE_IS(USHRT_MAX
, unsigned int), "");
83 _Static_assert(UINT_MAX
== (unsigned int)~0ULL, "");
84 _Static_assert(EXPR_TYPE_IS(UINT_MAX
, unsigned int), "");
88 _Static_assert(ULONG_MAX
== (unsigned long)~0ULL, "");
89 _Static_assert(EXPR_TYPE_IS(ULONG_MAX
, unsigned long), "");
93 _Static_assert(MB_LEN_MAX
>= 1, "");
97 _Static_assert(CHAR_BIT
>= 8, "");
101 _Static_assert(CHAR_MIN
== (((char)-1 < (char)0) ? -CHAR_MAX
-1 : 0), "");
102 _Static_assert(EXPR_TYPE_IS(CHAR_MIN
, int), "");
106 _Static_assert(CHAR_MAX
== (((char)-1 < (char)0) ? -(CHAR_MIN
+1) : (char)~0ULL), "");
107 _Static_assert(CHAR_MAX
<= INT_MAX
?
108 EXPR_TYPE_IS(CHAR_MAX
, int) :
109 EXPR_TYPE_IS(CHAR_MAX
, unsigned int), "");
113 #if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L
114 _Static_assert(LLONG_MAX
== -(LLONG_MIN
+1LL), "");
115 _Static_assert(EXPR_TYPE_IS(LLONG_MAX
, long long), "");
119 _Static_assert(LLONG_MIN
== -LLONG_MAX
-1LL, "");
122 _Static_assert(EXPR_TYPE_IS(LLONG_MIN
, long long), "");
124 _Static_assert(ULLONG_MAX
== (unsigned long long)~0ULL, "");
125 _Static_assert(EXPR_TYPE_IS(ULLONG_MAX
, unsigned long long), "");
129 int LLONG_MIN
, LLONG_MAX
, ULLONG_MAX
; // Not defined.
132 #if __STDC_VERSION__ >= 202311L
133 /* Validate the standard requirements. */
134 _Static_assert(BOOL_WIDTH
>= 1);
138 _Static_assert(CHAR_WIDTH
== CHAR_BIT
);
139 _Static_assert(CHAR_WIDTH
/ CHAR_BIT
== sizeof(char));
142 _Static_assert(SCHAR_WIDTH
== CHAR_BIT
);
143 _Static_assert(SCHAR_WIDTH
/ CHAR_BIT
== sizeof(signed char));
146 _Static_assert(UCHAR_WIDTH
== CHAR_BIT
);
147 _Static_assert(UCHAR_WIDTH
/ CHAR_BIT
== sizeof(unsigned char));
151 _Static_assert(USHRT_WIDTH
>= 16);
152 _Static_assert(USHRT_WIDTH
/ CHAR_BIT
== sizeof(unsigned short));
155 _Static_assert(SHRT_WIDTH
== USHRT_WIDTH
);
156 _Static_assert(SHRT_WIDTH
/ CHAR_BIT
== sizeof(signed short));
160 _Static_assert(UINT_WIDTH
>= 16);
161 _Static_assert(UINT_WIDTH
/ CHAR_BIT
== sizeof(unsigned int));
164 _Static_assert(INT_WIDTH
== UINT_WIDTH
);
165 _Static_assert(INT_WIDTH
/ CHAR_BIT
== sizeof(signed int));
169 _Static_assert(ULONG_WIDTH
>= 32);
170 _Static_assert(ULONG_WIDTH
/ CHAR_BIT
== sizeof(unsigned long));
173 _Static_assert(LONG_WIDTH
== ULONG_WIDTH
);
174 _Static_assert(LONG_WIDTH
/ CHAR_BIT
== sizeof(signed long));
178 _Static_assert(ULLONG_WIDTH
>= 64);
179 _Static_assert(ULLONG_WIDTH
/ CHAR_BIT
== sizeof(unsigned long long));
182 _Static_assert(LLONG_WIDTH
== ULLONG_WIDTH
);
183 _Static_assert(LLONG_WIDTH
/ CHAR_BIT
== sizeof(signed long long));
187 _Static_assert(BITINT_MAXWIDTH
>= ULLONG_WIDTH
);
191 /* None of these are defined. */
192 int BOOL_WIDTH
, CHAR_WIDTH
, SCHAR_WIDTH
, UCHAR_WIDTH
, USHRT_WIDTH
, SHRT_WIDTH
,
193 UINT_WIDTH
, INT_WIDTH
, ULONG_WIDTH
, LONG_WIDTH
, ULLONG_WIDTH
, LLONG_WIDTH
,