[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Headers / stdint.c
blobe8b193785ff085efd1784a3b4c928c3e1bb08eac
1 // RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify -std=c17 %s
2 // RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify -std=c2x %s
3 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=aarch64-none-none
4 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=arm-none-none
5 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=i386-none-none
6 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=mips-none-none
7 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=mips64-none-none
8 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=msp430-none-none
9 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=powerpc64-none-none
10 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=powerpc64-none-netbsd
11 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=powerpc-none-none
12 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=s390x-none-none
13 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=sparc-none-none
14 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=tce-none-none
15 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=x86_64-none-none
16 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=x86_64-pc-linux-gnu
17 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=i386-mingw32
18 // RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=xcore-none-none
19 // expected-no-diagnostics
21 #include <stdint.h>
23 #if __STDC_VERSION__ >= 202311L
24 /* Validate the standard requirements. */
25 _Static_assert(SIG_ATOMIC_WIDTH >= 8);
26 _Static_assert(SIZE_WIDTH >= 16);
27 _Static_assert(SIZE_WIDTH / __CHAR_BIT__ == sizeof(sizeof(0)));
28 _Static_assert(WCHAR_WIDTH >= 8);
29 _Static_assert(WCHAR_WIDTH / __CHAR_BIT__ == sizeof(L't'));
30 _Static_assert(WINT_WIDTH >= 16);
31 _Static_assert(UINTPTR_WIDTH >= 16);
32 _Static_assert(UINTPTR_WIDTH / __CHAR_BIT__ == sizeof(uintptr_t));
33 _Static_assert(INTPTR_WIDTH == UINTPTR_WIDTH);
34 _Static_assert(INTPTR_WIDTH / __CHAR_BIT__ == sizeof(intptr_t));
36 /* FIXME: the TCE target is not a conforming C target because it defines these
37 values to be less than 64. */
38 #if !defined(__TCE__)
39 _Static_assert(UINTMAX_WIDTH >= 64);
40 _Static_assert(UINTMAX_WIDTH / __CHAR_BIT__ == sizeof(uintmax_t));
41 _Static_assert(INTMAX_WIDTH == UINTMAX_WIDTH);
42 _Static_assert(INTMAX_WIDTH / __CHAR_BIT__ == sizeof(intmax_t));
43 #endif
45 /* NB: WG14 N2412 set this to 17, but WG14 N2808 set it back to 16. */
46 _Static_assert(PTRDIFF_WIDTH >= 16);
47 #else
48 /* None of these are defined. */
49 int PTRDIFF_WIDTH, SIG_ATOMIC_WIDTH, SIZE_WIDTH, WCHAR_WIDTH, WINT_WIDTH,
50 INTPTR_WIDTH, UINTPTR_WIDTH, INTMAX_WIDTH, UINTMAX_WIDTH;
51 #endif
53 #if defined(INT8_MAX) && __STDC_VERSION__ >= 202311L
54 _Static_assert(INT8_WIDTH == 8, "");
55 _Static_assert(UINT8_WIDTH == INT8_WIDTH, "");
56 _Static_assert(INT8_WIDTH / __CHAR_BIT__ == sizeof(int8_t), "");
57 _Static_assert(UINT8_WIDTH / __CHAR_BIT__ == sizeof(uint8_t), "");
58 #else
59 int INT8_WIDTH, UINT8_WIDTH; /* None of these are defined. */
60 #endif
61 #if defined(INT_LEAST8_MAX) && __STDC_VERSION__ >= 202311L
62 _Static_assert(INT_LEAST8_WIDTH >= 8, "");
63 _Static_assert(INT_LEAST8_WIDTH / __CHAR_BIT__ == sizeof(int_least8_t), "");
64 _Static_assert(UINT_LEAST8_WIDTH == INT_LEAST8_WIDTH, "");
65 _Static_assert(UINT_LEAST8_WIDTH / __CHAR_BIT__ == sizeof(uint_least8_t), "");
66 #else
67 int INT_LEAST8_WIDTH, UINT_LEAST8_WIDTH; /* None of these are defined. */
68 #endif
69 #if defined(INT_FAST8_MAX) && __STDC_VERSION__ >= 202311L
70 _Static_assert(INT_FAST8_WIDTH >= 8, "");
71 _Static_assert(INT_FAST8_WIDTH / __CHAR_BIT__ == sizeof(int_fast8_t), "");
72 _Static_assert(UINT_FAST8_WIDTH == INT_FAST8_WIDTH, "");
73 _Static_assert(UINT_FAST8_WIDTH / __CHAR_BIT__ == sizeof(uint_fast8_t), "");
74 #else
75 int INT_FAST8_WIDTH, UINT_FAST8_WIDTH; /* None of these are defined. */
76 #endif
78 #if defined(INT16_MAX) && __STDC_VERSION__ >= 202311L
79 _Static_assert(INT16_WIDTH == 16, "");
80 _Static_assert(UINT16_WIDTH == INT16_WIDTH, "");
81 _Static_assert(INT16_WIDTH / __CHAR_BIT__ == sizeof(int16_t), "");
82 _Static_assert(UINT16_WIDTH / __CHAR_BIT__ == sizeof(uint16_t), "");
83 #else
84 int INT16_WIDTH, UINT16_WIDTH; /* None of these are defined. */
85 #endif
86 #if defined(INT_LEAST16_MAX) && __STDC_VERSION__ >= 202311L
87 _Static_assert(INT_LEAST16_WIDTH >= 16, "");
88 _Static_assert(INT_LEAST16_WIDTH / __CHAR_BIT__ == sizeof(int_least16_t), "");
89 _Static_assert(UINT_LEAST16_WIDTH == INT_LEAST16_WIDTH, "");
90 _Static_assert(UINT_LEAST16_WIDTH / __CHAR_BIT__ == sizeof(uint_least16_t), "");
91 #else
92 int INT_LEAST16_WIDTH, UINT_LEAST16_WIDTH; /* None of these are defined. */
93 #endif
94 #if defined(INT_FAST16_MAX) && __STDC_VERSION__ >= 202311L
95 _Static_assert(INT_FAST16_WIDTH >= 16, "");
96 _Static_assert(INT_FAST16_WIDTH / __CHAR_BIT__ == sizeof(int_fast16_t), "");
97 _Static_assert(UINT_FAST16_WIDTH == INT_FAST16_WIDTH, "");
98 _Static_assert(UINT_FAST16_WIDTH / __CHAR_BIT__ == sizeof(int_fast16_t), "");
99 #else
100 int INT_FAST16_WIDTH, UINT_FAST16_WIDTH; /* None of these are defined. */
101 #endif
103 #if defined(INT24_MAX) && __STDC_VERSION__ >= 202311L
104 _Static_assert(INT24_WIDTH == 24, "");
105 _Static_assert(UINT24_WIDTH == INT24_WIDTH, "");
106 _Static_assert(INT24_WIDTH / __CHAR_BIT__ == sizeof(int24_t), "");
107 _Static_assert(UINT24_WIDTH / __CHAR_BIT__ == sizeof(uint24_t), "");
108 #else
109 int INT24_WIDTH, UINT24_WIDTH; /* None of these are defined. */
110 #endif
111 #if defined(INT_LEAST24_MAX) && __STDC_VERSION__ >= 202311L
112 _Static_assert(INT_LEAST24_WIDTH >= 24, "");
113 _Static_assert(INT_LEAST24_WIDTH / __CHAR_BIT__ == sizeof(int_least24_t), "");
114 _Static_assert(UINT_LEAST24_WIDTH == INT_LEAST24_WIDTH, "");
115 _Static_assert(UINT_LEAST24_WIDTH / __CHAR_BIT__ == sizeof(uint_least24_t), "");
116 #else
117 int INT_LEAST24_WIDTH, UINT_LEAST24_WIDTH; /* None of these are defined. */
118 #endif
119 #if defined(INT_FAST24_MAX) && __STDC_VERSION__ >= 202311L
120 _Static_assert(INT_FAST24_WIDTH >= 24, "");
121 _Static_assert(INT_FAST24_WIDTH / __CHAR_BIT__ == sizeof(int_fast24_t), "");
122 _Static_assert(UINT_FAST24_WIDTH == INT_FAST24_WIDTH, "");
123 _Static_assert(UINT_FAST24_WIDTH / __CHAR_BIT__ == sizeof(uint_fast24_t), "");
124 #else
125 int INT_FAST24_WIDTH, UINT_FAST24_WIDTH; /* None of these are defined. */
126 #endif
128 #if defined(INT32_MAX) && __STDC_VERSION__ >= 202311L
129 _Static_assert(INT32_WIDTH == 32, "");
130 _Static_assert(UINT32_WIDTH == INT32_WIDTH, "");
131 _Static_assert(INT32_WIDTH / __CHAR_BIT__ == sizeof(int32_t), "");
132 _Static_assert(UINT32_WIDTH / __CHAR_BIT__ == sizeof(uint32_t), "");
133 #else
134 int INT32_WIDTH, UINT32_WIDTH; /* None of these are defined. */
135 #endif
136 #if defined(INT_LEAST32_MAX) && __STDC_VERSION__ >= 202311L
137 _Static_assert(INT_LEAST32_WIDTH >= 32, "");
138 _Static_assert(INT_LEAST32_WIDTH / __CHAR_BIT__ == sizeof(int_least32_t), "");
139 _Static_assert(UINT_LEAST32_WIDTH == INT_LEAST32_WIDTH, "");
140 _Static_assert(UINT_LEAST32_WIDTH / __CHAR_BIT__ == sizeof(uint_least32_t), "");
141 #else
142 int INT_LEAST32_WIDTH, UINT_LEAST32_WIDTH; /* None of these are defined. */
143 #endif
144 #if defined(INT_FAST32_MAX) && __STDC_VERSION__ >= 202311L
145 _Static_assert(INT_FAST32_WIDTH >= 32, "");
146 _Static_assert(INT_FAST32_WIDTH / __CHAR_BIT__ == sizeof(int_fast32_t), "");
147 _Static_assert(UINT_FAST32_WIDTH == INT_FAST32_WIDTH, "");
148 _Static_assert(UINT_FAST32_WIDTH / __CHAR_BIT__ == sizeof(uint_fast32_t), "");
149 #else
150 int INT_FAST32_WIDTH, UINT_FAST32_WIDTH; /* None of these are defined. */
151 #endif
153 #if defined(INT40_MAX) && __STDC_VERSION__ >= 202311L
154 _Static_assert(INT40_WIDTH == 40, "");
155 _Static_assert(UINT40_WIDTH == INT40_WIDTH, "");
156 _Static_assert(INT40_WIDTH / __CHAR_BIT__ == sizeof(int40_t), "");
157 _Static_assert(UINT40_WIDTH / __CHAR_BIT__ == sizeof(uint40_t), "");
158 #else
159 int INT40_WIDTH, UINT40_WIDTH; /* None of these are defined. */
160 #endif
161 #if defined(INT_LEAST40_MAX) && __STDC_VERSION__ >= 202311L
162 _Static_assert(INT_LEAST40_WIDTH >= 40, "");
163 _Static_assert(INT_LEAST40_WIDTH / __CHAR_BIT__ == sizeof(int_least40_t), "");
164 _Static_assert(UINT_LEAST40_WIDTH == INT_LEAST40_WIDTH, "");
165 _Static_assert(UINT_LEAST40_WIDTH / __CHAR_BIT__ == sizeof(int_least40_t), "");
166 #else
167 int INT_LEAST40_WIDTH, UINT_LEAST40_WIDTH; /* None of these are defined. */
168 #endif
169 #if defined(INT_FAST40_MAX) && __STDC_VERSION__ >= 202311L
170 _Static_assert(INT_FAST40_WIDTH >= 40, "");
171 _Static_assert(INT_FAST40_WIDTH / __CHAR_BIT__ == sizeof(int_fast40_t), "");
172 _Static_assert(UINT_FAST40_WIDTH == INT_FAST40_WIDTH, "");
173 _Static_assert(UINT_FAST40_WIDTH / __CHAR_BIT__ == sizeof(uint_fast40_t), "");
174 #else
175 int INT_FAST40_WIDTH, UINT_FAST40_WIDTH; /* None of these are defined. */
176 #endif
178 #if defined(INT48_MAX) && __STDC_VERSION__ >= 202311L
179 _Static_assert(INT48_WIDTH == 48, "");
180 _Static_assert(UINT48_WIDTH == INT48_WIDTH, "");
181 _Static_assert(INT48_WIDTH / __CHAR_BIT__ == sizeof(int48_t), "");
182 _Static_assert(UINT48_WIDTH / __CHAR_BIT__ == sizeof(uint48_t), "");
183 #else
184 int INT48_WIDTH, UINT48_WIDTH; /* None of these are defined. */
185 #endif
186 #if defined(INT_LEAST48_MAX) && __STDC_VERSION__ >= 202311L
187 _Static_assert(INT_LEAST48_WIDTH >= 48, "");
188 _Static_assert(INT_LEAST48_WIDTH / __CHAR_BIT__ == sizeof(int_least48_t), "");
189 _Static_assert(UINT_LEAST48_WIDTH == INT_LEAST48_WIDTH, "");
190 _Static_assert(UINT_LEAST48_WIDTH / __CHAR_BIT__ == sizeof(int_least48_t), "");
191 #else
192 int INT_LEAST48_WIDTH, UINT_LEAST48_WIDTH; /* None of these are defined. */
193 #endif
194 #if defined(INT_FAST48_MAX) && __STDC_VERSION__ >= 202311L
195 _Static_assert(INT_FAST48_WIDTH >= 48, "");
196 _Static_assert(INT_FAST48_WIDTH / __CHAR_BIT__ == sizeof(int_fast48_t), "");
197 _Static_assert(UINT_FAST48_WIDTH == INT_FAST48_WIDTH, "");
198 _Static_assert(UINT_FAST48_WIDTH / __CHAR_BIT__ == sizeof(int_fast48_t), "");
199 #else
200 int INT_FAST48_WIDTH, UINT_FAST48_WIDTH; /* None of these are defined. */
201 #endif
203 #if defined(INT56_MAX) && __STDC_VERSION__ >= 202311L
204 _Static_assert(INT56_WIDTH == 56, "");
205 _Static_assert(UINT56_WIDTH == INT56_WIDTH, "");
206 _Static_assert(INT56_WIDTH / __CHAR_BIT__ == sizeof(int56_t), "");
207 _Static_assert(UINT56_WIDTH / __CHAR_BIT__ == sizeof(uint56_t), "");
208 #else
209 int INT56_WIDTH, UINT56_WIDTH; /* None of these are defined. */
210 #endif
211 #if defined(INT_LEAST56_MAX) && __STDC_VERSION__ >= 202311L
212 _Static_assert(INT_LEAST56_WIDTH >= 56, "");
213 _Static_assert(INT_LEAST56_WIDTH / __CHAR_BIT__ == sizeof(int_least56_t), "");
214 _Static_assert(UINT_LEAST56_WIDTH == INT_LEAST56_WIDTH, "");
215 _Static_assert(UINT_LEAST56_WIDTH / __CHAR_BIT__ == sizeof(int_least56_t), "");
216 #else
217 int INT_LEAST56_WIDTH, UINT_LEAST56_WIDTH; /* None of these are defined. */
218 #endif
219 #if defined(INT_FAST56_MAX) && __STDC_VERSION__ >= 202311L
220 _Static_assert(INT_FAST56_WIDTH >= 56, "");
221 _Static_assert(INT_FAST56_WIDTH / __CHAR_BIT__ == sizeof(int_fast56_t), "");
222 _Static_assert(UINT_FAST56_WIDTH == INT_FAST56_WIDTH, "");
223 _Static_assert(UINT_FAST56_WIDTH / __CHAR_BIT__ == sizeof(int_fast56_t), "");
224 #else
225 int INT_FAST56_WIDTH, UINT_FAST56_WIDTH; /* None of these are defined. */
226 #endif
228 #if defined(INT64_MAX) && __STDC_VERSION__ >= 202311L
229 _Static_assert(INT64_WIDTH == 64, "");
230 _Static_assert(UINT64_WIDTH == INT64_WIDTH, "");
231 _Static_assert(INT64_WIDTH / __CHAR_BIT__ == sizeof(int64_t), "");
232 _Static_assert(UINT64_WIDTH / __CHAR_BIT__ == sizeof(uint64_t), "");
233 #else
234 int INT64_WIDTH, UINT64_WIDTH; /* None of these are defined. */
235 #endif
236 #if defined(INT_LEAST64_MAX) && __STDC_VERSION__ >= 202311L
237 _Static_assert(INT_LEAST64_WIDTH >= 64, "");
238 _Static_assert(INT_LEAST64_WIDTH / __CHAR_BIT__ == sizeof(int_least64_t), "");
239 _Static_assert(UINT_LEAST64_WIDTH == INT_LEAST64_WIDTH, "");
240 _Static_assert(UINT_LEAST64_WIDTH / __CHAR_BIT__ == sizeof(int_least64_t), "");
241 #else
242 int INT_LEAST64_WIDTH, UINT_LEAST64_WIDTH; /* None of these are defined. */
243 #endif
244 #if defined(INT_FAST64_MAX) && __STDC_VERSION__ >= 202311L
245 _Static_assert(INT_FAST64_WIDTH >= 64, "");
246 _Static_assert(INT_FAST64_WIDTH / __CHAR_BIT__ == sizeof(int_fast64_t), "");
247 _Static_assert(UINT_FAST64_WIDTH == INT_FAST64_WIDTH, "");
248 _Static_assert(UINT_FAST64_WIDTH / __CHAR_BIT__ == sizeof(int_fast64_t), "");
249 #else
250 int INT_FAST64_WIDTH, UINT_FAST64_WIDTH; /* None of these are defined. */
251 #endif