1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // test <stdint.h>
11
12 #include <stdint.h>
13 #include <cstddef>
14 #include <csignal>
15 #include <cwctype>
16 #include <climits>
17 #include <type_traits>
18 #include <limits>
19 #include <cassert>
20
main()21 int main()
22 {
23 // typedef int8_t
24 static_assert(sizeof(int8_t)*CHAR_BIT == 8,
25 "sizeof(int8_t)*CHAR_BIT == 8");
26 static_assert(std::is_signed<int8_t>::value,
27 "std::is_signed<int8_t>::value");
28 // typedef int16_t
29 static_assert(sizeof(int16_t)*CHAR_BIT == 16,
30 "sizeof(int16_t)*CHAR_BIT == 16");
31 static_assert(std::is_signed<int16_t>::value,
32 "std::is_signed<int16_t>::value");
33 // typedef int32_t
34 static_assert(sizeof(int32_t)*CHAR_BIT == 32,
35 "sizeof(int32_t)*CHAR_BIT == 32");
36 static_assert(std::is_signed<int32_t>::value,
37 "std::is_signed<int32_t>::value");
38 // typedef int64_t
39 static_assert(sizeof(int64_t)*CHAR_BIT == 64,
40 "sizeof(int64_t)*CHAR_BIT == 64");
41 static_assert(std::is_signed<int64_t>::value,
42 "std::is_signed<int64_t>::value");
43
44 // typedef uint8_t
45 static_assert(sizeof(uint8_t)*CHAR_BIT == 8,
46 "sizeof(uint8_t)*CHAR_BIT == 8");
47 static_assert(std::is_unsigned<uint8_t>::value,
48 "std::is_unsigned<uint8_t>::value");
49 // typedef uint16_t
50 static_assert(sizeof(uint16_t)*CHAR_BIT == 16,
51 "sizeof(uint16_t)*CHAR_BIT == 16");
52 static_assert(std::is_unsigned<uint16_t>::value,
53 "std::is_unsigned<uint16_t>::value");
54 // typedef uint32_t
55 static_assert(sizeof(uint32_t)*CHAR_BIT == 32,
56 "sizeof(uint32_t)*CHAR_BIT == 32");
57 static_assert(std::is_unsigned<uint32_t>::value,
58 "std::is_unsigned<uint32_t>::value");
59 // typedef uint64_t
60 static_assert(sizeof(uint64_t)*CHAR_BIT == 64,
61 "sizeof(uint64_t)*CHAR_BIT == 64");
62 static_assert(std::is_unsigned<uint64_t>::value,
63 "std::is_unsigned<uint64_t>::value");
64
65 // typedef int_least8_t
66 static_assert(sizeof(int_least8_t)*CHAR_BIT >= 8,
67 "sizeof(int_least8_t)*CHAR_BIT >= 8");
68 static_assert(std::is_signed<int_least8_t>::value,
69 "std::is_signed<int_least8_t>::value");
70 // typedef int_least16_t
71 static_assert(sizeof(int_least16_t)*CHAR_BIT >= 16,
72 "sizeof(int_least16_t)*CHAR_BIT >= 16");
73 static_assert(std::is_signed<int_least16_t>::value,
74 "std::is_signed<int_least16_t>::value");
75 // typedef int_least32_t
76 static_assert(sizeof(int_least32_t)*CHAR_BIT >= 32,
77 "sizeof(int_least32_t)*CHAR_BIT >= 32");
78 static_assert(std::is_signed<int_least32_t>::value,
79 "std::is_signed<int_least32_t>::value");
80 // typedef int_least64_t
81 static_assert(sizeof(int_least64_t)*CHAR_BIT >= 64,
82 "sizeof(int_least64_t)*CHAR_BIT >= 64");
83 static_assert(std::is_signed<int_least64_t>::value,
84 "std::is_signed<int_least64_t>::value");
85
86 // typedef uint_least8_t
87 static_assert(sizeof(uint_least8_t)*CHAR_BIT >= 8,
88 "sizeof(uint_least8_t)*CHAR_BIT >= 8");
89 static_assert(std::is_unsigned<uint_least8_t>::value,
90 "std::is_unsigned<uint_least8_t>::value");
91 // typedef uint_least16_t
92 static_assert(sizeof(uint_least16_t)*CHAR_BIT >= 16,
93 "sizeof(uint_least16_t)*CHAR_BIT >= 16");
94 static_assert(std::is_unsigned<uint_least16_t>::value,
95 "std::is_unsigned<uint_least16_t>::value");
96 // typedef uint_least32_t
97 static_assert(sizeof(uint_least32_t)*CHAR_BIT >= 32,
98 "sizeof(uint_least32_t)*CHAR_BIT >= 32");
99 static_assert(std::is_unsigned<uint_least32_t>::value,
100 "std::is_unsigned<uint_least32_t>::value");
101 // typedef uint_least64_t
102 static_assert(sizeof(uint_least64_t)*CHAR_BIT >= 64,
103 "sizeof(uint_least64_t)*CHAR_BIT >= 64");
104 static_assert(std::is_unsigned<uint_least64_t>::value,
105 "std::is_unsigned<uint_least64_t>::value");
106
107 // typedef int_fast8_t
108 static_assert(sizeof(int_fast8_t)*CHAR_BIT >= 8,
109 "sizeof(int_fast8_t)*CHAR_BIT >= 8");
110 static_assert(std::is_signed<int_fast8_t>::value,
111 "std::is_signed<int_fast8_t>::value");
112 // typedef int_fast16_t
113 static_assert(sizeof(int_fast16_t)*CHAR_BIT >= 16,
114 "sizeof(int_fast16_t)*CHAR_BIT >= 16");
115 static_assert(std::is_signed<int_fast16_t>::value,
116 "std::is_signed<int_fast16_t>::value");
117 // typedef int_fast32_t
118 static_assert(sizeof(int_fast32_t)*CHAR_BIT >= 32,
119 "sizeof(int_fast32_t)*CHAR_BIT >= 32");
120 static_assert(std::is_signed<int_fast32_t>::value,
121 "std::is_signed<int_fast32_t>::value");
122 // typedef int_fast64_t
123 static_assert(sizeof(int_fast64_t)*CHAR_BIT >= 64,
124 "sizeof(int_fast64_t)*CHAR_BIT >= 64");
125 static_assert(std::is_signed<int_fast64_t>::value,
126 "std::is_signed<int_fast64_t>::value");
127
128 // typedef uint_fast8_t
129 static_assert(sizeof(uint_fast8_t)*CHAR_BIT >= 8,
130 "sizeof(uint_fast8_t)*CHAR_BIT >= 8");
131 static_assert(std::is_unsigned<uint_fast8_t>::value,
132 "std::is_unsigned<uint_fast8_t>::value");
133 // typedef uint_fast16_t
134 static_assert(sizeof(uint_fast16_t)*CHAR_BIT >= 16,
135 "sizeof(uint_fast16_t)*CHAR_BIT >= 16");
136 static_assert(std::is_unsigned<uint_fast16_t>::value,
137 "std::is_unsigned<uint_fast16_t>::value");
138 // typedef uint_fast32_t
139 static_assert(sizeof(uint_fast32_t)*CHAR_BIT >= 32,
140 "sizeof(uint_fast32_t)*CHAR_BIT >= 32");
141 static_assert(std::is_unsigned<uint_fast32_t>::value,
142 "std::is_unsigned<uint_fast32_t>::value");
143 // typedef uint_fast64_t
144 static_assert(sizeof(uint_fast64_t)*CHAR_BIT >= 64,
145 "sizeof(uint_fast64_t)*CHAR_BIT >= 64");
146 static_assert(std::is_unsigned<uint_fast64_t>::value,
147 "std::is_unsigned<uint_fast64_t>::value");
148
149 // typedef intptr_t
150 static_assert(sizeof(intptr_t) >= sizeof(void*),
151 "sizeof(intptr_t) >= sizeof(void*)");
152 static_assert(std::is_signed<intptr_t>::value,
153 "std::is_signed<intptr_t>::value");
154 // typedef uintptr_t
155 static_assert(sizeof(uintptr_t) >= sizeof(void*),
156 "sizeof(uintptr_t) >= sizeof(void*)");
157 static_assert(std::is_unsigned<uintptr_t>::value,
158 "std::is_unsigned<uintptr_t>::value");
159
160 // typedef intmax_t
161 static_assert(sizeof(intmax_t) >= sizeof(long long),
162 "sizeof(intmax_t) >= sizeof(long long)");
163 static_assert(std::is_signed<intmax_t>::value,
164 "std::is_signed<intmax_t>::value");
165 // typedef uintmax_t
166 static_assert(sizeof(uintmax_t) >= sizeof(unsigned long long),
167 "sizeof(uintmax_t) >= sizeof(unsigned long long)");
168 static_assert(std::is_unsigned<uintmax_t>::value,
169 "std::is_unsigned<uintmax_t>::value");
170
171 // INTN_MIN
172 static_assert(INT8_MIN == -128, "INT8_MIN == -128");
173 static_assert(INT16_MIN == -32768, "INT16_MIN == -32768");
174 static_assert(INT32_MIN == -2147483647 - 1, "INT32_MIN == -2147483648");
175 static_assert(INT64_MIN == -9223372036854775807LL - 1, "INT64_MIN == -9223372036854775808LL");
176
177 // INTN_MAX
178 static_assert(INT8_MAX == 127, "INT8_MAX == 127");
179 static_assert(INT16_MAX == 32767, "INT16_MAX == 32767");
180 static_assert(INT32_MAX == 2147483647, "INT32_MAX == 2147483647");
181 static_assert(INT64_MAX == 9223372036854775807LL, "INT64_MAX == 9223372036854775807LL");
182
183 // UINTN_MAX
184 static_assert(UINT8_MAX == 255, "UINT8_MAX == 255");
185 static_assert(UINT16_MAX == 65535, "UINT16_MAX == 65535");
186 static_assert(UINT32_MAX == 4294967295U, "UINT32_MAX == 4294967295");
187 static_assert(UINT64_MAX == 18446744073709551615ULL, "UINT64_MAX == 18446744073709551615ULL");
188
189 // INT_FASTN_MIN
190 static_assert(INT_FAST8_MIN <= -128, "INT_FAST8_MIN <= -128");
191 static_assert(INT_FAST16_MIN <= -32768, "INT_FAST16_MIN <= -32768");
192 static_assert(INT_FAST32_MIN <= -2147483647 - 1, "INT_FAST32_MIN <= -2147483648");
193 static_assert(INT_FAST64_MIN <= -9223372036854775807LL - 1, "INT_FAST64_MIN <= -9223372036854775808LL");
194
195 // INT_FASTN_MAX
196 static_assert(INT_FAST8_MAX >= 127, "INT_FAST8_MAX >= 127");
197 static_assert(INT_FAST16_MAX >= 32767, "INT_FAST16_MAX >= 32767");
198 static_assert(INT_FAST32_MAX >= 2147483647, "INT_FAST32_MAX >= 2147483647");
199 static_assert(INT_FAST64_MAX >= 9223372036854775807LL, "INT_FAST64_MAX >= 9223372036854775807LL");
200
201 // UINT_FASTN_MAX
202 static_assert(UINT_FAST8_MAX >= 255, "UINT_FAST8_MAX >= 255");
203 static_assert(UINT_FAST16_MAX >= 65535, "UINT_FAST16_MAX >= 65535");
204 static_assert(UINT_FAST32_MAX >= 4294967295U, "UINT_FAST32_MAX >= 4294967295");
205 static_assert(UINT_FAST64_MAX >= 18446744073709551615ULL, "UINT_FAST64_MAX >= 18446744073709551615ULL");
206
207 // INTPTR_MIN
208 assert(INTPTR_MIN == std::numeric_limits<intptr_t>::min());
209
210 // INTPTR_MAX
211 assert(INTPTR_MAX == std::numeric_limits<intptr_t>::max());
212
213 // UINTPTR_MAX
214 assert(UINTPTR_MAX == std::numeric_limits<uintptr_t>::max());
215
216 // INTMAX_MIN
217 assert(INTMAX_MIN == std::numeric_limits<intmax_t>::min());
218
219 // INTMAX_MAX
220 assert(INTMAX_MAX == std::numeric_limits<intmax_t>::max());
221
222 // UINTMAX_MAX
223 assert(UINTMAX_MAX == std::numeric_limits<uintmax_t>::max());
224
225 // PTRDIFF_MIN
226 assert(PTRDIFF_MIN == std::numeric_limits<std::ptrdiff_t>::min());
227
228 // PTRDIFF_MAX
229 assert(PTRDIFF_MAX == std::numeric_limits<std::ptrdiff_t>::max());
230
231 // SIG_ATOMIC_MIN
232 assert(SIG_ATOMIC_MIN == std::numeric_limits<sig_atomic_t>::min());
233
234 // SIG_ATOMIC_MAX
235 assert(SIG_ATOMIC_MAX == std::numeric_limits<sig_atomic_t>::max());
236
237 // SIZE_MAX
238 assert(SIZE_MAX == std::numeric_limits<size_t>::max());
239
240 // WCHAR_MIN
241 assert(WCHAR_MIN == std::numeric_limits<wchar_t>::min());
242
243 // WCHAR_MAX
244 assert(WCHAR_MAX == std::numeric_limits<wchar_t>::max());
245
246 // WINT_MIN
247 assert(WINT_MIN == std::numeric_limits<wint_t>::min());
248
249 // WINT_MAX
250 assert(WINT_MAX == std::numeric_limits<wint_t>::max());
251
252 #ifndef INT8_C
253 #error INT8_C not defined
254 #endif
255
256 #ifndef INT16_C
257 #error INT16_C not defined
258 #endif
259
260 #ifndef INT32_C
261 #error INT32_C not defined
262 #endif
263
264 #ifndef INT64_C
265 #error INT64_C not defined
266 #endif
267
268 #ifndef UINT8_C
269 #error UINT8_C not defined
270 #endif
271
272 #ifndef UINT16_C
273 #error UINT16_C not defined
274 #endif
275
276 #ifndef UINT32_C
277 #error UINT32_C not defined
278 #endif
279
280 #ifndef UINT64_C
281 #error UINT64_C not defined
282 #endif
283
284 #ifndef INTMAX_C
285 #error INTMAX_C not defined
286 #endif
287
288 #ifndef UINTMAX_C
289 #error UINTMAX_C not defined
290 #endif
291 }
292