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
15#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
16# pragma GCC system_header
17#endif
18
19#ifdef __cplusplus
20
21# include <__configuration/abi.h>
22# include <__configuration/attributes.h>
23# include <__configuration/availability.h>
24# include <__configuration/compiler.h>
25# include <__configuration/experimental.h>
26# include <__configuration/hardening.h>
27# include <__configuration/language.h>
28# include <__configuration/platform.h>
29
30// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
31
32// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
33// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
34// defined to XXYYZZ.
35# define _LIBCPP_VERSION 230000
36
37# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
38# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
39# define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z))
40
41# define _LIBCPP_TOSTRING2(x) #x
42# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
43
44# ifndef __has_constexpr_builtin
45# define __has_constexpr_builtin(x) 0
46# endif
47
48// This checks wheter a Clang module is built
49# ifndef __building_module
50# define __building_module(...) 0
51# endif
52
53// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
54// the compiler and '1' otherwise.
55# ifndef __is_identifier
56# define __is_identifier(__x) 1
57# endif
58
59# define __has_keyword(__x) !(__is_identifier(__x))
60
61# ifndef __has_warning
62# define __has_warning(...) 0
63# endif
64
65# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
66# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
67# endif
68
69# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
70# define _LIBCPP_ABI_VCRUNTIME
71# endif
72
73# if defined(__MVS__)
74# include <features.h> // for __NATIVE_ASCII_F
75# endif
76
77# if defined(_WIN32)
78# define _LIBCPP_WIN32API
79# define _LIBCPP_SHORT_WCHAR 1
80// Both MinGW and native MSVC provide a "MSVC"-like environment
81# define _LIBCPP_MSVCRT_LIKE
82// If mingw not explicitly detected, assume using MS C runtime only if
83// a MS compatibility version is specified.
84# if defined(_MSC_VER) && !defined(__MINGW32__)
85# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
86# endif
87# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
88# define _LIBCPP_HAS_BITSCAN64 1
89# else
90# define _LIBCPP_HAS_BITSCAN64 0
91# endif
92# define _LIBCPP_HAS_OPEN_WITH_WCHAR 1
93# else
94# define _LIBCPP_HAS_OPEN_WITH_WCHAR 0
95# define _LIBCPP_HAS_BITSCAN64 0
96# endif // defined(_WIN32)
97
98# if defined(_AIX) && !defined(__64BIT__)
99// The size of wchar is 2 byte on 32-bit mode on AIX.
100# define _LIBCPP_SHORT_WCHAR 1
101# endif
102
103// Libc++ supports various implementations of std::random_device.
104//
105// _LIBCPP_USING_DEV_RANDOM
106// Read entropy from the given file, by default `/dev/urandom`.
107// If a token is provided, it is assumed to be the path to a file
108// to read entropy from. This is the default behavior if nothing
109// else is specified. This implementation requires storing state
110// inside `std::random_device`.
111//
112// _LIBCPP_USING_ARC4_RANDOM
113// Use arc4random(). This allows obtaining random data even when
114// using sandboxing mechanisms. On some platforms like Apple, this
115// is the recommended source of entropy for user-space programs.
116// When this option is used, the token passed to `std::random_device`'s
117// constructor *must* be "/dev/urandom" -- anything else is an error.
118//
119// _LIBCPP_USING_GETENTROPY
120// Use getentropy().
121// When this option is used, the token passed to `std::random_device`'s
122// constructor *must* be "/dev/urandom" -- anything else is an error.
123//
124// _LIBCPP_USING_FUCHSIA_CPRNG
125// Use Fuchsia's zx_cprng_draw() system call, which is specified to
126// deliver high-quality entropy and cannot fail.
127// When this option is used, the token passed to `std::random_device`'s
128// constructor *must* be "/dev/urandom" -- anything else is an error.
129//
130// _LIBCPP_USING_WIN32_RANDOM
131// Use rand_s(), for use on Windows.
132// When this option is used, the token passed to `std::random_device`'s
133// constructor *must* be "/dev/urandom" -- anything else is an error.
134# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
135 defined(__DragonFly__)
136# define _LIBCPP_USING_ARC4_RANDOM
137# elif defined(__wasi__) || defined(__EMSCRIPTEN__)
138# define _LIBCPP_USING_GETENTROPY
139# elif defined(__Fuchsia__)
140# define _LIBCPP_USING_FUCHSIA_CPRNG
141# elif defined(_LIBCPP_WIN32API)
142# define _LIBCPP_USING_WIN32_RANDOM
143# else
144# define _LIBCPP_USING_DEV_RANDOM
145# endif
146
147# ifndef _LIBCPP_CXX03_LANG
148
149# define _LIBCPP_ALIGNOF(...) alignof(__VA_ARGS__)
150# define _ALIGNAS_TYPE(x) alignas(x)
151# define _ALIGNAS(x) alignas(x)
152# define _NOEXCEPT noexcept
153# define _NOEXCEPT_(...) noexcept(__VA_ARGS__)
154# define _LIBCPP_CONSTEXPR constexpr
155
156# else
157
158# define _LIBCPP_ALIGNOF(...) _Alignof(__VA_ARGS__)
159# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
160# define _ALIGNAS(x) __attribute__((__aligned__(x)))
161# define nullptr __nullptr
162# define _NOEXCEPT throw()
163# define _NOEXCEPT_(...)
164# define static_assert(...) _Static_assert(__VA_ARGS__)
165# define decltype(...) __decltype(__VA_ARGS__)
166# define _LIBCPP_CONSTEXPR
167
168typedef __char16_t char16_t;
169typedef __char32_t char32_t;
170
171# endif
172
173# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
174
175# if __has_extension(blocks) && defined(__APPLE__)
176# define _LIBCPP_HAS_BLOCKS_RUNTIME 1
177# else
178# define _LIBCPP_HAS_BLOCKS_RUNTIME 0
179# endif
180
181# ifdef _LIBCPP_COMPILER_CLANG_BASED
182# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
183# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
184# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
185# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
186# elif defined(_LIBCPP_COMPILER_GCC)
187# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
188# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
189# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
190# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
191# else
192# define _LIBCPP_DIAGNOSTIC_PUSH
193# define _LIBCPP_DIAGNOSTIC_POP
194# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
195# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
196# endif
197
198// Macros to enter and leave a state where deprecation warnings are suppressed.
199# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
200 _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated") \
201 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
202# define _LIBCPP_SUPPRESS_DEPRECATED_POP _LIBCPP_DIAGNOSTIC_POP
203
204// Clang modules take a significant compile time hit when pushing and popping diagnostics.
205// Since all the headers are marked as system headers unless _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER is defined, we can
206// simply disable this pushing and popping when _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER isn't defined.
207# ifdef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
208# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
209 _LIBCPP_DIAGNOSTIC_PUSH \
210 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \
211 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
212 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
213 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
214 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") \
215 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
216 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
217 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
218 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
219# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP
220# else
221# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS
222# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
223# endif
224
225// clang-format off
226
227// The unversioned namespace is used when we want to be ABI compatible with other standard libraries in some way. There
228// are two main categories where that's the case:
229// - Historically, we have made exception types ABI compatible with libstdc++ to allow throwing them between libstdc++
230// and libc++. This is not used anymore for new exception types, since there is no use-case for it anymore.
231// - Types and functions which are used by the compiler are in the unversioned namespace, since the compiler has to know
232// their mangling without the appropriate declaration in some cases.
233// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned
234// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used.
235# define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \
236 _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std {
237
238# define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS
239
240# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE {
241# define _LIBCPP_END_NAMESPACE_STD } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
242
243// TODO: This should really be in the versioned namespace
244#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD namespace experimental {
245#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
246
247#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
248#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
249
250#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 {
251#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
252
253#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
254# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {
255# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD
256#else
257# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \
258 inline namespace __fs { namespace filesystem {
259
260# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
261#endif
262
263// clang-format on
264
265# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
266# define _LIBCPP_HAS_INT128 0
267# else
268# define _LIBCPP_HAS_INT128 1
269# endif
270
271# ifdef _LIBCPP_CXX03_LANG
272# define _LIBCPP_DECLARE_STRONG_ENUM(x) \
273 struct _LIBCPP_EXPORTED_FROM_ABI x { \
274 enum __lx
275// clang-format off
276# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
277 __lx __v_; \
278 _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \
279 _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
280 _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \
281 };
282// clang-format on
283
284# else // _LIBCPP_CXX03_LANG
285# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
286# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
287# endif // _LIBCPP_CXX03_LANG
288
289# ifdef __FreeBSD__
290# define _DECLARE_C99_LDBL_MATH 1
291# endif
292
293// If we are getting operator new from the MSVC CRT, then allocation overloads
294// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
295# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
296# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
297# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
298// We're deferring to Microsoft's STL to provide aligned new et al. We don't
299// have it unless the language feature test macro is defined.
300# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
301# elif defined(__MVS__)
302# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
303# else
304# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1
305# endif
306
307# if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
308# define _LIBCPP_HAS_ALIGNED_ALLOCATION 0
309# else
310# define _LIBCPP_HAS_ALIGNED_ALLOCATION 1
311# endif
312
313# if defined(__APPLE__) || defined(__FreeBSD__)
314# define _LIBCPP_WCTYPE_IS_MASK
315# endif
316
317// FIXME: using `#warning` causes diagnostics from system headers which include deprecated headers. This can only be
318// enabled again once https://github.com/llvm/llvm-project/pull/168041 (or a similar feature) has landed, since that
319// allows suppression in system headers.
320# if defined(__DEPRECATED) && __DEPRECATED && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && 0
321# define _LIBCPP_DIAGNOSE_DEPRECATED_HEADERS 1
322# else
323# define _LIBCPP_DIAGNOSE_DEPRECATED_HEADERS 0
324# endif
325
326# if _LIBCPP_STD_VER <= 11
327# define _LIBCPP_EXPLICIT_SINCE_CXX14
328# else
329# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
330# endif
331
332# if _LIBCPP_STD_VER >= 23
333# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
334# else
335# define _LIBCPP_EXPLICIT_SINCE_CXX23
336# endif
337
338# if _LIBCPP_STD_VER >= 14
339# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
340# else
341# define _LIBCPP_CONSTEXPR_SINCE_CXX14
342# endif
343
344# if _LIBCPP_STD_VER >= 17
345# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
346# else
347# define _LIBCPP_CONSTEXPR_SINCE_CXX17
348# endif
349
350# if _LIBCPP_STD_VER >= 20
351# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
352# else
353# define _LIBCPP_CONSTEXPR_SINCE_CXX20
354# endif
355
356# if _LIBCPP_STD_VER >= 23
357# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
358# else
359# define _LIBCPP_CONSTEXPR_SINCE_CXX23
360# endif
361
362# if _LIBCPP_STD_VER >= 26
363# define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr
364# else
365# define _LIBCPP_CONSTEXPR_SINCE_CXX26
366# endif
367
368// Thread API
369// clang-format off
370# if _LIBCPP_HAS_THREADS && \
371 !_LIBCPP_HAS_THREAD_API_PTHREAD && \
372 !_LIBCPP_HAS_THREAD_API_WIN32 && \
373 !_LIBCPP_HAS_THREAD_API_EXTERNAL
374
375# if defined(__FreeBSD__) || \
376 defined(__wasi__) || \
377 defined(__NetBSD__) || \
378 defined(__OpenBSD__) || \
379 defined(__NuttX__) || \
380 defined(__linux__) || \
381 defined(__GNU__) || \
382 defined(__APPLE__) || \
383 defined(__MVS__) || \
384 defined(_AIX) || \
385 defined(__EMSCRIPTEN__)
386// clang-format on
387# undef _LIBCPP_HAS_THREAD_API_PTHREAD
388# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
389# elif defined(__Fuchsia__)
390// TODO(44575): Switch to C11 thread API when possible.
391# undef _LIBCPP_HAS_THREAD_API_PTHREAD
392# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
393# elif defined(_LIBCPP_WIN32API)
394# undef _LIBCPP_HAS_THREAD_API_WIN32
395# define _LIBCPP_HAS_THREAD_API_WIN32 1
396# else
397# error "No thread API"
398# endif // _LIBCPP_HAS_THREAD_API
399# endif // _LIBCPP_HAS_THREADS
400
401# if !_LIBCPP_HAS_THREAD_API_PTHREAD
402# define _LIBCPP_HAS_COND_CLOCKWAIT 0
403# elif (defined(__ANDROID__) && __ANDROID_API__ >= 30) || _LIBCPP_GLIBC_PREREQ(2, 30)
404# define _LIBCPP_HAS_COND_CLOCKWAIT 1
405# else
406# define _LIBCPP_HAS_COND_CLOCKWAIT 0
407# endif
408
409# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD
410# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true.
411# endif
412
413# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL
414# error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true.
415# endif
416
417# if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS
418# error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false.
419# endif
420
421# if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__)
422# define __STDCPP_THREADS__ 1
423# endif
424
425// The glibc and Bionic implementation of pthreads implements
426// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
427// mutexes have no destroy mechanism.
428//
429// This optimization can't be performed on Apple platforms, where
430// pthread_mutex_destroy can allow the kernel to release resources.
431// See https://llvm.org/D64298 for details.
432//
433// TODO(EricWF): Enable this optimization on Bionic after speaking to their
434// respective stakeholders.
435// clang-format off
436# if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \
437 (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \
438 _LIBCPP_HAS_THREAD_API_WIN32
439// clang-format on
440# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1
441# else
442# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0
443# endif
444
445// Destroying a condvar is a nop on Windows.
446//
447// This optimization can't be performed on Apple platforms, where
448// pthread_cond_destroy can allow the kernel to release resources.
449// See https://llvm.org/D64298 for details.
450//
451// TODO(EricWF): This is potentially true for some pthread implementations
452// as well.
453# if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32
454# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1
455# else
456# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0
457# endif
458
459# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
460 _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || _LIBCPP_LIBC_LLVM_LIBC
461# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
462# endif
463
464# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
465# define _LIBCPP_HAS_C_ATOMIC_IMP 1
466# define _LIBCPP_HAS_GCC_ATOMIC_IMP 0
467# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
468# elif defined(_LIBCPP_COMPILER_GCC)
469# define _LIBCPP_HAS_C_ATOMIC_IMP 0
470# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1
471# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
472# endif
473
474# if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP
475# define _LIBCPP_HAS_ATOMIC_HEADER 0
476# else
477# define _LIBCPP_HAS_ATOMIC_HEADER 1
478# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
479# define _LIBCPP_ATOMIC_FLAG_TYPE bool
480# endif
481# endif
482
483// We often repeat things just for handling wide characters in the library.
484// When wide characters are disabled, it can be useful to have a quick way of
485// disabling it without having to resort to #if-#endif, which has a larger
486// impact on readability.
487# if !_LIBCPP_HAS_WIDE_CHARACTERS
488# define _LIBCPP_IF_WIDE_CHARACTERS(...)
489# else
490# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
491# endif
492
493// clang-format off
494# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")")
495# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")")
496// clang-format on
497
498# ifndef _LIBCPP_NO_AUTO_LINK
499# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
500# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
501# pragma comment(lib, "c++.lib")
502# else
503# pragma comment(lib, "libc++.lib")
504# endif
505# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
506# endif // _LIBCPP_NO_AUTO_LINK
507
508// Configures the fopen close-on-exec mode character, if any. This string will
509// be appended to any mode string used by fstream for fopen/fdopen.
510//
511// Not all platforms support this, but it helps avoid fd-leaks on platforms that
512// do.
513# if defined(__BIONIC__)
514# define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
515# else
516# define _LIBCPP_FOPEN_CLOEXEC_MODE
517# endif
518
519// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
520// functions is gradually being added to existing C libraries. The conditions
521// below check for known C library versions and conditions under which these
522// functions are declared by the C library.
523//
524// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
525// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
526// the latter depends on internal GNU libc details that are not appropriate
527// to depend on here, so any declarations present when __cpp_char8_t is not
528// defined are ignored.
529# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
530# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
531# else
532# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
533# endif
534
535// There are a handful of public standard library types that are intended to
536// support CTAD but don't need any explicit deduction guides to do so. This
537// macro is used to mark them as such, which suppresses the
538// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
539// with these classes.
540# if _LIBCPP_STD_VER >= 17
541# ifdef _LIBCPP_COMPILER_CLANG_BASED
542# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
543 template <class... _Tag> \
544 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
545# else
546# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \
547 template <class... _Tag> \
548 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
549# endif
550# else
551# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
552# endif
553
554# if defined(__OBJC__) && defined(_LIBCPP_APPLE_CLANG_VER)
555# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
556# endif
557
558# define _PSTL_PRAGMA(x) _Pragma(#x)
559
560// Enable SIMD for compilers that support OpenMP 4.0
561# if (defined(_OPENMP) && _OPENMP >= 201307)
562
563# define _PSTL_UDR_PRESENT
564# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
565# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
566# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
567# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
568# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
569# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
570
571// Declaration of reduction functor, where
572// NAME - the name of the functor
573// OP - type of the callable object with the reduction operation
574// omp_in - refers to the local partial result
575// omp_out - refers to the final value of the combiner operator
576// omp_priv - refers to the private copy of the initial value
577// omp_orig - refers to the original variable to be reduced
578# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \
579 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
580
581# elif defined(_LIBCPP_COMPILER_CLANG_BASED)
582
583# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
584# define _PSTL_PRAGMA_DECLARE_SIMD
585# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
586# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
587# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
588# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
589# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
590
591# else // (defined(_OPENMP) && _OPENMP >= 201307)
592
593# define _PSTL_PRAGMA_SIMD
594# define _PSTL_PRAGMA_DECLARE_SIMD
595# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
596# define _PSTL_PRAGMA_SIMD_SCAN(PRM)
597# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
598# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
599# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
600
601# endif // (defined(_OPENMP) && _OPENMP >= 201307)
602
603# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
604
605#endif // __cplusplus
606
607#endif // _LIBCPP___CONFIG
608