[RISCV][FMV] Support target_clones (#85786)
[llvm-project.git] / clang / test / Headers / limits.cpp
blobda7a64901831d56803c127e195648adb6d0a2428
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 #if __STDC_VERSION__ >= 202311L
130 /* Validate the standard requirements. */
131 _Static_assert(BOOL_WIDTH >= 1);
132 #if BOOL_WIDTH
133 #endif
135 _Static_assert(CHAR_WIDTH == CHAR_BIT);
136 _Static_assert(CHAR_WIDTH / CHAR_BIT == sizeof(char));
137 #if CHAR_WIDTH
138 #endif
139 _Static_assert(SCHAR_WIDTH == CHAR_BIT);
140 _Static_assert(SCHAR_WIDTH / CHAR_BIT == sizeof(signed char));
141 #if SCHAR_WIDTH
142 #endif
143 _Static_assert(UCHAR_WIDTH == CHAR_BIT);
144 _Static_assert(UCHAR_WIDTH / CHAR_BIT == sizeof(unsigned char));
145 #if UCHAR_WIDTH
146 #endif
148 _Static_assert(USHRT_WIDTH >= 16);
149 _Static_assert(USHRT_WIDTH / CHAR_BIT == sizeof(unsigned short));
150 #if USHRT_WIDTH
151 #endif
152 _Static_assert(SHRT_WIDTH == USHRT_WIDTH);
153 _Static_assert(SHRT_WIDTH / CHAR_BIT == sizeof(signed short));
154 #if SHRT_WIDTH
155 #endif
157 _Static_assert(UINT_WIDTH >= 16);
158 _Static_assert(UINT_WIDTH / CHAR_BIT == sizeof(unsigned int));
159 #if UINT_WIDTH
160 #endif
161 _Static_assert(INT_WIDTH == UINT_WIDTH);
162 _Static_assert(INT_WIDTH / CHAR_BIT == sizeof(signed int));
163 #if INT_WIDTH
164 #endif
166 _Static_assert(ULONG_WIDTH >= 32);
167 _Static_assert(ULONG_WIDTH / CHAR_BIT == sizeof(unsigned long));
168 #if ULONG_WIDTH
169 #endif
170 _Static_assert(LONG_WIDTH == ULONG_WIDTH);
171 _Static_assert(LONG_WIDTH / CHAR_BIT == sizeof(signed long));
172 #if LONG_WIDTH
173 #endif
175 _Static_assert(ULLONG_WIDTH >= 64);
176 _Static_assert(ULLONG_WIDTH / CHAR_BIT == sizeof(unsigned long long));
177 #if ULLONG_WIDTH
178 #endif
179 _Static_assert(LLONG_WIDTH == ULLONG_WIDTH);
180 _Static_assert(LLONG_WIDTH / CHAR_BIT == sizeof(signed long long));
181 #if LLONG_WIDTH
182 #endif
184 _Static_assert(BITINT_MAXWIDTH >= ULLONG_WIDTH);
185 #if BITINT_MAXWIDTH
186 #endif
187 #else
188 /* None of these are defined. */
189 int BOOL_WIDTH, CHAR_WIDTH, SCHAR_WIDTH, UCHAR_WIDTH, USHRT_WIDTH, SHRT_WIDTH,
190 UINT_WIDTH, INT_WIDTH, ULONG_WIDTH, LONG_WIDTH, ULLONG_WIDTH, LLONG_WIDTH,
191 BITINT_MAXWIDTH;
192 #endif