1 | // -*- C++ -*- |
2 | //===----------------------------------------------------------------------===// |
3 | // |
4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | // See https://llvm.org/LICENSE.txt for license information. |
6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | |
10 | #ifndef _LIBCPP___CONFIG |
11 | #define _LIBCPP___CONFIG |
12 | |
13 | #include <__config_site> |
14 | #include <__configuration/abi.h> |
15 | #include <__configuration/availability.h> |
16 | #include <__configuration/compiler.h> |
17 | #include <__configuration/language.h> |
18 | #include <__configuration/platform.h> |
19 | |
20 | #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER |
21 | # pragma GCC system_header |
22 | #endif |
23 | |
24 | #ifdef __cplusplus |
25 | |
26 | // The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html |
27 | |
28 | // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. |
29 | // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is |
30 | // defined to XXYYZZ. |
31 | # define _LIBCPP_VERSION 210000 |
32 | |
33 | # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y |
34 | # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) |
35 | # define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z)) |
36 | |
37 | # if __STDC_HOSTED__ == 0 |
38 | # define _LIBCPP_FREESTANDING |
39 | # endif |
40 | |
41 | // HARDENING { |
42 | |
43 | // TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated. |
44 | # ifdef _LIBCPP_ENABLE_ASSERTIONS |
45 | # error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead" |
46 | # endif |
47 | |
48 | // The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: |
49 | // |
50 | // - `_LIBCPP_HARDENING_MODE_NONE`; |
51 | // - `_LIBCPP_HARDENING_MODE_FAST`; |
52 | // - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; |
53 | // - `_LIBCPP_HARDENING_MODE_DEBUG`. |
54 | // |
55 | // These values have the following effects: |
56 | // |
57 | // - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; |
58 | // |
59 | // - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks |
60 | // that can be done with relatively little runtime overhead in constant time; |
61 | // |
62 | // - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of |
63 | // the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors |
64 | // but are not necessarily security-critical; |
65 | // |
66 | // - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive |
67 | // mode and enables all checks available in the library, including internal assertions. Checks that are part of the |
68 | // debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. |
69 | |
70 | // Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These |
71 | // macros are only for internal use -- users should only pick one of the high-level hardening modes described above. |
72 | // |
73 | // - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and |
74 | // a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: |
75 | // - the sentinel is reachable from the begin iterator; |
76 | // - TODO(hardening): both iterators refer to the same container. |
77 | // |
78 | // - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through |
79 | // the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access |
80 | // a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like |
81 | // `optional` and `function` are considered one-element containers for the purposes of this check. |
82 | // |
83 | // - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero |
84 | // address does not refer to an actual location in memory, so a null pointer dereference would not compromize the |
85 | // memory security of a program (however, it is still undefined behavior that can result in strange errors due to |
86 | // compiler optimizations). |
87 | // |
88 | // - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the |
89 | // given ranges do not overlap. |
90 | // |
91 | // - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object |
92 | // was allocated by the given allocator). Violating this category typically results in a memory leak. |
93 | // |
94 | // - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in |
95 | // an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like |
96 | // attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category |
97 | // (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or |
98 | // otherwise create an immediate security issue. |
99 | // |
100 | // - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure |
101 | // the containers have compatible allocators. |
102 | // |
103 | // - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments |
104 | // for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the |
105 | // original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g. |
106 | // a string view where only a subset of elements is possible to access). This category is for assertions violating |
107 | // which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the |
108 | // user code. |
109 | // |
110 | // - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to |
111 | // be benign in our implementation. |
112 | // |
113 | // - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed |
114 | // by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied; |
115 | // thus, this would often be a heuristic check and it might be quite expensive. |
116 | // |
117 | // - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on |
118 | // user input. |
119 | // |
120 | // - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. |
121 | |
122 | // clang-format off |
123 | # define _LIBCPP_HARDENING_MODE_NONE (1 << 1) |
124 | # define _LIBCPP_HARDENING_MODE_FAST (1 << 2) |
125 | # define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. |
126 | # define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) |
127 | // clang-format on |
128 | |
129 | # ifndef _LIBCPP_HARDENING_MODE |
130 | |
131 | # ifndef _LIBCPP_HARDENING_MODE_DEFAULT |
132 | # error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \ |
133 | `__config_site` header, please make sure your installation of libc++ is not broken. |
134 | # endif |
135 | |
136 | # define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT |
137 | # endif |
138 | |
139 | # if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \ |
140 | _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ |
141 | _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ |
142 | _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG |
143 | # error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ |
144 | _LIBCPP_HARDENING_MODE_NONE, \ |
145 | _LIBCPP_HARDENING_MODE_FAST, \ |
146 | _LIBCPP_HARDENING_MODE_EXTENSIVE, \ |
147 | _LIBCPP_HARDENING_MODE_DEBUG |
148 | # endif |
149 | |
150 | // } HARDENING |
151 | |
152 | # define _LIBCPP_TOSTRING2(x) #x |
153 | # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) |
154 | |
155 | // NOLINTNEXTLINE(libcpp-cpp-version-check) |
156 | # if __cplusplus < 201103L |
157 | # define _LIBCPP_CXX03_LANG |
158 | # endif |
159 | |
160 | # ifndef __has_constexpr_builtin |
161 | # define __has_constexpr_builtin(x) 0 |
162 | # endif |
163 | |
164 | // This checks wheter a Clang module is built |
165 | # ifndef __building_module |
166 | # define __building_module(...) 0 |
167 | # endif |
168 | |
169 | // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by |
170 | // the compiler and '1' otherwise. |
171 | # ifndef __is_identifier |
172 | # define __is_identifier(__x) 1 |
173 | # endif |
174 | |
175 | # ifndef __has_declspec_attribute |
176 | # define __has_declspec_attribute(__x) 0 |
177 | # endif |
178 | |
179 | # define __has_keyword(__x) !(__is_identifier(__x)) |
180 | |
181 | # ifndef __has_warning |
182 | # define __has_warning(...) 0 |
183 | # endif |
184 | |
185 | # if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L |
186 | # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" |
187 | # endif |
188 | |
189 | # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) |
190 | # define _LIBCPP_ABI_VCRUNTIME |
191 | # endif |
192 | |
193 | # if __has_feature(experimental_library) |
194 | # ifndef _LIBCPP_ENABLE_EXPERIMENTAL |
195 | # define _LIBCPP_ENABLE_EXPERIMENTAL |
196 | # endif |
197 | # endif |
198 | |
199 | // Incomplete features get their own specific disabling flags. This makes it |
200 | // easier to grep for target specific flags once the feature is complete. |
201 | # if defined(_LIBCPP_ENABLE_EXPERIMENTAL) || defined(_LIBCPP_BUILDING_LIBRARY) |
202 | # define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 1 |
203 | # else |
204 | # define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 0 |
205 | # endif |
206 | |
207 | # define _LIBCPP_HAS_EXPERIMENTAL_PSTL _LIBCPP_HAS_EXPERIMENTAL_LIBRARY |
208 | # define _LIBCPP_HAS_EXPERIMENTAL_TZDB _LIBCPP_HAS_EXPERIMENTAL_LIBRARY |
209 | # define _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM _LIBCPP_HAS_EXPERIMENTAL_LIBRARY |
210 | |
211 | # if defined(__MVS__) |
212 | # include <features.h> // for __NATIVE_ASCII_F |
213 | # endif |
214 | |
215 | # if defined(_WIN32) |
216 | # define _LIBCPP_WIN32API |
217 | # define _LIBCPP_SHORT_WCHAR 1 |
218 | // Both MinGW and native MSVC provide a "MSVC"-like environment |
219 | # define _LIBCPP_MSVCRT_LIKE |
220 | // If mingw not explicitly detected, assume using MS C runtime only if |
221 | // a MS compatibility version is specified. |
222 | # if defined(_MSC_VER) && !defined(__MINGW32__) |
223 | # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library |
224 | # endif |
225 | # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) |
226 | # define _LIBCPP_HAS_BITSCAN64 1 |
227 | # else |
228 | # define _LIBCPP_HAS_BITSCAN64 0 |
229 | # endif |
230 | # define _LIBCPP_HAS_OPEN_WITH_WCHAR 1 |
231 | # else |
232 | # define _LIBCPP_HAS_OPEN_WITH_WCHAR 0 |
233 | # define _LIBCPP_HAS_BITSCAN64 0 |
234 | # endif // defined(_WIN32) |
235 | |
236 | # if defined(_AIX) && !defined(__64BIT__) |
237 | // The size of wchar is 2 byte on 32-bit mode on AIX. |
238 | # define _LIBCPP_SHORT_WCHAR 1 |
239 | # endif |
240 | |
241 | // Libc++ supports various implementations of std::random_device. |
242 | // |
243 | // _LIBCPP_USING_DEV_RANDOM |
244 | // Read entropy from the given file, by default `/dev/urandom`. |
245 | // If a token is provided, it is assumed to be the path to a file |
246 | // to read entropy from. This is the default behavior if nothing |
247 | // else is specified. This implementation requires storing state |
248 | // inside `std::random_device`. |
249 | // |
250 | // _LIBCPP_USING_ARC4_RANDOM |
251 | // Use arc4random(). This allows obtaining random data even when |
252 | // using sandboxing mechanisms. On some platforms like Apple, this |
253 | // is the recommended source of entropy for user-space programs. |
254 | // When this option is used, the token passed to `std::random_device`'s |
255 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
256 | // |
257 | // _LIBCPP_USING_GETENTROPY |
258 | // Use getentropy(). |
259 | // When this option is used, the token passed to `std::random_device`'s |
260 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
261 | // |
262 | // _LIBCPP_USING_FUCHSIA_CPRNG |
263 | // Use Fuchsia's zx_cprng_draw() system call, which is specified to |
264 | // deliver high-quality entropy and cannot fail. |
265 | // When this option is used, the token passed to `std::random_device`'s |
266 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
267 | // |
268 | // _LIBCPP_USING_NACL_RANDOM |
269 | // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, |
270 | // including accesses to the special files under `/dev`. This implementation |
271 | // uses the NaCL syscall `nacl_secure_random_init()` to get entropy. |
272 | // When this option is used, the token passed to `std::random_device`'s |
273 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
274 | // |
275 | // _LIBCPP_USING_WIN32_RANDOM |
276 | // Use rand_s(), for use on Windows. |
277 | // When this option is used, the token passed to `std::random_device`'s |
278 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
279 | # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ |
280 | defined(__DragonFly__) |
281 | # define _LIBCPP_USING_ARC4_RANDOM |
282 | # elif defined(__wasi__) || defined(__EMSCRIPTEN__) |
283 | # define _LIBCPP_USING_GETENTROPY |
284 | # elif defined(__Fuchsia__) |
285 | # define _LIBCPP_USING_FUCHSIA_CPRNG |
286 | # elif defined(__native_client__) |
287 | # define _LIBCPP_USING_NACL_RANDOM |
288 | # elif defined(_LIBCPP_WIN32API) |
289 | # define _LIBCPP_USING_WIN32_RANDOM |
290 | # else |
291 | # define _LIBCPP_USING_DEV_RANDOM |
292 | # endif |
293 | |
294 | # ifndef _LIBCPP_CXX03_LANG |
295 | |
296 | # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) |
297 | # define _ALIGNAS_TYPE(x) alignas(x) |
298 | # define _ALIGNAS(x) alignas(x) |
299 | # define _NOEXCEPT noexcept |
300 | # define _NOEXCEPT_(...) noexcept(__VA_ARGS__) |
301 | # define _LIBCPP_CONSTEXPR constexpr |
302 | |
303 | # else |
304 | |
305 | # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) |
306 | # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) |
307 | # define _ALIGNAS(x) __attribute__((__aligned__(x))) |
308 | # define nullptr __nullptr |
309 | # define _NOEXCEPT throw() |
310 | # define _NOEXCEPT_(...) |
311 | # define static_assert(...) _Static_assert(__VA_ARGS__) |
312 | # define decltype(...) __decltype(__VA_ARGS__) |
313 | # define _LIBCPP_CONSTEXPR |
314 | |
315 | typedef __char16_t char16_t; |
316 | typedef __char32_t char32_t; |
317 | |
318 | # endif |
319 | |
320 | # define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) |
321 | |
322 | # if __has_extension(blocks) && defined(__APPLE__) |
323 | # define _LIBCPP_HAS_BLOCKS_RUNTIME 1 |
324 | # else |
325 | # define _LIBCPP_HAS_BLOCKS_RUNTIME 0 |
326 | # endif |
327 | |
328 | # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) |
329 | |
330 | # if defined(_LIBCPP_OBJECT_FORMAT_COFF) |
331 | |
332 | # ifdef _DLL |
333 | # define _LIBCPP_CRT_FUNC __declspec(dllimport) |
334 | # else |
335 | # define _LIBCPP_CRT_FUNC |
336 | # endif |
337 | |
338 | # if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) |
339 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS |
340 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
341 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS |
342 | # define _LIBCPP_EXPORTED_FROM_ABI |
343 | # elif defined(_LIBCPP_BUILDING_LIBRARY) |
344 | # if defined(__MINGW32__) |
345 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllexport) |
346 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
347 | # else |
348 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS |
349 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __declspec(dllexport) |
350 | # endif |
351 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS __declspec(dllexport) |
352 | # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) |
353 | # else |
354 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllimport) |
355 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
356 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS |
357 | # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) |
358 | # endif |
359 | |
360 | # define _LIBCPP_HIDDEN |
361 | # define _LIBCPP_TEMPLATE_DATA_VIS |
362 | # define _LIBCPP_NAMESPACE_VISIBILITY |
363 | |
364 | # else |
365 | |
366 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
367 | # define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) |
368 | # else |
369 | # define _LIBCPP_VISIBILITY(vis) |
370 | # endif |
371 | |
372 | # define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") |
373 | # define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") |
374 | # define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") |
375 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") |
376 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
377 | |
378 | // TODO: Make this a proper customization point or remove the option to override it. |
379 | # ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS |
380 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") |
381 | # endif |
382 | |
383 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) |
384 | # define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default"))) |
385 | # elif !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
386 | # define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default"))) |
387 | # else |
388 | # define _LIBCPP_NAMESPACE_VISIBILITY |
389 | # endif |
390 | |
391 | # endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) |
392 | |
393 | # if __has_attribute(exclude_from_explicit_instantiation) |
394 | # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) |
395 | # else |
396 | // Try to approximate the effect of exclude_from_explicit_instantiation |
397 | // (which is that entities are not assumed to be provided by explicit |
398 | // template instantiations in the dylib) by always inlining those entities. |
399 | # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE |
400 | # endif |
401 | |
402 | # ifdef _LIBCPP_COMPILER_CLANG_BASED |
403 | # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") |
404 | # define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") |
405 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) |
406 | # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) |
407 | # elif defined(_LIBCPP_COMPILER_GCC) |
408 | # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") |
409 | # define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") |
410 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) |
411 | # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) |
412 | # else |
413 | # define _LIBCPP_DIAGNOSTIC_PUSH |
414 | # define _LIBCPP_DIAGNOSTIC_POP |
415 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) |
416 | # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) |
417 | # endif |
418 | |
419 | # if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST |
420 | # define _LIBCPP_HARDENING_SIG f |
421 | # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE |
422 | # define _LIBCPP_HARDENING_SIG s |
423 | # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG |
424 | # define _LIBCPP_HARDENING_SIG d |
425 | # else |
426 | # define _LIBCPP_HARDENING_SIG n // "none" |
427 | # endif |
428 | |
429 | # if !_LIBCPP_HAS_EXCEPTIONS |
430 | # define _LIBCPP_EXCEPTIONS_SIG n |
431 | # else |
432 | # define _LIBCPP_EXCEPTIONS_SIG e |
433 | # endif |
434 | |
435 | # define _LIBCPP_ODR_SIGNATURE \ |
436 | _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) |
437 | |
438 | // This macro marks a symbol as being hidden from libc++'s ABI. This is achieved |
439 | // on two levels: |
440 | // 1. The symbol is given hidden visibility, which ensures that users won't start exporting |
441 | // symbols from their dynamic library by means of using the libc++ headers. This ensures |
442 | // that those symbols stay private to the dynamic library in which it is defined. |
443 | // |
444 | // 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. |
445 | // This ensures that no ODR violation can arise from mixing two TUs compiled with different |
446 | // versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the |
447 | // program contains two definitions of a function, the ODR requires them to be token-by-token |
448 | // equivalent, and the linker is allowed to pick either definition and discard the other one. |
449 | // |
450 | // For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled |
451 | // *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs |
452 | // compiled with different settings), the two definitions are both visible by the linker and they |
453 | // have the same name, but they have a meaningfully different implementation (one throws an exception |
454 | // and the other aborts the program). This violates the ODR and makes the program ill-formed, and in |
455 | // practice what will happen is that the linker will pick one of the definitions at random and will |
456 | // discard the other one. This can quite clearly lead to incorrect program behavior. |
457 | // |
458 | // A similar reasoning holds for many other properties that are ODR-affecting. Essentially any |
459 | // property that causes the code of a function to differ from the code in another configuration |
460 | // can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI |
461 | // tag, but we encode the ones that we think are most important: library version, exceptions, and |
462 | // hardening mode. |
463 | // |
464 | // Note that historically, solving this problem has been achieved in various ways, including |
465 | // force-inlining all functions or giving internal linkage to all functions. Both these previous |
466 | // solutions suffer from drawbacks that lead notably to code bloat. |
467 | // |
468 | // Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend |
469 | // on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. |
470 | // |
471 | // Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions |
472 | // instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled |
473 | // name of a virtual function is part of its ABI, since some architectures like arm64e can sign |
474 | // the virtual function pointer in the vtable based on the mangled name of the function. Since |
475 | // we use an ABI tag that changes with each released version, the mangled name of the virtual |
476 | // function would change, which is incorrect. Note that it doesn't make much sense to change |
477 | // the implementation of a virtual function in an ABI-incompatible way in the first place, |
478 | // since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. |
479 | // |
480 | // The macro can be applied to record and enum types. When the tagged type is nested in |
481 | // a record this "parent" record needs to have the macro too. Another use case for applying |
482 | // this macro to records and unions is to apply an ABI tag to inline constexpr variables. |
483 | // This can be useful for inline variables that are implementation details which are expected |
484 | // to change in the future. |
485 | // |
486 | // TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing |
487 | // the length of symbols with an ABI tag. In practice, we should remove the escape hatch and |
488 | // use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. |
489 | # ifndef _LIBCPP_NO_ABI_TAG |
490 | # define _LIBCPP_HIDE_FROM_ABI \ |
491 | _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ |
492 | __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) |
493 | # else |
494 | # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION |
495 | # endif |
496 | # define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION |
497 | |
498 | # ifdef _LIBCPP_BUILDING_LIBRARY |
499 | # if _LIBCPP_ABI_VERSION > 1 |
500 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI |
501 | # else |
502 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
503 | # endif |
504 | # else |
505 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI |
506 | # endif |
507 | |
508 | // Clang modules take a significant compile time hit when pushing and popping diagnostics. |
509 | // Since all the headers are marked as system headers unless _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER is defined, we can |
510 | // simply disable this pushing and popping when _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER isn't defined. |
511 | # ifdef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER |
512 | # define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ |
513 | _LIBCPP_DIAGNOSTIC_PUSH \ |
514 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \ |
515 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ |
516 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ |
517 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ |
518 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") \ |
519 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ |
520 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ |
521 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ |
522 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") |
523 | # define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP |
524 | # else |
525 | # define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS |
526 | # define _LIBCPP_POP_EXTENSION_DIAGNOSTICS |
527 | # endif |
528 | |
529 | // clang-format off |
530 | |
531 | // The unversioned namespace is used when we want to be ABI compatible with other standard libraries in some way. There |
532 | // are two main categories where that's the case: |
533 | // - Historically, we have made exception types ABI compatible with libstdc++ to allow throwing them between libstdc++ |
534 | // and libc++. This is not used anymore for new exception types, since there is no use-case for it anymore. |
535 | // - Types and functions which are used by the compiler are in the unversioned namespace, since the compiler has to know |
536 | // their mangling without the appropriate declaration in some cases. |
537 | // If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned |
538 | // namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used. |
539 | # define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \ |
540 | _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std { |
541 | |
542 | # define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS |
543 | |
544 | # define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE { |
545 | # define _LIBCPP_END_NAMESPACE_STD } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD |
546 | |
547 | // TODO: This should really be in the versioned namespace |
548 | #define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD namespace experimental { |
549 | #define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD |
550 | |
551 | #define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 { |
552 | #define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL |
553 | |
554 | #define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 { |
555 | #define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL |
556 | |
557 | #ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE |
558 | # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem { |
559 | # define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD |
560 | #else |
561 | # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ |
562 | inline namespace __fs { namespace filesystem { |
563 | |
564 | # define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD |
565 | #endif |
566 | |
567 | // clang-format on |
568 | |
569 | # if __has_attribute(__enable_if__) |
570 | # define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) |
571 | # endif |
572 | |
573 | # if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) |
574 | # define _LIBCPP_HAS_INT128 0 |
575 | # else |
576 | # define _LIBCPP_HAS_INT128 1 |
577 | # endif |
578 | |
579 | # ifdef _LIBCPP_CXX03_LANG |
580 | # define _LIBCPP_DECLARE_STRONG_ENUM(x) \ |
581 | struct _LIBCPP_EXPORTED_FROM_ABI x { \ |
582 | enum __lx |
583 | // clang-format off |
584 | # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ |
585 | __lx __v_; \ |
586 | _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ |
587 | _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ |
588 | _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ |
589 | }; |
590 | // clang-format on |
591 | |
592 | # else // _LIBCPP_CXX03_LANG |
593 | # define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x |
594 | # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) |
595 | # endif // _LIBCPP_CXX03_LANG |
596 | |
597 | # ifdef __FreeBSD__ |
598 | # define _DECLARE_C99_LDBL_MATH 1 |
599 | # endif |
600 | |
601 | // If we are getting operator new from the MSVC CRT, then allocation overloads |
602 | // for align_val_t were added in 19.12, aka VS 2017 version 15.3. |
603 | # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 |
604 | # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 |
605 | # elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) |
606 | // We're deferring to Microsoft's STL to provide aligned new et al. We don't |
607 | // have it unless the language feature test macro is defined. |
608 | # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 |
609 | # elif defined(__MVS__) |
610 | # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 |
611 | # else |
612 | # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1 |
613 | # endif |
614 | |
615 | # if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) |
616 | # define _LIBCPP_HAS_ALIGNED_ALLOCATION 0 |
617 | # else |
618 | # define _LIBCPP_HAS_ALIGNED_ALLOCATION 1 |
619 | # endif |
620 | |
621 | // It is not yet possible to use aligned_alloc() on all Apple platforms since |
622 | // 10.15 was the first version to ship an implementation of aligned_alloc(). |
623 | # if defined(__APPLE__) |
624 | # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ |
625 | __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ |
626 | (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ |
627 | __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \ |
628 | (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \ |
629 | __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) || \ |
630 | (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) |
631 | # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 |
632 | # else |
633 | # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 |
634 | # endif |
635 | # elif defined(__ANDROID__) && __ANDROID_API__ < 28 |
636 | // Android only provides aligned_alloc when targeting API 28 or higher. |
637 | # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 |
638 | # else |
639 | # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 |
640 | # endif |
641 | |
642 | # if defined(__APPLE__) || defined(__FreeBSD__) |
643 | # define _LIBCPP_HAS_DEFAULTRUNELOCALE |
644 | # endif |
645 | |
646 | # if defined(__APPLE__) || defined(__FreeBSD__) |
647 | # define _LIBCPP_WCTYPE_IS_MASK |
648 | # endif |
649 | |
650 | # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) |
651 | # define _LIBCPP_HAS_CHAR8_T 0 |
652 | # else |
653 | # define _LIBCPP_HAS_CHAR8_T 1 |
654 | # endif |
655 | |
656 | // Deprecation macros. |
657 | // |
658 | // Deprecations warnings are always enabled, except when users explicitly opt-out |
659 | // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. |
660 | # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) |
661 | # if __has_attribute(__deprecated__) |
662 | # define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) |
663 | # define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) |
664 | # elif _LIBCPP_STD_VER >= 14 |
665 | # define _LIBCPP_DEPRECATED [[deprecated]] |
666 | # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] |
667 | # else |
668 | # define _LIBCPP_DEPRECATED |
669 | # define _LIBCPP_DEPRECATED_(m) |
670 | # endif |
671 | # else |
672 | # define _LIBCPP_DEPRECATED |
673 | # define _LIBCPP_DEPRECATED_(m) |
674 | # endif |
675 | |
676 | # if !defined(_LIBCPP_CXX03_LANG) |
677 | # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED |
678 | # else |
679 | # define _LIBCPP_DEPRECATED_IN_CXX11 |
680 | # endif |
681 | |
682 | # if _LIBCPP_STD_VER >= 14 |
683 | # define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED |
684 | # else |
685 | # define _LIBCPP_DEPRECATED_IN_CXX14 |
686 | # endif |
687 | |
688 | # if _LIBCPP_STD_VER >= 17 |
689 | # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED |
690 | # else |
691 | # define _LIBCPP_DEPRECATED_IN_CXX17 |
692 | # endif |
693 | |
694 | # if _LIBCPP_STD_VER >= 20 |
695 | # define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED |
696 | # else |
697 | # define _LIBCPP_DEPRECATED_IN_CXX20 |
698 | # endif |
699 | |
700 | # if _LIBCPP_STD_VER >= 23 |
701 | # define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED |
702 | # else |
703 | # define _LIBCPP_DEPRECATED_IN_CXX23 |
704 | # endif |
705 | |
706 | # if _LIBCPP_STD_VER >= 26 |
707 | # define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED |
708 | # define _LIBCPP_DEPRECATED_IN_CXX26_(m) _LIBCPP_DEPRECATED_(m) |
709 | # else |
710 | # define _LIBCPP_DEPRECATED_IN_CXX26 |
711 | # define _LIBCPP_DEPRECATED_IN_CXX26_(m) |
712 | # endif |
713 | |
714 | # if _LIBCPP_HAS_CHAR8_T |
715 | # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED |
716 | # else |
717 | # define _LIBCPP_DEPRECATED_WITH_CHAR8_T |
718 | # endif |
719 | |
720 | // Macros to enter and leave a state where deprecation warnings are suppressed. |
721 | # if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) |
722 | # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ |
723 | _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ |
724 | _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") |
725 | # define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") |
726 | # else |
727 | # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
728 | # define _LIBCPP_SUPPRESS_DEPRECATED_POP |
729 | # endif |
730 | |
731 | # if _LIBCPP_STD_VER <= 11 |
732 | # define _LIBCPP_EXPLICIT_SINCE_CXX14 |
733 | # else |
734 | # define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit |
735 | # endif |
736 | |
737 | # if _LIBCPP_STD_VER >= 23 |
738 | # define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit |
739 | # else |
740 | # define _LIBCPP_EXPLICIT_SINCE_CXX23 |
741 | # endif |
742 | |
743 | # if _LIBCPP_STD_VER >= 14 |
744 | # define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr |
745 | # else |
746 | # define _LIBCPP_CONSTEXPR_SINCE_CXX14 |
747 | # endif |
748 | |
749 | # if _LIBCPP_STD_VER >= 17 |
750 | # define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr |
751 | # else |
752 | # define _LIBCPP_CONSTEXPR_SINCE_CXX17 |
753 | # endif |
754 | |
755 | # if _LIBCPP_STD_VER >= 20 |
756 | # define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr |
757 | # else |
758 | # define _LIBCPP_CONSTEXPR_SINCE_CXX20 |
759 | # endif |
760 | |
761 | # if _LIBCPP_STD_VER >= 23 |
762 | # define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr |
763 | # else |
764 | # define _LIBCPP_CONSTEXPR_SINCE_CXX23 |
765 | # endif |
766 | |
767 | # if _LIBCPP_STD_VER >= 26 |
768 | # define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr |
769 | # else |
770 | # define _LIBCPP_CONSTEXPR_SINCE_CXX26 |
771 | # endif |
772 | |
773 | # ifndef _LIBCPP_WEAK |
774 | # define _LIBCPP_WEAK __attribute__((__weak__)) |
775 | # endif |
776 | |
777 | // Thread API |
778 | // clang-format off |
779 | # if _LIBCPP_HAS_THREADS && \ |
780 | !_LIBCPP_HAS_THREAD_API_PTHREAD && \ |
781 | !_LIBCPP_HAS_THREAD_API_WIN32 && \ |
782 | !_LIBCPP_HAS_THREAD_API_EXTERNAL |
783 | |
784 | # if defined(__FreeBSD__) || \ |
785 | defined(__wasi__) || \ |
786 | defined(__NetBSD__) || \ |
787 | defined(__OpenBSD__) || \ |
788 | defined(__NuttX__) || \ |
789 | defined(__linux__) || \ |
790 | defined(__GNU__) || \ |
791 | defined(__APPLE__) || \ |
792 | defined(__MVS__) || \ |
793 | defined(_AIX) || \ |
794 | defined(__EMSCRIPTEN__) |
795 | // clang-format on |
796 | # undef _LIBCPP_HAS_THREAD_API_PTHREAD |
797 | # define _LIBCPP_HAS_THREAD_API_PTHREAD 1 |
798 | # elif defined(__Fuchsia__) |
799 | // TODO(44575): Switch to C11 thread API when possible. |
800 | # undef _LIBCPP_HAS_THREAD_API_PTHREAD |
801 | # define _LIBCPP_HAS_THREAD_API_PTHREAD 1 |
802 | # elif defined(_LIBCPP_WIN32API) |
803 | # undef _LIBCPP_HAS_THREAD_API_WIN32 |
804 | # define _LIBCPP_HAS_THREAD_API_WIN32 1 |
805 | # else |
806 | # error "No thread API" |
807 | # endif // _LIBCPP_HAS_THREAD_API |
808 | # endif // _LIBCPP_HAS_THREADS |
809 | |
810 | # if _LIBCPP_HAS_THREAD_API_PTHREAD |
811 | # if defined(__ANDROID__) && __ANDROID_API__ >= 30 |
812 | # define _LIBCPP_HAS_COND_CLOCKWAIT 1 |
813 | # elif defined(_LIBCPP_GLIBC_PREREQ) |
814 | # if _LIBCPP_GLIBC_PREREQ(2, 30) |
815 | # define _LIBCPP_HAS_COND_CLOCKWAIT 1 |
816 | # else |
817 | # define _LIBCPP_HAS_COND_CLOCKWAIT 0 |
818 | # endif |
819 | # else |
820 | # define _LIBCPP_HAS_COND_CLOCKWAIT 0 |
821 | # endif |
822 | # else |
823 | # define _LIBCPP_HAS_COND_CLOCKWAIT 0 |
824 | # endif |
825 | |
826 | # if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD |
827 | # error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true. |
828 | # endif |
829 | |
830 | # if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL |
831 | # error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true. |
832 | # endif |
833 | |
834 | # if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS |
835 | # error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false. |
836 | # endif |
837 | |
838 | # if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__) |
839 | # define __STDCPP_THREADS__ 1 |
840 | # endif |
841 | |
842 | // The glibc and Bionic implementation of pthreads implements |
843 | // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 |
844 | // mutexes have no destroy mechanism. |
845 | // |
846 | // This optimization can't be performed on Apple platforms, where |
847 | // pthread_mutex_destroy can allow the kernel to release resources. |
848 | // See https://llvm.org/D64298 for details. |
849 | // |
850 | // TODO(EricWF): Enable this optimization on Bionic after speaking to their |
851 | // respective stakeholders. |
852 | // clang-format off |
853 | # if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \ |
854 | (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \ |
855 | _LIBCPP_HAS_THREAD_API_WIN32 |
856 | // clang-format on |
857 | # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1 |
858 | # else |
859 | # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0 |
860 | # endif |
861 | |
862 | // Destroying a condvar is a nop on Windows. |
863 | // |
864 | // This optimization can't be performed on Apple platforms, where |
865 | // pthread_cond_destroy can allow the kernel to release resources. |
866 | // See https://llvm.org/D64298 for details. |
867 | // |
868 | // TODO(EricWF): This is potentially true for some pthread implementations |
869 | // as well. |
870 | # if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32 |
871 | # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1 |
872 | # else |
873 | # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0 |
874 | # endif |
875 | |
876 | # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ |
877 | _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__) |
878 | # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE |
879 | # endif |
880 | |
881 | # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) |
882 | # define _LIBCPP_HAS_C_ATOMIC_IMP 1 |
883 | # define _LIBCPP_HAS_GCC_ATOMIC_IMP 0 |
884 | # define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 |
885 | # elif defined(_LIBCPP_COMPILER_GCC) |
886 | # define _LIBCPP_HAS_C_ATOMIC_IMP 0 |
887 | # define _LIBCPP_HAS_GCC_ATOMIC_IMP 1 |
888 | # define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 |
889 | # endif |
890 | |
891 | # if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP |
892 | # define _LIBCPP_HAS_ATOMIC_HEADER 0 |
893 | # else |
894 | # define 1 |
895 | # ifndef _LIBCPP_ATOMIC_FLAG_TYPE |
896 | # define _LIBCPP_ATOMIC_FLAG_TYPE bool |
897 | # endif |
898 | # endif |
899 | |
900 | # if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) |
901 | # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) |
902 | # else |
903 | # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS |
904 | # endif |
905 | |
906 | // Work around the attribute handling in clang. When both __declspec and |
907 | // __attribute__ are present, the processing goes awry preventing the definition |
908 | // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus |
909 | // combining the two does work. |
910 | # if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) && defined(__clang__) && \ |
911 | __has_attribute(acquire_capability) && !defined(_MSC_VER) |
912 | # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1 |
913 | # else |
914 | # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 0 |
915 | # endif |
916 | |
917 | # if _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS |
918 | # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) |
919 | # else |
920 | # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) |
921 | # endif |
922 | |
923 | # if _LIBCPP_STD_VER >= 20 |
924 | # define _LIBCPP_CONSTINIT constinit |
925 | # elif __has_attribute(__require_constant_initialization__) |
926 | # define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) |
927 | # else |
928 | # define _LIBCPP_CONSTINIT |
929 | # endif |
930 | |
931 | # if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) |
932 | // The CUDA SDK contains an unfortunate definition for the __noinline__ macro, |
933 | // which breaks the regular __attribute__((__noinline__)) syntax. Therefore, |
934 | // when compiling for CUDA we use the non-underscored version of the noinline |
935 | // attribute. |
936 | // |
937 | // This is a temporary workaround and we still expect the CUDA SDK team to solve |
938 | // this issue properly in the SDK headers. |
939 | // |
940 | // See https://github.com/llvm/llvm-project/pull/73838 for more details. |
941 | # define _LIBCPP_NOINLINE __attribute__((noinline)) |
942 | # elif __has_attribute(__noinline__) |
943 | # define _LIBCPP_NOINLINE __attribute__((__noinline__)) |
944 | # else |
945 | # define _LIBCPP_NOINLINE |
946 | # endif |
947 | |
948 | // We often repeat things just for handling wide characters in the library. |
949 | // When wide characters are disabled, it can be useful to have a quick way of |
950 | // disabling it without having to resort to #if-#endif, which has a larger |
951 | // impact on readability. |
952 | # if !_LIBCPP_HAS_WIDE_CHARACTERS |
953 | # define _LIBCPP_IF_WIDE_CHARACTERS(...) |
954 | # else |
955 | # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ |
956 | # endif |
957 | |
958 | // clang-format off |
959 | # define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")") |
960 | # define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")") |
961 | // clang-format on |
962 | |
963 | # ifndef _LIBCPP_NO_AUTO_LINK |
964 | # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) |
965 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
966 | # pragma comment(lib, "c++.lib") |
967 | # else |
968 | # pragma comment(lib, "libc++.lib") |
969 | # endif |
970 | # endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) |
971 | # endif // _LIBCPP_NO_AUTO_LINK |
972 | |
973 | // Configures the fopen close-on-exec mode character, if any. This string will |
974 | // be appended to any mode string used by fstream for fopen/fdopen. |
975 | // |
976 | // Not all platforms support this, but it helps avoid fd-leaks on platforms that |
977 | // do. |
978 | # if defined(__BIONIC__) |
979 | # define _LIBCPP_FOPEN_CLOEXEC_MODE "e" |
980 | # else |
981 | # define _LIBCPP_FOPEN_CLOEXEC_MODE |
982 | # endif |
983 | |
984 | # if __has_cpp_attribute(msvc::no_unique_address) |
985 | // MSVC implements [[no_unique_address]] as a silent no-op currently. |
986 | // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) |
987 | // However, MSVC implements [[msvc::no_unique_address]] which does what |
988 | // [[no_unique_address]] is supposed to do, in general. |
989 | # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] |
990 | # else |
991 | # define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] |
992 | # endif |
993 | |
994 | // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these |
995 | // functions is gradually being added to existing C libraries. The conditions |
996 | // below check for known C library versions and conditions under which these |
997 | // functions are declared by the C library. |
998 | // |
999 | // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if |
1000 | // __cpp_char8_t is defined or if C2X extensions are enabled. Determining |
1001 | // the latter depends on internal GNU libc details that are not appropriate |
1002 | // to depend on here, so any declarations present when __cpp_char8_t is not |
1003 | // defined are ignored. |
1004 | # if defined(_LIBCPP_GLIBC_PREREQ) |
1005 | # if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) |
1006 | # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1 |
1007 | # else |
1008 | # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 |
1009 | # endif |
1010 | # else |
1011 | # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 |
1012 | # endif |
1013 | |
1014 | // There are a handful of public standard library types that are intended to |
1015 | // support CTAD but don't need any explicit deduction guides to do so. This |
1016 | // macro is used to mark them as such, which suppresses the |
1017 | // '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code |
1018 | // with these classes. |
1019 | # if _LIBCPP_STD_VER >= 17 |
1020 | # ifdef _LIBCPP_COMPILER_CLANG_BASED |
1021 | # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ |
1022 | template <class... _Tag> \ |
1023 | [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> |
1024 | # else |
1025 | # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ |
1026 | template <class... _Tag> \ |
1027 | ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> |
1028 | # endif |
1029 | # else |
1030 | # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") |
1031 | # endif |
1032 | |
1033 | // TODO(LLVM 22): Remove the workaround |
1034 | # if defined(__OBJC__) && (!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER < 2001) |
1035 | # define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS |
1036 | # endif |
1037 | |
1038 | # define _PSTL_PRAGMA(x) _Pragma(#x) |
1039 | |
1040 | // Enable SIMD for compilers that support OpenMP 4.0 |
1041 | # if (defined(_OPENMP) && _OPENMP >= 201307) |
1042 | |
1043 | # define _PSTL_UDR_PRESENT |
1044 | # define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) |
1045 | # define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) |
1046 | # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) |
1047 | # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) |
1048 | # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) |
1049 | # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) |
1050 | |
1051 | // Declaration of reduction functor, where |
1052 | // NAME - the name of the functor |
1053 | // OP - type of the callable object with the reduction operation |
1054 | // omp_in - refers to the local partial result |
1055 | // omp_out - refers to the final value of the combiner operator |
1056 | // omp_priv - refers to the private copy of the initial value |
1057 | // omp_orig - refers to the original variable to be reduced |
1058 | # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ |
1059 | _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) |
1060 | |
1061 | # elif defined(_LIBCPP_COMPILER_CLANG_BASED) |
1062 | |
1063 | # define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") |
1064 | # define _PSTL_PRAGMA_DECLARE_SIMD |
1065 | # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") |
1066 | # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") |
1067 | # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) |
1068 | # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) |
1069 | # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) |
1070 | |
1071 | # else // (defined(_OPENMP) && _OPENMP >= 201307) |
1072 | |
1073 | # define _PSTL_PRAGMA_SIMD |
1074 | # define _PSTL_PRAGMA_DECLARE_SIMD |
1075 | # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) |
1076 | # define _PSTL_PRAGMA_SIMD_SCAN(PRM) |
1077 | # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) |
1078 | # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) |
1079 | # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) |
1080 | |
1081 | # endif // (defined(_OPENMP) && _OPENMP >= 201307) |
1082 | |
1083 | # define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED |
1084 | |
1085 | // Optional attributes - these are useful for a better QoI, but not required to be available |
1086 | |
1087 | # define _LIBCPP_NOALIAS __attribute__((__malloc__)) |
1088 | # define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]] |
1089 | # define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) |
1090 | # define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) |
1091 | # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ |
1092 | __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) |
1093 | # define _LIBCPP_PACKED __attribute__((__packed__)) |
1094 | |
1095 | # if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) |
1096 | # define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) |
1097 | # else |
1098 | # define _LIBCPP_NO_CFI |
1099 | # endif |
1100 | |
1101 | # if __has_attribute(__using_if_exists__) |
1102 | # define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) |
1103 | # else |
1104 | # define _LIBCPP_USING_IF_EXISTS |
1105 | # endif |
1106 | |
1107 | # if __has_cpp_attribute(_Clang::__no_destroy__) |
1108 | # define _LIBCPP_NO_DESTROY [[_Clang::__no_destroy__]] |
1109 | # else |
1110 | # define _LIBCPP_NO_DESTROY |
1111 | # endif |
1112 | |
1113 | # if __has_attribute(__diagnose_if__) |
1114 | # define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) |
1115 | # else |
1116 | # define _LIBCPP_DIAGNOSE_WARNING(...) |
1117 | # endif |
1118 | |
1119 | # if __has_cpp_attribute(_Clang::__lifetimebound__) |
1120 | # define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] |
1121 | # else |
1122 | # define _LIBCPP_LIFETIMEBOUND |
1123 | # endif |
1124 | |
1125 | # if __has_cpp_attribute(_Clang::__noescape__) |
1126 | # define _LIBCPP_NOESCAPE [[_Clang::__noescape__]] |
1127 | # else |
1128 | # define _LIBCPP_NOESCAPE |
1129 | # endif |
1130 | |
1131 | # if __has_cpp_attribute(_Clang::__no_specializations__) |
1132 | # define _LIBCPP_NO_SPECIALIZATIONS \ |
1133 | [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]] |
1134 | # else |
1135 | # define _LIBCPP_NO_SPECIALIZATIONS |
1136 | # endif |
1137 | |
1138 | # if __has_cpp_attribute(_Clang::__standalone_debug__) |
1139 | # define _LIBCPP_STANDALONE_DEBUG [[_Clang::__standalone_debug__]] |
1140 | # else |
1141 | # define _LIBCPP_STANDALONE_DEBUG |
1142 | # endif |
1143 | |
1144 | # if __has_cpp_attribute(_Clang::__preferred_name__) |
1145 | # define _LIBCPP_PREFERRED_NAME(x) [[_Clang::__preferred_name__(x)]] |
1146 | # else |
1147 | # define _LIBCPP_PREFERRED_NAME(x) |
1148 | # endif |
1149 | |
1150 | # if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) |
1151 | # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) |
1152 | # else |
1153 | # define _LIBCPP_DECLSPEC_EMPTY_BASES |
1154 | # endif |
1155 | |
1156 | // Allow for build-time disabling of unsigned integer sanitization |
1157 | # if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) |
1158 | # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) |
1159 | # else |
1160 | # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
1161 | # endif |
1162 | |
1163 | # if __has_feature(nullability) |
1164 | # define _LIBCPP_DIAGNOSE_NULLPTR _Nonnull |
1165 | # else |
1166 | # define _LIBCPP_DIAGNOSE_NULLPTR |
1167 | # endif |
1168 | |
1169 | // TODO(LLVM 22): Remove this macro once LLVM19 support ends. __cpp_explicit_this_parameter has been set in LLVM20. |
1170 | // Clang-18 has support for deducing this, but it does not set the FTM. |
1171 | # if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800) |
1172 | # define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1 |
1173 | # else |
1174 | # define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0 |
1175 | # endif |
1176 | |
1177 | #endif // __cplusplus |
1178 | |
1179 | #endif // _LIBCPP___CONFIG |
1180 | |