[LICM] allow MemoryAccess creation failure (#116813)
[llvm-project.git] / libc / include / llvm-libc-macros / stdint-macros.h
blob1d5da2b783b6eb56966068e75c0f8afc09853d7e
1 //===-- Definition of macros from stdint.h --------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_MACROS_STDINT_MACROS_H
10 #define LLVM_LIBC_MACROS_STDINT_MACROS_H
12 // These definitions are copied directly from the clang implementation located
13 // at 'clang/lib/Headers/stdint.h'. We provide it here again for compatibility.
15 /* C99 7.18.1.1 Exact-width integer types.
16 * C99 7.18.1.2 Minimum-width integer types.
17 * C99 7.18.1.3 Fastest minimum-width integer types.
19 * The standard requires that exact-width type be defined for 8-, 16-, 32-, and
20 * 64-bit types if they are implemented. Other exact width types are optional.
21 * This implementation defines an exact-width types for every integer width
22 * that is represented in the standard integer types.
24 * The standard also requires minimum-width types be defined for 8-, 16-, 32-,
25 * and 64-bit widths regardless of whether there are corresponding exact-width
26 * types.
28 * To accommodate targets that are missing types that are exactly 8, 16, 32, or
29 * 64 bits wide, this implementation takes an approach of cascading
30 * redefinitions, redefining __int_leastN_t to successively smaller exact-width
31 * types. It is therefore important that the types are defined in order of
32 * descending widths.
34 * We currently assume that the minimum-width types and the fastest
35 * minimum-width types are the same. This is allowed by the standard, but is
36 * suboptimal.
38 * In violation of the standard, some targets do not implement a type that is
39 * wide enough to represent all of the required widths (8-, 16-, 32-, 64-bit).
40 * To accommodate these targets, a required minimum-width type is only
41 * defined if there exists an exact-width type of equal or greater width.
44 #ifdef __INT64_TYPE__
45 #ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/
46 typedef __INT64_TYPE__ int64_t;
47 #endif /* __int8_t_defined */
48 typedef __UINT64_TYPE__ uint64_t;
49 #undef __int_least64_t
50 #define __int_least64_t int64_t
51 #undef __uint_least64_t
52 #define __uint_least64_t uint64_t
53 #undef __int_least32_t
54 #define __int_least32_t int64_t
55 #undef __uint_least32_t
56 #define __uint_least32_t uint64_t
57 #undef __int_least16_t
58 #define __int_least16_t int64_t
59 #undef __uint_least16_t
60 #define __uint_least16_t uint64_t
61 #undef __int_least8_t
62 #define __int_least8_t int64_t
63 #undef __uint_least8_t
64 #define __uint_least8_t uint64_t
65 #endif /* __INT64_TYPE__ */
67 #ifdef __int_least64_t
68 typedef __int_least64_t int_least64_t;
69 typedef __uint_least64_t uint_least64_t;
70 typedef __int_least64_t int_fast64_t;
71 typedef __uint_least64_t uint_fast64_t;
72 #endif /* __int_least64_t */
74 #ifdef __INT56_TYPE__
75 typedef __INT56_TYPE__ int56_t;
76 typedef __UINT56_TYPE__ uint56_t;
77 typedef int56_t int_least56_t;
78 typedef uint56_t uint_least56_t;
79 typedef int56_t int_fast56_t;
80 typedef uint56_t uint_fast56_t;
81 #undef __int_least32_t
82 #define __int_least32_t int56_t
83 #undef __uint_least32_t
84 #define __uint_least32_t uint56_t
85 #undef __int_least16_t
86 #define __int_least16_t int56_t
87 #undef __uint_least16_t
88 #define __uint_least16_t uint56_t
89 #undef __int_least8_t
90 #define __int_least8_t int56_t
91 #undef __uint_least8_t
92 #define __uint_least8_t uint56_t
93 #endif /* __INT56_TYPE__ */
95 #ifdef __INT48_TYPE__
96 typedef __INT48_TYPE__ int48_t;
97 typedef __UINT48_TYPE__ uint48_t;
98 typedef int48_t int_least48_t;
99 typedef uint48_t uint_least48_t;
100 typedef int48_t int_fast48_t;
101 typedef uint48_t uint_fast48_t;
102 #undef __int_least32_t
103 #define __int_least32_t int48_t
104 #undef __uint_least32_t
105 #define __uint_least32_t uint48_t
106 #undef __int_least16_t
107 #define __int_least16_t int48_t
108 #undef __uint_least16_t
109 #define __uint_least16_t uint48_t
110 #undef __int_least8_t
111 #define __int_least8_t int48_t
112 #undef __uint_least8_t
113 #define __uint_least8_t uint48_t
114 #endif /* __INT48_TYPE__ */
116 #ifdef __INT40_TYPE__
117 typedef __INT40_TYPE__ int40_t;
118 typedef __UINT40_TYPE__ uint40_t;
119 typedef int40_t int_least40_t;
120 typedef uint40_t uint_least40_t;
121 typedef int40_t int_fast40_t;
122 typedef uint40_t uint_fast40_t;
123 #undef __int_least32_t
124 #define __int_least32_t int40_t
125 #undef __uint_least32_t
126 #define __uint_least32_t uint40_t
127 #undef __int_least16_t
128 #define __int_least16_t int40_t
129 #undef __uint_least16_t
130 #define __uint_least16_t uint40_t
131 #undef __int_least8_t
132 #define __int_least8_t int40_t
133 #undef __uint_least8_t
134 #define __uint_least8_t uint40_t
135 #endif /* __INT40_TYPE__ */
137 #ifdef __INT32_TYPE__
139 #ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/
140 typedef __INT32_TYPE__ int32_t;
141 #endif /* __int8_t_defined */
143 #ifndef __uint32_t_defined /* more glibc compatibility */
144 #define __uint32_t_defined
145 typedef __UINT32_TYPE__ uint32_t;
146 #endif /* __uint32_t_defined */
148 #undef __int_least32_t
149 #define __int_least32_t int32_t
150 #undef __uint_least32_t
151 #define __uint_least32_t uint32_t
152 #undef __int_least16_t
153 #define __int_least16_t int32_t
154 #undef __uint_least16_t
155 #define __uint_least16_t uint32_t
156 #undef __int_least8_t
157 #define __int_least8_t int32_t
158 #undef __uint_least8_t
159 #define __uint_least8_t uint32_t
160 #endif /* __INT32_TYPE__ */
162 #ifdef __int_least32_t
163 typedef __int_least32_t int_least32_t;
164 typedef __uint_least32_t uint_least32_t;
165 typedef __int_least32_t int_fast32_t;
166 typedef __uint_least32_t uint_fast32_t;
167 #endif /* __int_least32_t */
169 #ifdef __INT24_TYPE__
170 typedef __INT24_TYPE__ int24_t;
171 typedef __UINT24_TYPE__ uint24_t;
172 typedef int24_t int_least24_t;
173 typedef uint24_t uint_least24_t;
174 typedef int24_t int_fast24_t;
175 typedef uint24_t uint_fast24_t;
176 #undef __int_least16_t
177 #define __int_least16_t int24_t
178 #undef __uint_least16_t
179 #define __uint_least16_t uint24_t
180 #undef __int_least8_t
181 #define __int_least8_t int24_t
182 #undef __uint_least8_t
183 #define __uint_least8_t uint24_t
184 #endif /* __INT24_TYPE__ */
186 #ifdef __INT16_TYPE__
187 #ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/
188 typedef __INT16_TYPE__ int16_t;
189 #endif /* __int8_t_defined */
190 typedef __UINT16_TYPE__ uint16_t;
191 #undef __int_least16_t
192 #define __int_least16_t int16_t
193 #undef __uint_least16_t
194 #define __uint_least16_t uint16_t
195 #undef __int_least8_t
196 #define __int_least8_t int16_t
197 #undef __uint_least8_t
198 #define __uint_least8_t uint16_t
199 #endif /* __INT16_TYPE__ */
201 #ifdef __int_least16_t
202 typedef __int_least16_t int_least16_t;
203 typedef __uint_least16_t uint_least16_t;
204 typedef __int_least16_t int_fast16_t;
205 typedef __uint_least16_t uint_fast16_t;
206 #endif /* __int_least16_t */
208 #ifdef __INT8_TYPE__
209 #ifndef __int8_t_defined /* glibc sys/types.h also defines int8_t*/
210 typedef __INT8_TYPE__ int8_t;
211 #endif /* __int8_t_defined */
212 typedef __UINT8_TYPE__ uint8_t;
213 #undef __int_least8_t
214 #define __int_least8_t int8_t
215 #undef __uint_least8_t
216 #define __uint_least8_t uint8_t
217 #endif /* __INT8_TYPE__ */
219 #ifdef __int_least8_t
220 typedef __int_least8_t int_least8_t;
221 typedef __uint_least8_t uint_least8_t;
222 typedef __int_least8_t int_fast8_t;
223 typedef __uint_least8_t uint_fast8_t;
224 #endif /* __int_least8_t */
226 /* prevent glibc sys/types.h from defining conflicting types */
227 #ifndef __int8_t_defined
228 #define __int8_t_defined
229 #endif /* __int8_t_defined */
231 /* C99 7.18.1.4 Integer types capable of holding object pointers.
233 #define __stdint_join3(a, b, c) a##b##c
235 #ifndef _INTPTR_T
236 #ifndef __intptr_t_defined
237 typedef __INTPTR_TYPE__ intptr_t;
238 #define __intptr_t_defined
239 #define _INTPTR_T
240 #endif
241 #endif
243 #ifndef _UINTPTR_T
244 typedef __UINTPTR_TYPE__ uintptr_t;
245 #define _UINTPTR_T
246 #endif
248 /* C99 7.18.1.5 Greatest-width integer types.
250 typedef __INTMAX_TYPE__ intmax_t;
251 typedef __UINTMAX_TYPE__ uintmax_t;
253 /* C99 7.18.4 Macros for minimum-width integer constants.
255 * The standard requires that integer constant macros be defined for all the
256 * minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width
257 * types are required, the corresponding integer constant macros are defined
258 * here. This implementation also defines minimum-width types for every other
259 * integer width that the target implements, so corresponding macros are
260 * defined below, too.
262 * These macros are defined using the same successive-shrinking approach as
263 * the type definitions above. It is likewise important that macros are defined
264 * in order of decending width.
266 * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the
267 * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
270 #define __int_c_join(a, b) a##b
271 #define __int_c(v, suffix) __int_c_join(v, suffix)
272 #define __uint_c(v, suffix) __int_c_join(v##U, suffix)
274 #ifdef __INT64_TYPE__
275 #undef __int64_c_suffix
276 #undef __int32_c_suffix
277 #undef __int16_c_suffix
278 #undef __int8_c_suffix
279 #ifdef __INT64_C_SUFFIX__
280 #define __int64_c_suffix __INT64_C_SUFFIX__
281 #define __int32_c_suffix __INT64_C_SUFFIX__
282 #define __int16_c_suffix __INT64_C_SUFFIX__
283 #define __int8_c_suffix __INT64_C_SUFFIX__
284 #endif /* __INT64_C_SUFFIX__ */
285 #endif /* __INT64_TYPE__ */
287 #ifdef __int_least64_t
288 #ifdef __int64_c_suffix
289 #define INT64_C(v) __int_c(v, __int64_c_suffix)
290 #define UINT64_C(v) __uint_c(v, __int64_c_suffix)
291 #else
292 #define INT64_C(v) v
293 #define UINT64_C(v) v##U
294 #endif /* __int64_c_suffix */
295 #endif /* __int_least64_t */
297 #ifdef __INT56_TYPE__
298 #undef __int32_c_suffix
299 #undef __int16_c_suffix
300 #undef __int8_c_suffix
301 #ifdef __INT56_C_SUFFIX__
302 #define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__)
303 #define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__)
304 #define __int32_c_suffix __INT56_C_SUFFIX__
305 #define __int16_c_suffix __INT56_C_SUFFIX__
306 #define __int8_c_suffix __INT56_C_SUFFIX__
307 #else
308 #define INT56_C(v) v
309 #define UINT56_C(v) v##U
310 #endif /* __INT56_C_SUFFIX__ */
311 #endif /* __INT56_TYPE__ */
313 #ifdef __INT48_TYPE__
314 #undef __int32_c_suffix
315 #undef __int16_c_suffix
316 #undef __int8_c_suffix
317 #ifdef __INT48_C_SUFFIX__
318 #define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__)
319 #define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__)
320 #define __int32_c_suffix __INT48_C_SUFFIX__
321 #define __int16_c_suffix __INT48_C_SUFFIX__
322 #define __int8_c_suffix __INT48_C_SUFFIX__
323 #else
324 #define INT48_C(v) v
325 #define UINT48_C(v) v##U
326 #endif /* __INT48_C_SUFFIX__ */
327 #endif /* __INT48_TYPE__ */
329 #ifdef __INT40_TYPE__
330 #undef __int32_c_suffix
331 #undef __int16_c_suffix
332 #undef __int8_c_suffix
333 #ifdef __INT40_C_SUFFIX__
334 #define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__)
335 #define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__)
336 #define __int32_c_suffix __INT40_C_SUFFIX__
337 #define __int16_c_suffix __INT40_C_SUFFIX__
338 #define __int8_c_suffix __INT40_C_SUFFIX__
339 #else
340 #define INT40_C(v) v
341 #define UINT40_C(v) v##U
342 #endif /* __INT40_C_SUFFIX__ */
343 #endif /* __INT40_TYPE__ */
345 #ifdef __INT32_TYPE__
346 #undef __int32_c_suffix
347 #undef __int16_c_suffix
348 #undef __int8_c_suffix
349 #ifdef __INT32_C_SUFFIX__
350 #define __int32_c_suffix __INT32_C_SUFFIX__
351 #define __int16_c_suffix __INT32_C_SUFFIX__
352 #define __int8_c_suffix __INT32_C_SUFFIX__
353 #endif /* __INT32_C_SUFFIX__ */
354 #endif /* __INT32_TYPE__ */
356 #ifdef __int_least32_t
357 #ifdef __int32_c_suffix
358 #define INT32_C(v) __int_c(v, __int32_c_suffix)
359 #define UINT32_C(v) __uint_c(v, __int32_c_suffix)
360 #else
361 #define INT32_C(v) v
362 #define UINT32_C(v) v##U
363 #endif /* __int32_c_suffix */
364 #endif /* __int_least32_t */
366 #ifdef __INT24_TYPE__
367 #undef __int16_c_suffix
368 #undef __int8_c_suffix
369 #ifdef __INT24_C_SUFFIX__
370 #define INT24_C(v) __int_c(v, __INT24_C_SUFFIX__)
371 #define UINT24_C(v) __uint_c(v, __INT24_C_SUFFIX__)
372 #define __int16_c_suffix __INT24_C_SUFFIX__
373 #define __int8_c_suffix __INT24_C_SUFFIX__
374 #else
375 #define INT24_C(v) v
376 #define UINT24_C(v) v##U
377 #endif /* __INT24_C_SUFFIX__ */
378 #endif /* __INT24_TYPE__ */
380 #ifdef __INT16_TYPE__
381 #undef __int16_c_suffix
382 #undef __int8_c_suffix
383 #ifdef __INT16_C_SUFFIX__
384 #define __int16_c_suffix __INT16_C_SUFFIX__
385 #define __int8_c_suffix __INT16_C_SUFFIX__
386 #endif /* __INT16_C_SUFFIX__ */
387 #endif /* __INT16_TYPE__ */
389 #ifdef __int_least16_t
390 #ifdef __int16_c_suffix
391 #define INT16_C(v) __int_c(v, __int16_c_suffix)
392 #define UINT16_C(v) __uint_c(v, __int16_c_suffix)
393 #else
394 #define INT16_C(v) v
395 #define UINT16_C(v) v##U
396 #endif /* __int16_c_suffix */
397 #endif /* __int_least16_t */
399 #ifdef __INT8_TYPE__
400 #undef __int8_c_suffix
401 #ifdef __INT8_C_SUFFIX__
402 #define __int8_c_suffix __INT8_C_SUFFIX__
403 #endif /* __INT8_C_SUFFIX__ */
404 #endif /* __INT8_TYPE__ */
406 #ifdef __int_least8_t
407 #ifdef __int8_c_suffix
408 #define INT8_C(v) __int_c(v, __int8_c_suffix)
409 #define UINT8_C(v) __uint_c(v, __int8_c_suffix)
410 #else
411 #define INT8_C(v) v
412 #define UINT8_C(v) v##U
413 #endif /* __int8_c_suffix */
414 #endif /* __int_least8_t */
416 /* C99 7.18.2.1 Limits of exact-width integer types.
417 * C99 7.18.2.2 Limits of minimum-width integer types.
418 * C99 7.18.2.3 Limits of fastest minimum-width integer types.
420 * The presence of limit macros are completely optional in C99. This
421 * implementation defines limits for all of the types (exact- and
422 * minimum-width) that it defines above, using the limits of the minimum-width
423 * type for any types that do not have exact-width representations.
425 * As in the type definitions, this section takes an approach of
426 * successive-shrinking to determine which limits to use for the standard (8,
427 * 16, 32, 64) bit widths when they don't have exact representations. It is
428 * therefore important that the definitions be kept in order of decending
429 * widths.
431 * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the
432 * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
435 #ifdef __INT64_TYPE__
436 #define INT64_MAX INT64_C(9223372036854775807)
437 #define INT64_MIN (-INT64_C(9223372036854775807) - 1)
438 #define UINT64_MAX UINT64_C(18446744073709551615)
440 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
441 #define UINT64_WIDTH 64
442 #define INT64_WIDTH UINT64_WIDTH
444 #define __UINT_LEAST64_WIDTH UINT64_WIDTH
445 #undef __UINT_LEAST32_WIDTH
446 #define __UINT_LEAST32_WIDTH UINT64_WIDTH
447 #undef __UINT_LEAST16_WIDTH
448 #define __UINT_LEAST16_WIDTH UINT64_WIDTH
449 #undef __UINT_LEAST8_MAX
450 #define __UINT_LEAST8_MAX UINT64_MAX
451 #endif /* __STDC_VERSION__ */
453 #define __INT_LEAST64_MIN INT64_MIN
454 #define __INT_LEAST64_MAX INT64_MAX
455 #define __UINT_LEAST64_MAX UINT64_MAX
456 #undef __INT_LEAST32_MIN
457 #define __INT_LEAST32_MIN INT64_MIN
458 #undef __INT_LEAST32_MAX
459 #define __INT_LEAST32_MAX INT64_MAX
460 #undef __UINT_LEAST32_MAX
461 #define __UINT_LEAST32_MAX UINT64_MAX
462 #undef __INT_LEAST16_MIN
463 #define __INT_LEAST16_MIN INT64_MIN
464 #undef __INT_LEAST16_MAX
465 #define __INT_LEAST16_MAX INT64_MAX
466 #undef __UINT_LEAST16_MAX
467 #define __UINT_LEAST16_MAX UINT64_MAX
468 #undef __INT_LEAST8_MIN
469 #define __INT_LEAST8_MIN INT64_MIN
470 #undef __INT_LEAST8_MAX
471 #define __INT_LEAST8_MAX INT64_MAX
472 #undef __UINT_LEAST8_MAX
473 #define __UINT_LEAST8_MAX UINT64_MAX
474 #endif /* __INT64_TYPE__ */
476 #ifdef __INT_LEAST64_MIN
477 #define INT_LEAST64_MIN __INT_LEAST64_MIN
478 #define INT_LEAST64_MAX __INT_LEAST64_MAX
479 #define UINT_LEAST64_MAX __UINT_LEAST64_MAX
480 #define INT_FAST64_MIN __INT_LEAST64_MIN
481 #define INT_FAST64_MAX __INT_LEAST64_MAX
482 #define UINT_FAST64_MAX __UINT_LEAST64_MAX
484 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
485 #define UINT_LEAST64_WIDTH __UINT_LEAST64_WIDTH
486 #define INT_LEAST64_WIDTH UINT_LEAST64_WIDTH
487 #define UINT_FAST64_WIDTH __UINT_LEAST64_WIDTH
488 #define INT_FAST64_WIDTH UINT_FAST64_WIDTH
489 #endif /* __STDC_VERSION__ */
490 #endif /* __INT_LEAST64_MIN */
492 #ifdef __INT56_TYPE__
493 #define INT56_MAX INT56_C(36028797018963967)
494 #define INT56_MIN (-INT56_C(36028797018963967) - 1)
495 #define UINT56_MAX UINT56_C(72057594037927935)
496 #define INT_LEAST56_MIN INT56_MIN
497 #define INT_LEAST56_MAX INT56_MAX
498 #define UINT_LEAST56_MAX UINT56_MAX
499 #define INT_FAST56_MIN INT56_MIN
500 #define INT_FAST56_MAX INT56_MAX
501 #define UINT_FAST56_MAX UINT56_MAX
503 #undef __INT_LEAST32_MIN
504 #define __INT_LEAST32_MIN INT56_MIN
505 #undef __INT_LEAST32_MAX
506 #define __INT_LEAST32_MAX INT56_MAX
507 #undef __UINT_LEAST32_MAX
508 #define __UINT_LEAST32_MAX UINT56_MAX
509 #undef __INT_LEAST16_MIN
510 #define __INT_LEAST16_MIN INT56_MIN
511 #undef __INT_LEAST16_MAX
512 #define __INT_LEAST16_MAX INT56_MAX
513 #undef __UINT_LEAST16_MAX
514 #define __UINT_LEAST16_MAX UINT56_MAX
515 #undef __INT_LEAST8_MIN
516 #define __INT_LEAST8_MIN INT56_MIN
517 #undef __INT_LEAST8_MAX
518 #define __INT_LEAST8_MAX INT56_MAX
519 #undef __UINT_LEAST8_MAX
520 #define __UINT_LEAST8_MAX UINT56_MAX
522 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
523 #define UINT56_WIDTH 56
524 #define INT56_WIDTH UINT56_WIDTH
525 #define UINT_LEAST56_WIDTH UINT56_WIDTH
526 #define INT_LEAST56_WIDTH UINT_LEAST56_WIDTH
527 #define UINT_FAST56_WIDTH UINT56_WIDTH
528 #define INT_FAST56_WIDTH UINT_FAST56_WIDTH
529 #undef __UINT_LEAST32_WIDTH
530 #define __UINT_LEAST32_WIDTH UINT56_WIDTH
531 #undef __UINT_LEAST16_WIDTH
532 #define __UINT_LEAST16_WIDTH UINT56_WIDTH
533 #undef __UINT_LEAST8_WIDTH
534 #define __UINT_LEAST8_WIDTH UINT56_WIDTH
535 #endif /* __STDC_VERSION__ */
536 #endif /* __INT56_TYPE__ */
538 #ifdef __INT48_TYPE__
539 #define INT48_MAX INT48_C(140737488355327)
540 #define INT48_MIN (-INT48_C(140737488355327) - 1)
541 #define UINT48_MAX UINT48_C(281474976710655)
542 #define INT_LEAST48_MIN INT48_MIN
543 #define INT_LEAST48_MAX INT48_MAX
544 #define UINT_LEAST48_MAX UINT48_MAX
545 #define INT_FAST48_MIN INT48_MIN
546 #define INT_FAST48_MAX INT48_MAX
547 #define UINT_FAST48_MAX UINT48_MAX
549 #undef __INT_LEAST32_MIN
550 #define __INT_LEAST32_MIN INT48_MIN
551 #undef __INT_LEAST32_MAX
552 #define __INT_LEAST32_MAX INT48_MAX
553 #undef __UINT_LEAST32_MAX
554 #define __UINT_LEAST32_MAX UINT48_MAX
555 #undef __INT_LEAST16_MIN
556 #define __INT_LEAST16_MIN INT48_MIN
557 #undef __INT_LEAST16_MAX
558 #define __INT_LEAST16_MAX INT48_MAX
559 #undef __UINT_LEAST16_MAX
560 #define __UINT_LEAST16_MAX UINT48_MAX
561 #undef __INT_LEAST8_MIN
562 #define __INT_LEAST8_MIN INT48_MIN
563 #undef __INT_LEAST8_MAX
564 #define __INT_LEAST8_MAX INT48_MAX
565 #undef __UINT_LEAST8_MAX
566 #define __UINT_LEAST8_MAX UINT48_MAX
568 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
569 #define UINT48_WIDTH 48
570 #define INT48_WIDTH UINT48_WIDTH
571 #define UINT_LEAST48_WIDTH UINT48_WIDTH
572 #define INT_LEAST48_WIDTH UINT_LEAST48_WIDTH
573 #define UINT_FAST48_WIDTH UINT48_WIDTH
574 #define INT_FAST48_WIDTH UINT_FAST48_WIDTH
575 #undef __UINT_LEAST32_WIDTH
576 #define __UINT_LEAST32_WIDTH UINT48_WIDTH
577 #undef __UINT_LEAST16_WIDTH
578 #define __UINT_LEAST16_WIDTH UINT48_WIDTH
579 #undef __UINT_LEAST8_WIDTH
580 #define __UINT_LEAST8_WIDTH UINT48_WIDTH
581 #endif /* __STDC_VERSION__ */
582 #endif /* __INT48_TYPE__ */
584 #ifdef __INT40_TYPE__
585 #define INT40_MAX INT40_C(549755813887)
586 #define INT40_MIN (-INT40_C(549755813887) - 1)
587 #define UINT40_MAX UINT40_C(1099511627775)
588 #define INT_LEAST40_MIN INT40_MIN
589 #define INT_LEAST40_MAX INT40_MAX
590 #define UINT_LEAST40_MAX UINT40_MAX
591 #define INT_FAST40_MIN INT40_MIN
592 #define INT_FAST40_MAX INT40_MAX
593 #define UINT_FAST40_MAX UINT40_MAX
595 #undef __INT_LEAST32_MIN
596 #define __INT_LEAST32_MIN INT40_MIN
597 #undef __INT_LEAST32_MAX
598 #define __INT_LEAST32_MAX INT40_MAX
599 #undef __UINT_LEAST32_MAX
600 #define __UINT_LEAST32_MAX UINT40_MAX
601 #undef __INT_LEAST16_MIN
602 #define __INT_LEAST16_MIN INT40_MIN
603 #undef __INT_LEAST16_MAX
604 #define __INT_LEAST16_MAX INT40_MAX
605 #undef __UINT_LEAST16_MAX
606 #define __UINT_LEAST16_MAX UINT40_MAX
607 #undef __INT_LEAST8_MIN
608 #define __INT_LEAST8_MIN INT40_MIN
609 #undef __INT_LEAST8_MAX
610 #define __INT_LEAST8_MAX INT40_MAX
611 #undef __UINT_LEAST8_MAX
612 #define __UINT_LEAST8_MAX UINT40_MAX
614 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
615 #define UINT40_WIDTH 40
616 #define INT40_WIDTH UINT40_WIDTH
617 #define UINT_LEAST40_WIDTH UINT40_WIDTH
618 #define INT_LEAST40_WIDTH UINT_LEAST40_WIDTH
619 #define UINT_FAST40_WIDTH UINT40_WIDTH
620 #define INT_FAST40_WIDTH UINT_FAST40_WIDTH
621 #undef __UINT_LEAST32_WIDTH
622 #define __UINT_LEAST32_WIDTH UINT40_WIDTH
623 #undef __UINT_LEAST16_WIDTH
624 #define __UINT_LEAST16_WIDTH UINT40_WIDTH
625 #undef __UINT_LEAST8_WIDTH
626 #define __UINT_LEAST8_WIDTH UINT40_WIDTH
627 #endif /* __STDC_VERSION__ */
628 #endif /* __INT40_TYPE__ */
630 #ifdef __INT32_TYPE__
631 #define INT32_MAX INT32_C(2147483647)
632 #define INT32_MIN (-INT32_C(2147483647) - 1)
633 #define UINT32_MAX UINT32_C(4294967295)
635 #undef __INT_LEAST32_MIN
636 #define __INT_LEAST32_MIN INT32_MIN
637 #undef __INT_LEAST32_MAX
638 #define __INT_LEAST32_MAX INT32_MAX
639 #undef __UINT_LEAST32_MAX
640 #define __UINT_LEAST32_MAX UINT32_MAX
641 #undef __INT_LEAST16_MIN
642 #define __INT_LEAST16_MIN INT32_MIN
643 #undef __INT_LEAST16_MAX
644 #define __INT_LEAST16_MAX INT32_MAX
645 #undef __UINT_LEAST16_MAX
646 #define __UINT_LEAST16_MAX UINT32_MAX
647 #undef __INT_LEAST8_MIN
648 #define __INT_LEAST8_MIN INT32_MIN
649 #undef __INT_LEAST8_MAX
650 #define __INT_LEAST8_MAX INT32_MAX
651 #undef __UINT_LEAST8_MAX
652 #define __UINT_LEAST8_MAX UINT32_MAX
654 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
655 #define UINT32_WIDTH 32
656 #define INT32_WIDTH UINT32_WIDTH
657 #undef __UINT_LEAST32_WIDTH
658 #define __UINT_LEAST32_WIDTH UINT32_WIDTH
659 #undef __UINT_LEAST16_WIDTH
660 #define __UINT_LEAST16_WIDTH UINT32_WIDTH
661 #undef __UINT_LEAST8_WIDTH
662 #define __UINT_LEAST8_WIDTH UINT32_WIDTH
663 #endif /* __STDC_VERSION__ */
664 #endif /* __INT32_TYPE__ */
666 #ifdef __INT_LEAST32_MIN
667 #define INT_LEAST32_MIN __INT_LEAST32_MIN
668 #define INT_LEAST32_MAX __INT_LEAST32_MAX
669 #define UINT_LEAST32_MAX __UINT_LEAST32_MAX
670 #define INT_FAST32_MIN __INT_LEAST32_MIN
671 #define INT_FAST32_MAX __INT_LEAST32_MAX
672 #define UINT_FAST32_MAX __UINT_LEAST32_MAX
674 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
675 #define UINT_LEAST32_WIDTH __UINT_LEAST32_WIDTH
676 #define INT_LEAST32_WIDTH UINT_LEAST32_WIDTH
677 #define UINT_FAST32_WIDTH __UINT_LEAST32_WIDTH
678 #define INT_FAST32_WIDTH UINT_FAST32_WIDTH
679 #endif /* __STDC_VERSION__ */
680 #endif /* __INT_LEAST32_MIN */
682 #ifdef __INT24_TYPE__
683 #define INT24_MAX INT24_C(8388607)
684 #define INT24_MIN (-INT24_C(8388607) - 1)
685 #define UINT24_MAX UINT24_C(16777215)
686 #define INT_LEAST24_MIN INT24_MIN
687 #define INT_LEAST24_MAX INT24_MAX
688 #define UINT_LEAST24_MAX UINT24_MAX
689 #define INT_FAST24_MIN INT24_MIN
690 #define INT_FAST24_MAX INT24_MAX
691 #define UINT_FAST24_MAX UINT24_MAX
693 #undef __INT_LEAST16_MIN
694 #define __INT_LEAST16_MIN INT24_MIN
695 #undef __INT_LEAST16_MAX
696 #define __INT_LEAST16_MAX INT24_MAX
697 #undef __UINT_LEAST16_MAX
698 #define __UINT_LEAST16_MAX UINT24_MAX
699 #undef __INT_LEAST8_MIN
700 #define __INT_LEAST8_MIN INT24_MIN
701 #undef __INT_LEAST8_MAX
702 #define __INT_LEAST8_MAX INT24_MAX
703 #undef __UINT_LEAST8_MAX
704 #define __UINT_LEAST8_MAX UINT24_MAX
706 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
707 #define UINT24_WIDTH 24
708 #define INT24_WIDTH UINT24_WIDTH
709 #define UINT_LEAST24_WIDTH UINT24_WIDTH
710 #define INT_LEAST24_WIDTH UINT_LEAST24_WIDTH
711 #define UINT_FAST24_WIDTH UINT24_WIDTH
712 #define INT_FAST24_WIDTH UINT_FAST24_WIDTH
713 #undef __UINT_LEAST16_WIDTH
714 #define __UINT_LEAST16_WIDTH UINT24_WIDTH
715 #undef __UINT_LEAST8_WIDTH
716 #define __UINT_LEAST8_WIDTH UINT24_WIDTH
717 #endif /* __STDC_VERSION__ */
718 #endif /* __INT24_TYPE__ */
720 #ifdef __INT16_TYPE__
721 #define INT16_MAX INT16_C(32767)
722 #define INT16_MIN (-INT16_C(32767) - 1)
723 #define UINT16_MAX UINT16_C(65535)
725 #undef __INT_LEAST16_MIN
726 #define __INT_LEAST16_MIN INT16_MIN
727 #undef __INT_LEAST16_MAX
728 #define __INT_LEAST16_MAX INT16_MAX
729 #undef __UINT_LEAST16_MAX
730 #define __UINT_LEAST16_MAX UINT16_MAX
731 #undef __INT_LEAST8_MIN
732 #define __INT_LEAST8_MIN INT16_MIN
733 #undef __INT_LEAST8_MAX
734 #define __INT_LEAST8_MAX INT16_MAX
735 #undef __UINT_LEAST8_MAX
736 #define __UINT_LEAST8_MAX UINT16_MAX
738 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
739 #define UINT16_WIDTH 16
740 #define INT16_WIDTH UINT16_WIDTH
741 #undef __UINT_LEAST16_WIDTH
742 #define __UINT_LEAST16_WIDTH UINT16_WIDTH
743 #undef __UINT_LEAST8_WIDTH
744 #define __UINT_LEAST8_WIDTH UINT16_WIDTH
745 #endif /* __STDC_VERSION__ */
746 #endif /* __INT16_TYPE__ */
748 #ifdef __INT_LEAST16_MIN
749 #define INT_LEAST16_MIN __INT_LEAST16_MIN
750 #define INT_LEAST16_MAX __INT_LEAST16_MAX
751 #define UINT_LEAST16_MAX __UINT_LEAST16_MAX
752 #define INT_FAST16_MIN __INT_LEAST16_MIN
753 #define INT_FAST16_MAX __INT_LEAST16_MAX
754 #define UINT_FAST16_MAX __UINT_LEAST16_MAX
756 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
757 #define UINT_LEAST16_WIDTH __UINT_LEAST16_WIDTH
758 #define INT_LEAST16_WIDTH UINT_LEAST16_WIDTH
759 #define UINT_FAST16_WIDTH __UINT_LEAST16_WIDTH
760 #define INT_FAST16_WIDTH UINT_FAST16_WIDTH
761 #endif /* __STDC_VERSION__ */
762 #endif /* __INT_LEAST16_MIN */
764 #ifdef __INT8_TYPE__
765 #define INT8_MAX INT8_C(127)
766 #define INT8_MIN (-INT8_C(127) - 1)
767 #define UINT8_MAX UINT8_C(255)
769 #undef __INT_LEAST8_MIN
770 #define __INT_LEAST8_MIN INT8_MIN
771 #undef __INT_LEAST8_MAX
772 #define __INT_LEAST8_MAX INT8_MAX
773 #undef __UINT_LEAST8_MAX
774 #define __UINT_LEAST8_MAX UINT8_MAX
776 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
777 #define UINT8_WIDTH 8
778 #define INT8_WIDTH UINT8_WIDTH
779 #undef __UINT_LEAST8_WIDTH
780 #define __UINT_LEAST8_WIDTH UINT8_WIDTH
781 #endif /* __STDC_VERSION__ */
782 #endif /* __INT8_TYPE__ */
784 #ifdef __INT_LEAST8_MIN
785 #define INT_LEAST8_MIN __INT_LEAST8_MIN
786 #define INT_LEAST8_MAX __INT_LEAST8_MAX
787 #define UINT_LEAST8_MAX __UINT_LEAST8_MAX
788 #define INT_FAST8_MIN __INT_LEAST8_MIN
789 #define INT_FAST8_MAX __INT_LEAST8_MAX
790 #define UINT_FAST8_MAX __UINT_LEAST8_MAX
792 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
793 #define UINT_LEAST8_WIDTH __UINT_LEAST8_WIDTH
794 #define INT_LEAST8_WIDTH UINT_LEAST8_WIDTH
795 #define UINT_FAST8_WIDTH __UINT_LEAST8_WIDTH
796 #define INT_FAST8_WIDTH UINT_FAST8_WIDTH
797 #endif /* __STDC_VERSION__ */
798 #endif /* __INT_LEAST8_MIN */
800 /* Some utility macros */
801 #define __INTN_MIN(n) __stdint_join3(INT, n, _MIN)
802 #define __INTN_MAX(n) __stdint_join3(INT, n, _MAX)
803 #define __UINTN_MAX(n) __stdint_join3(UINT, n, _MAX)
804 #define __INTN_C(n, v) __stdint_join3(INT, n, _C(v))
805 #define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v))
807 /* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */
808 /* C99 7.18.3 Limits of other integer types. */
810 #define INTPTR_MIN (-__INTPTR_MAX__ - 1)
811 #define INTPTR_MAX __INTPTR_MAX__
812 #define UINTPTR_MAX __UINTPTR_MAX__
813 #define PTRDIFF_MIN (-__PTRDIFF_MAX__ - 1)
814 #define PTRDIFF_MAX __PTRDIFF_MAX__
815 #define SIZE_MAX __SIZE_MAX__
817 /* C23 7.22.2.4 Width of integer types capable of holding object pointers. */
818 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
819 /* NB: The C standard requires that these be the same value, but the compiler
820 exposes separate internal width macros. */
821 #define INTPTR_WIDTH __INTPTR_WIDTH__
822 #define UINTPTR_WIDTH __UINTPTR_WIDTH__
823 #endif
825 /* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__
826 * is enabled. */
827 #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
828 #define RSIZE_MAX (SIZE_MAX >> 1)
829 #endif
831 /* C99 7.18.2.5 Limits of greatest-width integer types. */
832 #define INTMAX_MIN (-__INTMAX_MAX__ - 1)
833 #define INTMAX_MAX __INTMAX_MAX__
834 #define UINTMAX_MAX __UINTMAX_MAX__
836 /* C23 7.22.2.5 Width of greatest-width integer types. */
837 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
838 /* NB: The C standard requires that these be the same value, but the compiler
839 exposes separate internal width macros. */
840 #define INTMAX_WIDTH __INTMAX_WIDTH__
841 #define UINTMAX_WIDTH __UINTMAX_WIDTH__
842 #endif
844 /* C99 7.18.3 Limits of other integer types. */
845 #define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__)
846 #define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__)
847 #ifdef __WINT_UNSIGNED__
848 #define WINT_MIN __UINTN_C(__WINT_WIDTH__, 0)
849 #define WINT_MAX __UINTN_MAX(__WINT_WIDTH__)
850 #else
851 #define WINT_MIN __INTN_MIN(__WINT_WIDTH__)
852 #define WINT_MAX __INTN_MAX(__WINT_WIDTH__)
853 #endif
855 #ifndef WCHAR_MAX
856 #define WCHAR_MAX __WCHAR_MAX__
857 #endif
858 #ifndef WCHAR_MIN
859 #if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__)
860 #define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__)
861 #else
862 #define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0)
863 #endif
864 #endif
866 /* 7.18.4.2 Macros for greatest-width integer constants. */
867 #define INTMAX_C(v) __int_c(v, __INTMAX_C_SUFFIX__)
868 #define UINTMAX_C(v) __int_c(v, __UINTMAX_C_SUFFIX__)
870 /* C23 7.22.3.x Width of other integer types. */
871 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
872 #define PTRDIFF_WIDTH __PTRDIFF_WIDTH__
873 #define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__
874 #define SIZE_WIDTH __SIZE_WIDTH__
875 #define WCHAR_WIDTH __WCHAR_WIDTH__
876 #define WINT_WIDTH __WINT_WIDTH__
877 #endif
878 #endif // LLVM_LIBC_MACROS_STDINT_MACROS_H