[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Headers / limits.cpp
blobfbf6ed0f751cbbcc3bda6eb97514b9b0fb3e590a
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 16-bit int platforms.
8 // RUN: %clang_cc1 -triple=avr -ffreestanding -fsyntax-only -verify -x c %s
9 // RUN: %clang_cc1 -triple=avr -std=c++11 -ffreestanding -fsyntax-only -verify %s
11 // expected-no-diagnostics
13 #include <limits.h>
15 #if __cplusplus
16 #define EXPR_TYPE_IS(EXPR, TYP) __is_same(__typeof(EXPR), TYP)
17 #else
18 #define EXPR_TYPE_IS(EXPR, TYP) _Generic(EXPR, TYP: 1, default: 0)
19 #endif
21 _Static_assert(SCHAR_MAX == -(SCHAR_MIN+1), "");
22 _Static_assert(EXPR_TYPE_IS(SCHAR_MAX, int), "");
23 #if SCHAR_MAX
24 #endif
26 _Static_assert(SHRT_MAX == -(SHRT_MIN+1), "");
27 _Static_assert(EXPR_TYPE_IS(SHRT_MAX, int), "");
28 #if SHRT_MAX
29 #endif
31 _Static_assert(INT_MAX == -(INT_MIN+1), "");
32 _Static_assert(EXPR_TYPE_IS(INT_MAX, int), "");
33 #if INT_MAX
34 #endif
36 _Static_assert(LONG_MAX == -(LONG_MIN+1L), "");
37 _Static_assert(EXPR_TYPE_IS(LONG_MAX, long), "");
38 #if LONG_MAX
39 #endif
41 _Static_assert(SCHAR_MAX == UCHAR_MAX/2, "");
42 _Static_assert(SHRT_MAX == USHRT_MAX/2, "");
43 _Static_assert(INT_MAX == UINT_MAX/2, "");
44 _Static_assert(LONG_MAX == ULONG_MAX/2, "");
46 _Static_assert(SCHAR_MIN == -SCHAR_MAX-1, "");
47 _Static_assert(EXPR_TYPE_IS(SCHAR_MIN, int), "");
48 #if SCHAR_MIN
49 #endif
51 _Static_assert(SHRT_MIN == -SHRT_MAX-1, "");
52 _Static_assert(EXPR_TYPE_IS(SHRT_MIN, int), "");
53 #if SHRT_MIN
54 #endif
56 _Static_assert(INT_MIN == -INT_MAX-1, "");
57 _Static_assert(EXPR_TYPE_IS(INT_MIN, int), "");
58 #if INT_MIN
59 #endif
61 _Static_assert(LONG_MIN == -LONG_MAX-1L, "");
62 _Static_assert(EXPR_TYPE_IS(LONG_MIN, long), "");
63 #if LONG_MIN
64 #endif
66 _Static_assert(UCHAR_MAX == (unsigned char)~0ULL, "");
67 _Static_assert(UCHAR_MAX <= INT_MAX ?
68 EXPR_TYPE_IS(UCHAR_MAX, int) :
69 EXPR_TYPE_IS(UCHAR_MAX, unsigned int), "");
70 #if UCHAR_MAX
71 #endif
73 _Static_assert(USHRT_MAX == (unsigned short)~0ULL, "");
74 _Static_assert(USHRT_MAX <= INT_MAX ?
75 EXPR_TYPE_IS(USHRT_MAX, int) :
76 EXPR_TYPE_IS(USHRT_MAX, unsigned int), "");
77 #if USHRT_MAX
78 #endif
80 _Static_assert(UINT_MAX == (unsigned int)~0ULL, "");
81 _Static_assert(EXPR_TYPE_IS(UINT_MAX, unsigned int), "");
82 #if UINT_MAX
83 #endif
85 _Static_assert(ULONG_MAX == (unsigned long)~0ULL, "");
86 _Static_assert(EXPR_TYPE_IS(ULONG_MAX, unsigned long), "");
87 #if ULONG_MAX
88 #endif
90 _Static_assert(MB_LEN_MAX >= 1, "");
91 #if MB_LEN_MAX
92 #endif
94 _Static_assert(CHAR_BIT >= 8, "");
95 #if CHAR_BIT
96 #endif
98 _Static_assert(CHAR_MIN == (((char)-1 < (char)0) ? -CHAR_MAX-1 : 0), "");
99 _Static_assert(EXPR_TYPE_IS(CHAR_MIN, int), "");
100 #if CHAR_MIN
101 #endif
103 _Static_assert(CHAR_MAX == (((char)-1 < (char)0) ? -(CHAR_MIN+1) : (char)~0ULL), "");
104 _Static_assert(CHAR_MAX <= INT_MAX ?
105 EXPR_TYPE_IS(CHAR_MAX, int) :
106 EXPR_TYPE_IS(CHAR_MAX, unsigned int), "");
107 #if CHAR_MAX
108 #endif
110 #if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L
111 _Static_assert(LLONG_MAX == -(LLONG_MIN+1LL), "");
112 _Static_assert(EXPR_TYPE_IS(LLONG_MAX, long long), "");
113 #if LLONG_MAX
114 #endif
116 _Static_assert(LLONG_MIN == -LLONG_MAX-1LL, "");
117 #if LLONG_MIN
118 #endif
119 _Static_assert(EXPR_TYPE_IS(LLONG_MIN, long long), "");
121 _Static_assert(ULLONG_MAX == (unsigned long long)~0ULL, "");
122 _Static_assert(EXPR_TYPE_IS(ULLONG_MAX, unsigned long long), "");
123 #if ULLONG_MAX
124 #endif
125 #else
126 int LLONG_MIN, LLONG_MAX, ULLONG_MAX; // Not defined.
127 #endif
129 /* FIXME: This is using the placeholder dates Clang produces for these macros
130 in C2x mode; switch to the correct values once they've been published. */
131 #if __STDC_VERSION__ >= 202000L
132 /* Validate the standard requirements. */
133 _Static_assert(BOOL_WIDTH >= 1);
134 #if BOOL_WIDTH
135 #endif
137 _Static_assert(CHAR_WIDTH == CHAR_BIT);
138 _Static_assert(CHAR_WIDTH / CHAR_BIT == sizeof(char));
139 #if CHAR_WIDTH
140 #endif
141 _Static_assert(SCHAR_WIDTH == CHAR_BIT);
142 _Static_assert(SCHAR_WIDTH / CHAR_BIT == sizeof(signed char));
143 #if SCHAR_WIDTH
144 #endif
145 _Static_assert(UCHAR_WIDTH == CHAR_BIT);
146 _Static_assert(UCHAR_WIDTH / CHAR_BIT == sizeof(unsigned char));
147 #if UCHAR_WIDTH
148 #endif
150 _Static_assert(USHRT_WIDTH >= 16);
151 _Static_assert(USHRT_WIDTH / CHAR_BIT == sizeof(unsigned short));
152 #if USHRT_WIDTH
153 #endif
154 _Static_assert(SHRT_WIDTH == USHRT_WIDTH);
155 _Static_assert(SHRT_WIDTH / CHAR_BIT == sizeof(signed short));
156 #if SHRT_WIDTH
157 #endif
159 _Static_assert(UINT_WIDTH >= 16);
160 _Static_assert(UINT_WIDTH / CHAR_BIT == sizeof(unsigned int));
161 #if UINT_WIDTH
162 #endif
163 _Static_assert(INT_WIDTH == UINT_WIDTH);
164 _Static_assert(INT_WIDTH / CHAR_BIT == sizeof(signed int));
165 #if INT_WIDTH
166 #endif
168 _Static_assert(ULONG_WIDTH >= 32);
169 _Static_assert(ULONG_WIDTH / CHAR_BIT == sizeof(unsigned long));
170 #if ULONG_WIDTH
171 #endif
172 _Static_assert(LONG_WIDTH == ULONG_WIDTH);
173 _Static_assert(LONG_WIDTH / CHAR_BIT == sizeof(signed long));
174 #if LONG_WIDTH
175 #endif
177 _Static_assert(ULLONG_WIDTH >= 64);
178 _Static_assert(ULLONG_WIDTH / CHAR_BIT == sizeof(unsigned long long));
179 #if ULLONG_WIDTH
180 #endif
181 _Static_assert(LLONG_WIDTH == ULLONG_WIDTH);
182 _Static_assert(LLONG_WIDTH / CHAR_BIT == sizeof(signed long long));
183 #if LLONG_WIDTH
184 #endif
186 _Static_assert(BITINT_MAXWIDTH >= ULLONG_WIDTH);
187 #if BITINT_MAXWIDTH
188 #endif
189 #else
190 /* None of these are defined. */
191 int BOOL_WIDTH, CHAR_WIDTH, SCHAR_WIDTH, UCHAR_WIDTH, USHRT_WIDTH, SHRT_WIDTH,
192 UINT_WIDTH, INT_WIDTH, ULONG_WIDTH, LONG_WIDTH, ULLONG_WIDTH, LLONG_WIDTH,
193 BITINT_MAXWIDTH;
194 #endif