xref: /freebsd/contrib/llvm-project/libcxx/include/__config (revision 415efcecd8b80f68e76376ef2b854cb6f5c84b5a)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
1081ad6265SDimitry Andric#ifndef _LIBCPP___CONFIG
1181ad6265SDimitry Andric#define _LIBCPP___CONFIG
120b57cec5SDimitry Andric
13fe6060f1SDimitry Andric#include <__config_site>
140fca6ea1SDimitry Andric#include <__configuration/abi.h>
150fca6ea1SDimitry Andric#include <__configuration/availability.h>
160fca6ea1SDimitry Andric#include <__configuration/compiler.h>
170fca6ea1SDimitry Andric#include <__configuration/platform.h>
18fe6060f1SDimitry Andric
190b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
200b57cec5SDimitry Andric#  pragma GCC system_header
210b57cec5SDimitry Andric#endif
220b57cec5SDimitry Andric
230b57cec5SDimitry Andric#ifdef __cplusplus
240b57cec5SDimitry Andric
2506c3fb27SDimitry Andric// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
2606c3fb27SDimitry Andric
27bdd1243dSDimitry Andric// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
2806c3fb27SDimitry Andric// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
29bdd1243dSDimitry Andric// defined to XXYYZZ.
30*415efcecSDimitry Andric#  define _LIBCPP_VERSION 190104
310b57cec5SDimitry Andric
32753f127fSDimitry Andric#  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
33753f127fSDimitry Andric#  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
34753f127fSDimitry Andric
35e8d8bef9SDimitry Andric#  if __STDC_HOSTED__ == 0
360b57cec5SDimitry Andric#    define _LIBCPP_FREESTANDING
370b57cec5SDimitry Andric#  endif
380b57cec5SDimitry Andric
3906c3fb27SDimitry Andric// HARDENING {
4006c3fb27SDimitry Andric
415f757f3fSDimitry Andric// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes)
420fca6ea1SDimitry Andric// equivalent to setting the extensive mode. This is deprecated and will be removed in LLVM 20.
435f757f3fSDimitry Andric#  ifdef _LIBCPP_ENABLE_ASSERTIONS
440fca6ea1SDimitry Andric#    warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_HARDENING_MODE instead"
4506c3fb27SDimitry Andric#    if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
4606c3fb27SDimitry Andric#      error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
4706c3fb27SDimitry Andric#    endif
485f757f3fSDimitry Andric#    if _LIBCPP_ENABLE_ASSERTIONS
495f757f3fSDimitry Andric#      define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE
505f757f3fSDimitry Andric#    endif
515f757f3fSDimitry Andric#  endif
5206c3fb27SDimitry Andric
535f757f3fSDimitry Andric// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
548a4dda33SDimitry Andric//
555f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE`;
565f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST`;
575f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
585f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG`.
5906c3fb27SDimitry Andric//
605f757f3fSDimitry Andric// These values have the following effects:
6106c3fb27SDimitry Andric//
625f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
635f757f3fSDimitry Andric//
645f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
655f757f3fSDimitry Andric//   that can be done with relatively little runtime overhead in constant time;
665f757f3fSDimitry Andric//
675f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
685f757f3fSDimitry Andric//   the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
695f757f3fSDimitry Andric//   but are not necessarily security-critical;
705f757f3fSDimitry Andric//
715f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
725f757f3fSDimitry Andric//   mode and enables all checks available in the library, including internal assertions. Checks that are part of the
735f757f3fSDimitry Andric//   debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production.
7406c3fb27SDimitry Andric
7506c3fb27SDimitry Andric// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
7606c3fb27SDimitry Andric// macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
7706c3fb27SDimitry Andric//
7806c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
7906c3fb27SDimitry Andric//   a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
8006c3fb27SDimitry Andric//   - the sentinel is reachable from the begin iterator;
8106c3fb27SDimitry Andric//   - TODO(hardening): both iterators refer to the same container.
8206c3fb27SDimitry Andric//
8306c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
8406c3fb27SDimitry Andric//   the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
8506c3fb27SDimitry Andric//   a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
8606c3fb27SDimitry Andric//   `optional` and `function` are considered one-element containers for the purposes of this check.
8706c3fb27SDimitry Andric//
885f757f3fSDimitry Andric// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
895f757f3fSDimitry Andric//   address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
905f757f3fSDimitry Andric//   memory security of a program (however, it is still undefined behavior that can result in strange errors due to
915f757f3fSDimitry Andric//   compiler optimizations).
925f757f3fSDimitry Andric//
9306c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
9406c3fb27SDimitry Andric//   given ranges do not overlap.
9506c3fb27SDimitry Andric//
967a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object
977a6dacacSDimitry Andric//   was allocated by the given allocator). Violating this category typically results in a memory leak.
987a6dacacSDimitry Andric//
997a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in
1007a6dacacSDimitry Andric//   an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like
1017a6dacacSDimitry Andric//   attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category
1027a6dacacSDimitry Andric//   (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or
1037a6dacacSDimitry Andric//   otherwise create an immediate security issue.
1047a6dacacSDimitry Andric//
10506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
10606c3fb27SDimitry Andric//   the containers have compatible allocators.
10706c3fb27SDimitry Andric//
1087a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments
1097a6dacacSDimitry Andric//   for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the
1107a6dacacSDimitry Andric//   original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g.
1117a6dacacSDimitry Andric//   a string view where only a subset of elements is possible to access). This category is for assertions violating
1127a6dacacSDimitry Andric//   which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the
1137a6dacacSDimitry Andric//   user code.
1147a6dacacSDimitry Andric//
1151db9f3b2SDimitry Andric// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to
1161db9f3b2SDimitry Andric//   be benign in our implementation.
1171db9f3b2SDimitry Andric//
1187a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed
1197a6dacacSDimitry Andric//   by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied;
1207a6dacacSDimitry Andric//   thus, this would often be a heuristic check and it might be quite expensive.
1217a6dacacSDimitry Andric//
12206c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
12306c3fb27SDimitry Andric//   user input.
12406c3fb27SDimitry Andric//
12506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
12606c3fb27SDimitry Andric
1275f757f3fSDimitry Andric// clang-format off
1285f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_NONE      (1 << 1)
1295f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_FAST      (1 << 2)
1305f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
1315f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_DEBUG     (1 << 3)
1325f757f3fSDimitry Andric// clang-format on
1335f757f3fSDimitry Andric
1345f757f3fSDimitry Andric#  ifndef _LIBCPP_HARDENING_MODE
1350fca6ea1SDimitry Andric
1360fca6ea1SDimitry Andric#    ifndef _LIBCPP_HARDENING_MODE_DEFAULT
1370fca6ea1SDimitry Andric#      error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \
1380fca6ea1SDimitry Andric`__config_site` header, please make sure your installation of libc++ is not broken.
1390fca6ea1SDimitry Andric#    endif
1400fca6ea1SDimitry Andric
1415f757f3fSDimitry Andric#    define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
14206c3fb27SDimitry Andric#  endif
14306c3fb27SDimitry Andric
1445f757f3fSDimitry Andric#  if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE &&                                                         \
1455f757f3fSDimitry Andric      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST &&                                                         \
1465f757f3fSDimitry Andric      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE &&                                                    \
1475f757f3fSDimitry Andric      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
1485f757f3fSDimitry Andric#    error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
1495f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_NONE, \
1505f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_FAST, \
1515f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_EXTENSIVE, \
1525f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_DEBUG
15306c3fb27SDimitry Andric#  endif
15406c3fb27SDimitry Andric
15506c3fb27SDimitry Andric// } HARDENING
15606c3fb27SDimitry Andric
15781ad6265SDimitry Andric#  define _LIBCPP_TOSTRING2(x) #x
15881ad6265SDimitry Andric#  define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
1590b57cec5SDimitry Andric
16006c3fb27SDimitry Andric// NOLINTNEXTLINE(libcpp-cpp-version-check)
1610b57cec5SDimitry Andric#  if __cplusplus < 201103L
1620b57cec5SDimitry Andric#    define _LIBCPP_CXX03_LANG
1630b57cec5SDimitry Andric#  endif
1640b57cec5SDimitry Andric
1652f2ebe75SDimitry Andric// TODO: Remove once we switch to GCC 14
1662f2ebe75SDimitry Andric#  ifndef __has_extension
1672f2ebe75SDimitry Andric#    define __has_extension(__x) 0
1682f2ebe75SDimitry Andric#  endif
1692f2ebe75SDimitry Andric
1702f2ebe75SDimitry Andric// TODO: Remove once we switch to GCC 14
1712f2ebe75SDimitry Andric#  ifndef __has_feature
1722f2ebe75SDimitry Andric#    define __has_feature(__x) 0
1732f2ebe75SDimitry Andric#  endif
1742f2ebe75SDimitry Andric
175bdd1243dSDimitry Andric#  ifndef __has_constexpr_builtin
176bdd1243dSDimitry Andric#    define __has_constexpr_builtin(x) 0
177bdd1243dSDimitry Andric#  endif
178bdd1243dSDimitry Andric
1790fca6ea1SDimitry Andric// This checks wheter a Clang module is built
1800fca6ea1SDimitry Andric#  ifndef __building_module
1810fca6ea1SDimitry Andric#    define __building_module(...) 0
1820fca6ea1SDimitry Andric#  endif
1830fca6ea1SDimitry Andric
1840b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
1850b57cec5SDimitry Andric// the compiler and '1' otherwise.
1860b57cec5SDimitry Andric#  ifndef __is_identifier
1870b57cec5SDimitry Andric#    define __is_identifier(__x) 1
1880b57cec5SDimitry Andric#  endif
1890b57cec5SDimitry Andric
1900b57cec5SDimitry Andric#  ifndef __has_declspec_attribute
1910b57cec5SDimitry Andric#    define __has_declspec_attribute(__x) 0
1920b57cec5SDimitry Andric#  endif
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric#  define __has_keyword(__x) !(__is_identifier(__x))
1950b57cec5SDimitry Andric
1960fca6ea1SDimitry Andric#  ifndef __has_warning
1970fca6ea1SDimitry Andric#    define __has_warning(...) 0
1980b57cec5SDimitry Andric#  endif
1990b57cec5SDimitry Andric
20081ad6265SDimitry Andric#  if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
20181ad6265SDimitry Andric#    error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
2020b57cec5SDimitry Andric#  endif
2030b57cec5SDimitry Andric
2040b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This
2050b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume
2060b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
2070b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this
2080b57cec5SDimitry Andric// heuristic falls short.
2090b57cec5SDimitry Andric#  if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
2100b57cec5SDimitry Andric#    error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
2110b57cec5SDimitry Andric#  elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
2120b57cec5SDimitry Andric#    define _LIBCPP_ABI_ITANIUM
2130b57cec5SDimitry Andric#  elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
2140b57cec5SDimitry Andric#    define _LIBCPP_ABI_MICROSOFT
2150b57cec5SDimitry Andric#  else
2160b57cec5SDimitry Andric#    if defined(_WIN32) && defined(_MSC_VER)
2170b57cec5SDimitry Andric#      define _LIBCPP_ABI_MICROSOFT
2180b57cec5SDimitry Andric#    else
2190b57cec5SDimitry Andric#      define _LIBCPP_ABI_ITANIUM
2200b57cec5SDimitry Andric#    endif
2210b57cec5SDimitry Andric#  endif
2220b57cec5SDimitry Andric
2230b57cec5SDimitry Andric#  if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
2240b57cec5SDimitry Andric#    define _LIBCPP_ABI_VCRUNTIME
2250b57cec5SDimitry Andric#  endif
2260b57cec5SDimitry Andric
227fcaf7f86SDimitry Andric#  if __has_feature(experimental_library)
228fcaf7f86SDimitry Andric#    ifndef _LIBCPP_ENABLE_EXPERIMENTAL
229fcaf7f86SDimitry Andric#      define _LIBCPP_ENABLE_EXPERIMENTAL
230fcaf7f86SDimitry Andric#    endif
231fcaf7f86SDimitry Andric#  endif
232fcaf7f86SDimitry Andric
233fcaf7f86SDimitry Andric// Incomplete features get their own specific disabling flags. This makes it
234fcaf7f86SDimitry Andric// easier to grep for target specific flags once the feature is complete.
235fcaf7f86SDimitry Andric#  if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
23606c3fb27SDimitry Andric#    define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
23706c3fb27SDimitry Andric#    define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
2380fca6ea1SDimitry Andric#    define _LIBCPP_HAS_NO_EXPERIMENTAL_TZDB
2395f757f3fSDimitry Andric#    define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM
240fcaf7f86SDimitry Andric#  endif
241fcaf7f86SDimitry Andric
24204eeddc0SDimitry Andric#  if defined(__MVS__)
24304eeddc0SDimitry Andric#    include <features.h> // for __NATIVE_ASCII_F
24404eeddc0SDimitry Andric#  endif
24504eeddc0SDimitry Andric
2460b57cec5SDimitry Andric#  if defined(_WIN32)
2470b57cec5SDimitry Andric#    define _LIBCPP_WIN32API
2480b57cec5SDimitry Andric#    define _LIBCPP_SHORT_WCHAR 1
2490b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment
2500b57cec5SDimitry Andric#    define _LIBCPP_MSVCRT_LIKE
2510b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if
2520b57cec5SDimitry Andric// a MS compatibility version is specified.
2530b57cec5SDimitry Andric#    if defined(_MSC_VER) && !defined(__MINGW32__)
2540b57cec5SDimitry Andric#      define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
2550b57cec5SDimitry Andric#    endif
2560b57cec5SDimitry Andric#    if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
2570b57cec5SDimitry Andric#      define _LIBCPP_HAS_BITSCAN64
2580b57cec5SDimitry Andric#    endif
2590b57cec5SDimitry Andric#    define _LIBCPP_HAS_OPEN_WITH_WCHAR
2600b57cec5SDimitry Andric#  endif // defined(_WIN32)
2610b57cec5SDimitry Andric
262349cc55cSDimitry Andric#  if defined(_AIX) && !defined(__64BIT__)
263349cc55cSDimitry Andric// The size of wchar is 2 byte on 32-bit mode on AIX.
264349cc55cSDimitry Andric#    define _LIBCPP_SHORT_WCHAR 1
265349cc55cSDimitry Andric#  endif
266349cc55cSDimitry Andric
2670eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device.
2680eae32dcSDimitry Andric//
2690eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM
2700eae32dcSDimitry Andric//      Read entropy from the given file, by default `/dev/urandom`.
2710eae32dcSDimitry Andric//      If a token is provided, it is assumed to be the path to a file
2720eae32dcSDimitry Andric//      to read entropy from. This is the default behavior if nothing
2730eae32dcSDimitry Andric//      else is specified. This implementation requires storing state
2740eae32dcSDimitry Andric//      inside `std::random_device`.
2750eae32dcSDimitry Andric//
2760eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM
2770eae32dcSDimitry Andric//      Use arc4random(). This allows obtaining random data even when
2780eae32dcSDimitry Andric//      using sandboxing mechanisms. On some platforms like Apple, this
2790eae32dcSDimitry Andric//      is the recommended source of entropy for user-space programs.
2800eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
2810eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
2820eae32dcSDimitry Andric//
2830eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY
2840eae32dcSDimitry Andric//      Use getentropy().
2850eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
2860eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
2870eae32dcSDimitry Andric//
28804eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG
28904eeddc0SDimitry Andric//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
29004eeddc0SDimitry Andric//      deliver high-quality entropy and cannot fail.
29104eeddc0SDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
29204eeddc0SDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
29304eeddc0SDimitry Andric//
2940eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM
2950eae32dcSDimitry Andric//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
2960eae32dcSDimitry Andric//      including accesses to the special files under `/dev`. This implementation
2970eae32dcSDimitry Andric//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
2980eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
2990eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
3000eae32dcSDimitry Andric//
3010eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM
3020eae32dcSDimitry Andric//      Use rand_s(), for use on Windows.
3030eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
3040eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
30581ad6265SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
30606c3fb27SDimitry Andric      defined(__DragonFly__)
3070b57cec5SDimitry Andric#    define _LIBCPP_USING_ARC4_RANDOM
30881ad6265SDimitry Andric#  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
3090b57cec5SDimitry Andric#    define _LIBCPP_USING_GETENTROPY
31004eeddc0SDimitry Andric#  elif defined(__Fuchsia__)
31104eeddc0SDimitry Andric#    define _LIBCPP_USING_FUCHSIA_CPRNG
3120b57cec5SDimitry Andric#  elif defined(__native_client__)
3130b57cec5SDimitry Andric#    define _LIBCPP_USING_NACL_RANDOM
3140b57cec5SDimitry Andric#  elif defined(_LIBCPP_WIN32API)
3150b57cec5SDimitry Andric#    define _LIBCPP_USING_WIN32_RANDOM
3160b57cec5SDimitry Andric#  else
3170b57cec5SDimitry Andric#    define _LIBCPP_USING_DEV_RANDOM
3180b57cec5SDimitry Andric#  endif
3190b57cec5SDimitry Andric
3200b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
32181ad6265SDimitry Andric
3220b57cec5SDimitry Andric#    define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
32381ad6265SDimitry Andric#    define _ALIGNAS_TYPE(x) alignas(x)
32481ad6265SDimitry Andric#    define _ALIGNAS(x) alignas(x)
32581ad6265SDimitry Andric#    define _LIBCPP_NORETURN [[noreturn]]
32681ad6265SDimitry Andric#    define _NOEXCEPT noexcept
3270fca6ea1SDimitry Andric#    define _NOEXCEPT_(...) noexcept(__VA_ARGS__)
328bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR constexpr
32981ad6265SDimitry Andric
3300b57cec5SDimitry Andric#  else
33181ad6265SDimitry Andric
33281ad6265SDimitry Andric#    define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
33381ad6265SDimitry Andric#    define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
33481ad6265SDimitry Andric#    define _ALIGNAS(x) __attribute__((__aligned__(x)))
335bdd1243dSDimitry Andric#    define _LIBCPP_NORETURN __attribute__((__noreturn__))
33681ad6265SDimitry Andric#    define _LIBCPP_HAS_NO_NOEXCEPT
33781ad6265SDimitry Andric#    define nullptr __nullptr
33881ad6265SDimitry Andric#    define _NOEXCEPT throw()
3390fca6ea1SDimitry Andric#    define _NOEXCEPT_(...)
340bdd1243dSDimitry Andric#    define static_assert(...) _Static_assert(__VA_ARGS__)
341bdd1243dSDimitry Andric#    define decltype(...) __decltype(__VA_ARGS__)
342bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR
34381ad6265SDimitry Andric
34481ad6265SDimitry Andrictypedef __char16_t char16_t;
34581ad6265SDimitry Andrictypedef __char32_t char32_t;
34681ad6265SDimitry Andric
34781ad6265SDimitry Andric#  endif
34881ad6265SDimitry Andric
3490b57cec5SDimitry Andric#  define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
3500b57cec5SDimitry Andric
3512f2ebe75SDimitry Andric#  if defined(_LIBCPP_COMPILER_CLANG_BASED)
3522f2ebe75SDimitry Andric
3530b57cec5SDimitry Andric// Objective-C++ features (opt-in)
3540b57cec5SDimitry Andric#    if __has_feature(objc_arc)
3550b57cec5SDimitry Andric#      define _LIBCPP_HAS_OBJC_ARC
3560b57cec5SDimitry Andric#    endif
3570b57cec5SDimitry Andric
3580b57cec5SDimitry Andric#    if __has_feature(objc_arc_weak)
3590b57cec5SDimitry Andric#      define _LIBCPP_HAS_OBJC_ARC_WEAK
3600b57cec5SDimitry Andric#    endif
3610b57cec5SDimitry Andric
3625ffd83dbSDimitry Andric#    if __has_extension(blocks)
3635ffd83dbSDimitry Andric#      define _LIBCPP_HAS_EXTENSION_BLOCKS
3645ffd83dbSDimitry Andric#    endif
3655ffd83dbSDimitry Andric
3665ffd83dbSDimitry Andric#    if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
3675ffd83dbSDimitry Andric#      define _LIBCPP_HAS_BLOCKS_RUNTIME
3685ffd83dbSDimitry Andric#    endif
3695ffd83dbSDimitry Andric
370fe6060f1SDimitry Andric#    if !__has_feature(address_sanitizer)
3710b57cec5SDimitry Andric#      define _LIBCPP_HAS_NO_ASAN
3720b57cec5SDimitry Andric#    endif
3730b57cec5SDimitry Andric
3740b57cec5SDimitry Andric#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
3750b57cec5SDimitry Andric
376e40139ffSDimitry Andric#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
377e40139ffSDimitry Andric
3782f2ebe75SDimitry Andric#  elif defined(_LIBCPP_COMPILER_GCC)
3792f2ebe75SDimitry Andric
3802f2ebe75SDimitry Andric#    if !defined(__SANITIZE_ADDRESS__)
3812f2ebe75SDimitry Andric#      define _LIBCPP_HAS_NO_ASAN
3822f2ebe75SDimitry Andric#    endif
3832f2ebe75SDimitry Andric
3842f2ebe75SDimitry Andric#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
3852f2ebe75SDimitry Andric
3862f2ebe75SDimitry Andric#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
3872f2ebe75SDimitry Andric
3882f2ebe75SDimitry Andric#  endif // _LIBCPP_COMPILER_[CLANG|GCC]
3892f2ebe75SDimitry Andric
3900b57cec5SDimitry Andric#  if defined(_LIBCPP_OBJECT_FORMAT_COFF)
3910b57cec5SDimitry Andric
3920b57cec5SDimitry Andric#    ifdef _DLL
3930b57cec5SDimitry Andric#      define _LIBCPP_CRT_FUNC __declspec(dllimport)
3940b57cec5SDimitry Andric#    else
3950b57cec5SDimitry Andric#      define _LIBCPP_CRT_FUNC
3960b57cec5SDimitry Andric#    endif
3970b57cec5SDimitry Andric
39881ad6265SDimitry Andric#    if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
3990b57cec5SDimitry Andric#      define _LIBCPP_DLL_VIS
4000b57cec5SDimitry Andric#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
4010b57cec5SDimitry Andric#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
4020b57cec5SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
4030b57cec5SDimitry Andric#      define _LIBCPP_EXPORTED_FROM_ABI
4040b57cec5SDimitry Andric#    elif defined(_LIBCPP_BUILDING_LIBRARY)
4050b57cec5SDimitry Andric#      define _LIBCPP_DLL_VIS __declspec(dllexport)
4060b57cec5SDimitry Andric#      if defined(__MINGW32__)
4070b57cec5SDimitry Andric#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
4080b57cec5SDimitry Andric#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
4090b57cec5SDimitry Andric#      else
4100b57cec5SDimitry Andric#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
4110b57cec5SDimitry Andric#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
4120b57cec5SDimitry Andric#      endif
4130b57cec5SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
4140b57cec5SDimitry Andric#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
4150b57cec5SDimitry Andric#    else
4160b57cec5SDimitry Andric#      define _LIBCPP_DLL_VIS __declspec(dllimport)
4170b57cec5SDimitry Andric#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
4180b57cec5SDimitry Andric#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
4190b57cec5SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
4200b57cec5SDimitry Andric#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
4210b57cec5SDimitry Andric#    endif
4220b57cec5SDimitry Andric
4230b57cec5SDimitry Andric#    define _LIBCPP_HIDDEN
4240b57cec5SDimitry Andric#    define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
4250b57cec5SDimitry Andric#    define _LIBCPP_TEMPLATE_VIS
426fe6060f1SDimitry Andric#    define _LIBCPP_TEMPLATE_DATA_VIS
4275f757f3fSDimitry Andric#    define _LIBCPP_TYPE_VISIBILITY_DEFAULT
4280b57cec5SDimitry Andric
4290b57cec5SDimitry Andric#  else
43081ad6265SDimitry Andric
43181ad6265SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
43281ad6265SDimitry Andric#      define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
43381ad6265SDimitry Andric#    else
43481ad6265SDimitry Andric#      define _LIBCPP_VISIBILITY(vis)
4350b57cec5SDimitry Andric#    endif
4360b57cec5SDimitry Andric
43781ad6265SDimitry Andric#    define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
43881ad6265SDimitry Andric#    define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
43981ad6265SDimitry Andric#    define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
44081ad6265SDimitry Andric#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
44181ad6265SDimitry Andric#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
44281ad6265SDimitry Andric
443fcaf7f86SDimitry Andric// TODO: Make this a proper customization point or remove the option to override it.
444fcaf7f86SDimitry Andric#    ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
445fcaf7f86SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
446fcaf7f86SDimitry Andric#    endif
447fcaf7f86SDimitry Andric
4480b57cec5SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
4490b57cec5SDimitry Andric// The inline should be removed once PR32114 is resolved
4500b57cec5SDimitry Andric#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
4510b57cec5SDimitry Andric#    else
4520b57cec5SDimitry Andric#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
4530b57cec5SDimitry Andric#    endif
4540b57cec5SDimitry Andric
4555f757f3fSDimitry Andric// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
4565f757f3fSDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
4570b57cec5SDimitry Andric#      define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
4580b57cec5SDimitry Andric#    else
4590b57cec5SDimitry Andric#      define _LIBCPP_TEMPLATE_VIS
4600b57cec5SDimitry Andric#    endif
4610b57cec5SDimitry Andric
46246c59ea9SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) && \
46346c59ea9SDimitry Andric        _LIBCPP_CLANG_VER >= 1500 // FreeBSD customization
4645f757f3fSDimitry Andric#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
4650b57cec5SDimitry Andric#    else
4665f757f3fSDimitry Andric#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT
4670b57cec5SDimitry Andric#    endif
4680b57cec5SDimitry Andric
46981ad6265SDimitry Andric#  endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
4700b57cec5SDimitry Andric
4710b57cec5SDimitry Andric#  if __has_attribute(exclude_from_explicit_instantiation)
4720b57cec5SDimitry Andric#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
4730b57cec5SDimitry Andric#  else
4740b57cec5SDimitry Andric// Try to approximate the effect of exclude_from_explicit_instantiation
4750b57cec5SDimitry Andric// (which is that entities are not assumed to be provided by explicit
4760b57cec5SDimitry Andric// template instantiations in the dylib) by always inlining those entities.
4770b57cec5SDimitry Andric#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
4780b57cec5SDimitry Andric#  endif
4790b57cec5SDimitry Andric
4800fca6ea1SDimitry Andric#  ifdef _LIBCPP_COMPILER_CLANG_BASED
4810fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
4820fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
4830fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
4840fca6ea1SDimitry Andric#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
4850fca6ea1SDimitry Andric#  elif defined(_LIBCPP_COMPILER_GCC)
4860fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
4870fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
4880fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
4890fca6ea1SDimitry Andric#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
4900fca6ea1SDimitry Andric#  else
4910fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_PUSH
4920fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_POP
4930fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
4940fca6ea1SDimitry Andric#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
4950fca6ea1SDimitry Andric#  endif
4960fca6ea1SDimitry Andric
4975f757f3fSDimitry Andric#  if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
4985f757f3fSDimitry Andric#    define _LIBCPP_HARDENING_SIG f
4995f757f3fSDimitry Andric#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
500b121cb00SDimitry Andric#    define _LIBCPP_HARDENING_SIG s
5015f757f3fSDimitry Andric#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
502b121cb00SDimitry Andric#    define _LIBCPP_HARDENING_SIG d
503b121cb00SDimitry Andric#  else
5045f757f3fSDimitry Andric#    define _LIBCPP_HARDENING_SIG n // "none"
505b121cb00SDimitry Andric#  endif
506b121cb00SDimitry Andric
507b121cb00SDimitry Andric#  ifdef _LIBCPP_HAS_NO_EXCEPTIONS
508b121cb00SDimitry Andric#    define _LIBCPP_EXCEPTIONS_SIG n
509b121cb00SDimitry Andric#  else
510b121cb00SDimitry Andric#    define _LIBCPP_EXCEPTIONS_SIG e
511b121cb00SDimitry Andric#  endif
512b121cb00SDimitry Andric
513b121cb00SDimitry Andric#  define _LIBCPP_ODR_SIGNATURE                                                                                        \
514b121cb00SDimitry Andric    _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
515b121cb00SDimitry Andric
516753f127fSDimitry Andric// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
517753f127fSDimitry Andric// on two levels:
518753f127fSDimitry Andric// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
519753f127fSDimitry Andric//    symbols from their dynamic library by means of using the libc++ headers. This ensures
520753f127fSDimitry Andric//    that those symbols stay private to the dynamic library in which it is defined.
521753f127fSDimitry Andric//
522b121cb00SDimitry Andric// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
523b121cb00SDimitry Andric//    This ensures that no ODR violation can arise from mixing two TUs compiled with different
524b121cb00SDimitry Andric//    versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
525b121cb00SDimitry Andric//    program contains two definitions of a function, the ODR requires them to be token-by-token
526b121cb00SDimitry Andric//    equivalent, and the linker is allowed to pick either definition and discard the other one.
527b121cb00SDimitry Andric//
528b121cb00SDimitry Andric//    For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
529b121cb00SDimitry Andric//    *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
530b121cb00SDimitry Andric//    compiled with different settings), the two definitions are both visible by the linker and they
531b121cb00SDimitry Andric//    have the same name, but they have a meaningfully different implementation (one throws an exception
532b121cb00SDimitry Andric//    and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
533b121cb00SDimitry Andric//    practice what will happen is that the linker will pick one of the definitions at random and will
534b121cb00SDimitry Andric//    discard the other one. This can quite clearly lead to incorrect program behavior.
535b121cb00SDimitry Andric//
536b121cb00SDimitry Andric//    A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
537b121cb00SDimitry Andric//    property that causes the code of a function to differ from the code in another configuration
538b121cb00SDimitry Andric//    can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
539b121cb00SDimitry Andric//    tag, but we encode the ones that we think are most important: library version, exceptions, and
540b121cb00SDimitry Andric//    hardening mode.
541b121cb00SDimitry Andric//
542b121cb00SDimitry Andric//    Note that historically, solving this problem has been achieved in various ways, including
543b121cb00SDimitry Andric//    force-inlining all functions or giving internal linkage to all functions. Both these previous
544b121cb00SDimitry Andric//    solutions suffer from drawbacks that lead notably to code bloat.
545753f127fSDimitry Andric//
546753f127fSDimitry Andric// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
547753f127fSDimitry Andric// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
548753f127fSDimitry Andric//
549bdd1243dSDimitry Andric// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
550bdd1243dSDimitry Andric// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
551bdd1243dSDimitry Andric// name of a virtual function is part of its ABI, since some architectures like arm64e can sign
552bdd1243dSDimitry Andric// the virtual function pointer in the vtable based on the mangled name of the function. Since
553bdd1243dSDimitry Andric// we use an ABI tag that changes with each released version, the mangled name of the virtual
554bdd1243dSDimitry Andric// function would change, which is incorrect. Note that it doesn't make much sense to change
555bdd1243dSDimitry Andric// the implementation of a virtual function in an ABI-incompatible way in the first place,
556bdd1243dSDimitry Andric// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
557bdd1243dSDimitry Andric//
5580fca6ea1SDimitry Andric// The macro can be applied to record and enum types. When the tagged type is nested in
5590fca6ea1SDimitry Andric// a record this "parent" record needs to have the macro too. Another use case for applying
5600fca6ea1SDimitry Andric// this macro to records and unions is to apply an ABI tag to inline constexpr variables.
5610fca6ea1SDimitry Andric// This can be useful for inline variables that are implementation details which are expected
5620fca6ea1SDimitry Andric// to change in the future.
5630fca6ea1SDimitry Andric//
564753f127fSDimitry Andric// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
565753f127fSDimitry Andric//       the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
566753f127fSDimitry Andric//       use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
567753f127fSDimitry Andric#  ifndef _LIBCPP_NO_ABI_TAG
568753f127fSDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI                                                                                      \
569753f127fSDimitry Andric      _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION                                                       \
570b121cb00SDimitry Andric      __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
5710b57cec5SDimitry Andric#  else
5720b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
5730b57cec5SDimitry Andric#  endif
574bdd1243dSDimitry Andric#  define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
5750b57cec5SDimitry Andric
5760b57cec5SDimitry Andric#  ifdef _LIBCPP_BUILDING_LIBRARY
5770b57cec5SDimitry Andric#    if _LIBCPP_ABI_VERSION > 1
5780b57cec5SDimitry Andric#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
5790b57cec5SDimitry Andric#    else
5800b57cec5SDimitry Andric#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
5810b57cec5SDimitry Andric#    endif
5820b57cec5SDimitry Andric#  else
5830b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
5840b57cec5SDimitry Andric#  endif
5850b57cec5SDimitry Andric
5860fca6ea1SDimitry Andric// TODO: Remove this workaround once we drop support for Clang 16
5870fca6ea1SDimitry Andric#  if __has_warning("-Wc++23-extensions")
5880fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
5890fca6ea1SDimitry Andric#  else
5900fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions")
5910fca6ea1SDimitry Andric#  endif
5920fca6ea1SDimitry Andric
5930fca6ea1SDimitry Andric// Clang modules take a significant compile time hit when pushing and popping diagnostics.
5940fca6ea1SDimitry Andric// Since all the headers are marked as system headers in the modulemap, we can simply disable this
5950fca6ea1SDimitry Andric// pushing and popping when building with clang modules.
5960fca6ea1SDimitry Andric#  if !__has_feature(modules)
5970fca6ea1SDimitry Andric#    define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS                                                                         \
5980fca6ea1SDimitry Andric      _LIBCPP_DIAGNOSTIC_PUSH                                                                                          \
5990fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions")                                                           \
6000fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions")                                                           \
6010fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions")                                                           \
6020fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions")                                                           \
6030fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION                                                                 \
6040fca6ea1SDimitry Andric      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions")                                                             \
6050fca6ea1SDimitry Andric      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions")                                                             \
6060fca6ea1SDimitry Andric      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions")                                                             \
6070fca6ea1SDimitry Andric      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
6080fca6ea1SDimitry Andric#    define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP
6090fca6ea1SDimitry Andric#  else
6100fca6ea1SDimitry Andric#    define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS
6110fca6ea1SDimitry Andric#    define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
6120fca6ea1SDimitry Andric#  endif
6130b57cec5SDimitry Andric
6140b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
61581ad6265SDimitry Andric// clang-format off
6160fca6ea1SDimitry Andric#  define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS                                               \
6170fca6ea1SDimitry Andric                                      namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std {                                  \
6185f757f3fSDimitry Andric                               inline namespace _LIBCPP_ABI_NAMESPACE {
6190fca6ea1SDimitry Andric#  define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS
62081ad6265SDimitry Andric
6210fca6ea1SDimitry Andric#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
6220fca6ea1SDimitry Andric#  define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {
6230fca6ea1SDimitry Andric#  define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD
6240fca6ea1SDimitry Andric#else
6255f757f3fSDimitry Andric#  define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD                                               \
6265f757f3fSDimitry Andric                                             inline namespace __fs { namespace filesystem {
6270b57cec5SDimitry Andric
6280fca6ea1SDimitry Andric#  define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
6290fca6ea1SDimitry Andric#endif
6300fca6ea1SDimitry Andric
63181ad6265SDimitry Andric// clang-format on
6320b57cec5SDimitry Andric
6330b57cec5SDimitry Andric#  if __has_attribute(__enable_if__)
6340b57cec5SDimitry Andric#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
6350b57cec5SDimitry Andric#  endif
6360b57cec5SDimitry Andric
63706c3fb27SDimitry Andric#  if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
6380b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_INT128
6390b57cec5SDimitry Andric#  endif
6400b57cec5SDimitry Andric
64181ad6265SDimitry Andric#  ifdef _LIBCPP_CXX03_LANG
64281ad6265SDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM(x)                                                                             \
64306c3fb27SDimitry Andric      struct _LIBCPP_EXPORTED_FROM_ABI x {                                                                             \
64481ad6265SDimitry Andric        enum __lx
64581ad6265SDimitry Andric// clang-format off
6460b57cec5SDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)                                                                      \
6470b57cec5SDimitry Andric      __lx __v_;                                                                                                       \
6485f757f3fSDimitry Andric      _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {}                                                                 \
6495f757f3fSDimitry Andric      _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {}                                      \
6505f757f3fSDimitry Andric      _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; }                                                      \
6510b57cec5SDimitry Andric      };
65281ad6265SDimitry Andric// clang-format on
65381ad6265SDimitry Andric
65481ad6265SDimitry Andric#  else // _LIBCPP_CXX03_LANG
6555f757f3fSDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
6560b57cec5SDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
65781ad6265SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
6580b57cec5SDimitry Andric
65906c3fb27SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
6600b57cec5SDimitry Andric#    define _LIBCPP_LOCALE__L_EXTENSIONS 1
6610b57cec5SDimitry Andric#  endif
6620b57cec5SDimitry Andric
6630b57cec5SDimitry Andric#  ifdef __FreeBSD__
6640b57cec5SDimitry Andric#    define _DECLARE_C99_LDBL_MATH 1
6650b57cec5SDimitry Andric#  endif
6660b57cec5SDimitry Andric
6670b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads
6680b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
6690b57cec5SDimitry Andric#  if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
6700b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
6710b57cec5SDimitry Andric#  elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
6720b57cec5SDimitry Andric// We're deferring to Microsoft's STL to provide aligned new et al. We don't
6730b57cec5SDimitry Andric// have it unless the language feature test macro is defined.
6740b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
675e8d8bef9SDimitry Andric#  elif defined(__MVS__)
676e8d8bef9SDimitry Andric#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
6770b57cec5SDimitry Andric#  endif
6780b57cec5SDimitry Andric
67981ad6265SDimitry Andric#  if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
6800b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
6810b57cec5SDimitry Andric#  endif
6820b57cec5SDimitry Andric
683bdd1243dSDimitry Andric// It is not yet possible to use aligned_alloc() on all Apple platforms since
684bdd1243dSDimitry Andric// 10.15 was the first version to ship an implementation of aligned_alloc().
685bdd1243dSDimitry Andric#  if defined(__APPLE__)
686bdd1243dSDimitry Andric#    if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                                                     \
687bdd1243dSDimitry Andric         __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
688bdd1243dSDimitry Andric#      define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
689bdd1243dSDimitry Andric#    endif
690bdd1243dSDimitry Andric#  elif defined(__ANDROID__) && __ANDROID_API__ < 28
691bdd1243dSDimitry Andric// Android only provides aligned_alloc when targeting API 28 or higher.
692bdd1243dSDimitry Andric#    define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
693bdd1243dSDimitry Andric#  endif
694bdd1243dSDimitry Andric
6950b57cec5SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__)
6960b57cec5SDimitry Andric#    define _LIBCPP_HAS_DEFAULTRUNELOCALE
6970b57cec5SDimitry Andric#  endif
6980b57cec5SDimitry Andric
69906c3fb27SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__)
7000b57cec5SDimitry Andric#    define _LIBCPP_WCTYPE_IS_MASK
7010b57cec5SDimitry Andric#  endif
7020b57cec5SDimitry Andric
7030b57cec5SDimitry Andric#  if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
704fe6060f1SDimitry Andric#    define _LIBCPP_HAS_NO_CHAR8_T
7050b57cec5SDimitry Andric#  endif
7060b57cec5SDimitry Andric
7070b57cec5SDimitry Andric// Deprecation macros.
7080b57cec5SDimitry Andric//
7090b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out
7100b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
7110b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
71206c3fb27SDimitry Andric#    if __has_attribute(__deprecated__)
71306c3fb27SDimitry Andric#      define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
71406c3fb27SDimitry Andric#      define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
71506c3fb27SDimitry Andric#    elif _LIBCPP_STD_VER >= 14
7160b57cec5SDimitry Andric#      define _LIBCPP_DEPRECATED [[deprecated]]
71781ad6265SDimitry Andric#      define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
7180b57cec5SDimitry Andric#    else
7190b57cec5SDimitry Andric#      define _LIBCPP_DEPRECATED
72081ad6265SDimitry Andric#      define _LIBCPP_DEPRECATED_(m)
7210b57cec5SDimitry Andric#    endif
7220b57cec5SDimitry Andric#  else
7230b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED
72481ad6265SDimitry Andric#    define _LIBCPP_DEPRECATED_(m)
7250b57cec5SDimitry Andric#  endif
7260b57cec5SDimitry Andric
7270fca6ea1SDimitry Andric#  if _LIBCPP_STD_VER < 20
7280fca6ea1SDimitry Andric#    define _LIBCPP_DEPRECATED_ATOMIC_SYNC                                                                             \
7290fca6ea1SDimitry Andric      _LIBCPP_DEPRECATED_("The C++20 synchronization library has been deprecated prior to C++20. Please update to "    \
7300fca6ea1SDimitry Andric                          "using -std=c++20 if you need to use these facilities.")
7310fca6ea1SDimitry Andric#  else
7320fca6ea1SDimitry Andric#    define _LIBCPP_DEPRECATED_ATOMIC_SYNC /* nothing */
7330fca6ea1SDimitry Andric#  endif
7340fca6ea1SDimitry Andric
7350b57cec5SDimitry Andric#  if !defined(_LIBCPP_CXX03_LANG)
7360b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
7370b57cec5SDimitry Andric#  else
7380b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX11
7390b57cec5SDimitry Andric#  endif
7400b57cec5SDimitry Andric
74106c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
7420b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
7430b57cec5SDimitry Andric#  else
7440b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX14
7450b57cec5SDimitry Andric#  endif
7460b57cec5SDimitry Andric
74706c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
7480b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
7490b57cec5SDimitry Andric#  else
7500b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX17
7510b57cec5SDimitry Andric#  endif
7520b57cec5SDimitry Andric
75306c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
754e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
755e8d8bef9SDimitry Andric#  else
756e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX20
757e8d8bef9SDimitry Andric#  endif
758e8d8bef9SDimitry Andric
759bdd1243dSDimitry Andric#  if _LIBCPP_STD_VER >= 23
760bdd1243dSDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
761bdd1243dSDimitry Andric#  else
762bdd1243dSDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX23
763bdd1243dSDimitry Andric#  endif
764bdd1243dSDimitry Andric
7650fca6ea1SDimitry Andric#  if _LIBCPP_STD_VER >= 26
7660fca6ea1SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
7670fca6ea1SDimitry Andric#  else
7680fca6ea1SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX26
7690fca6ea1SDimitry Andric#  endif
7700fca6ea1SDimitry Andric
771fe6060f1SDimitry Andric#  if !defined(_LIBCPP_HAS_NO_CHAR8_T)
772e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
773e8d8bef9SDimitry Andric#  else
774e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T
775e8d8bef9SDimitry Andric#  endif
776e8d8bef9SDimitry Andric
777e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed.
778fe6060f1SDimitry Andric#  if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
779e40139ffSDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH                                                                           \
78081ad6265SDimitry Andric      _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")                                \
781fe6060f1SDimitry Andric          _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
78281ad6265SDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
783fe6060f1SDimitry Andric#  else
784e40139ffSDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
785e40139ffSDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_POP
786e40139ffSDimitry Andric#  endif
787e40139ffSDimitry Andric
7880b57cec5SDimitry Andric#  if _LIBCPP_STD_VER <= 11
78906c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX14
7900b57cec5SDimitry Andric#  else
79106c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
7920b57cec5SDimitry Andric#  endif
7930b57cec5SDimitry Andric
79406c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
79506c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
79606c3fb27SDimitry Andric#  else
79706c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX23
79806c3fb27SDimitry Andric#  endif
79906c3fb27SDimitry Andric
80006c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
801bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
8020b57cec5SDimitry Andric#  else
803bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX14
8040b57cec5SDimitry Andric#  endif
8050b57cec5SDimitry Andric
80606c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
807bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
8080b57cec5SDimitry Andric#  else
809bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX17
8100b57cec5SDimitry Andric#  endif
8110b57cec5SDimitry Andric
81206c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
813bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
8140b57cec5SDimitry Andric#  else
815bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX20
8160b57cec5SDimitry Andric#  endif
8170b57cec5SDimitry Andric
81806c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
819bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
820bdd1243dSDimitry Andric#  else
821bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX23
822bdd1243dSDimitry Andric#  endif
823bdd1243dSDimitry Andric
8240b57cec5SDimitry Andric#  ifndef _LIBCPP_WEAK
8250b57cec5SDimitry Andric#    define _LIBCPP_WEAK __attribute__((__weak__))
8260b57cec5SDimitry Andric#  endif
8270b57cec5SDimitry Andric
8280b57cec5SDimitry Andric// Thread API
82981ad6265SDimitry Andric// clang-format off
8300b57cec5SDimitry Andric#  if !defined(_LIBCPP_HAS_NO_THREADS) &&                                                                              \
8310b57cec5SDimitry Andric      !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) &&                                                                      \
8320b57cec5SDimitry Andric      !defined(_LIBCPP_HAS_THREAD_API_WIN32) &&                                                                        \
8330b57cec5SDimitry Andric      !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
83481ad6265SDimitry Andric
8350b57cec5SDimitry Andric#    if defined(__FreeBSD__) ||                                                                                        \
8360b57cec5SDimitry Andric        defined(__wasi__) ||                                                                                           \
8370b57cec5SDimitry Andric        defined(__NetBSD__) ||                                                                                         \
838e8d8bef9SDimitry Andric        defined(__OpenBSD__) ||                                                                                        \
839e8d8bef9SDimitry Andric        defined(__NuttX__) ||                                                                                          \
8400b57cec5SDimitry Andric        defined(__linux__) ||                                                                                          \
8410b57cec5SDimitry Andric        defined(__GNU__) ||                                                                                            \
8420b57cec5SDimitry Andric        defined(__APPLE__) ||                                                                                          \
843e8d8bef9SDimitry Andric        defined(__MVS__) ||                                                                                            \
84481ad6265SDimitry Andric        defined(_AIX) ||                                                                                               \
84581ad6265SDimitry Andric        defined(__EMSCRIPTEN__)
84681ad6265SDimitry Andric// clang-format on
8470b57cec5SDimitry Andric#      define _LIBCPP_HAS_THREAD_API_PTHREAD
848480093f4SDimitry Andric#    elif defined(__Fuchsia__)
8495ffd83dbSDimitry Andric// TODO(44575): Switch to C11 thread API when possible.
8505ffd83dbSDimitry Andric#      define _LIBCPP_HAS_THREAD_API_PTHREAD
8510b57cec5SDimitry Andric#    elif defined(_LIBCPP_WIN32API)
8520b57cec5SDimitry Andric#      define _LIBCPP_HAS_THREAD_API_WIN32
8530b57cec5SDimitry Andric#    else
8540b57cec5SDimitry Andric#      error "No thread API"
8550b57cec5SDimitry Andric#    endif // _LIBCPP_HAS_THREAD_API
8560b57cec5SDimitry Andric#  endif   // _LIBCPP_HAS_NO_THREADS
8570b57cec5SDimitry Andric
858e40139ffSDimitry Andric#  if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
859e40139ffSDimitry Andric#    if defined(__ANDROID__) && __ANDROID_API__ >= 30
860e40139ffSDimitry Andric#      define _LIBCPP_HAS_COND_CLOCKWAIT
861e40139ffSDimitry Andric#    elif defined(_LIBCPP_GLIBC_PREREQ)
862e40139ffSDimitry Andric#      if _LIBCPP_GLIBC_PREREQ(2, 30)
863e40139ffSDimitry Andric#        define _LIBCPP_HAS_COND_CLOCKWAIT
864e40139ffSDimitry Andric#      endif
865e40139ffSDimitry Andric#    endif
866e40139ffSDimitry Andric#  endif
867e40139ffSDimitry Andric
8680b57cec5SDimitry Andric#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
8690b57cec5SDimitry Andric#    error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
8700b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is not defined.
8710b57cec5SDimitry Andric#  endif
8720b57cec5SDimitry Andric
8730b57cec5SDimitry Andric#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
8740b57cec5SDimitry Andric#    error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
8750b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is defined.
8760b57cec5SDimitry Andric#  endif
8770b57cec5SDimitry Andric
8780b57cec5SDimitry Andric#  if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
8790b57cec5SDimitry Andric#    error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
8800b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is defined.
8810b57cec5SDimitry Andric#  endif
8820b57cec5SDimitry Andric
883e40139ffSDimitry Andric#  if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
884e40139ffSDimitry Andric#    define __STDCPP_THREADS__ 1
885e40139ffSDimitry Andric#  endif
886e40139ffSDimitry Andric
887e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements
8880b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
8890b57cec5SDimitry Andric// mutexes have no destroy mechanism.
890e40139ffSDimitry Andric//
891e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where
892e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources.
893e40139ffSDimitry Andric// See https://llvm.org/D64298 for details.
894e40139ffSDimitry Andric//
895e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their
896e40139ffSDimitry Andric//               respective stakeholders.
89781ad6265SDimitry Andric// clang-format off
89881ad6265SDimitry Andric#  if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) ||                                               \
89981ad6265SDimitry Andric      (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) ||                                                 \
90081ad6265SDimitry Andric       defined(_LIBCPP_HAS_THREAD_API_WIN32)
90181ad6265SDimitry Andric// clang-format on
9020b57cec5SDimitry Andric#    define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
9030b57cec5SDimitry Andric#  endif
9040b57cec5SDimitry Andric
9050b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows.
906e40139ffSDimitry Andric//
907e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where
908e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources.
909e40139ffSDimitry Andric// See https://llvm.org/D64298 for details.
910e40139ffSDimitry Andric//
9110b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations
9120b57cec5SDimitry Andric// as well.
91381ad6265SDimitry Andric#  if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
9140b57cec5SDimitry Andric#    define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
9150b57cec5SDimitry Andric#  endif
9160b57cec5SDimitry Andric
91781ad6265SDimitry Andric#  if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) ||                        \
91804eeddc0SDimitry Andric      defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
9190b57cec5SDimitry Andric#    define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
9200b57cec5SDimitry Andric#  endif
9210b57cec5SDimitry Andric
9220b57cec5SDimitry Andric#  if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
9230b57cec5SDimitry Andric#    define _LIBCPP_HAS_C_ATOMIC_IMP
9240b57cec5SDimitry Andric#  elif defined(_LIBCPP_COMPILER_GCC)
9250b57cec5SDimitry Andric#    define _LIBCPP_HAS_GCC_ATOMIC_IMP
9260b57cec5SDimitry Andric#  endif
9270b57cec5SDimitry Andric
92881ad6265SDimitry Andric#  if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) &&                                    \
929349cc55cSDimitry Andric      !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
9300b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_ATOMIC_HEADER
9310b57cec5SDimitry Andric#  else
9320b57cec5SDimitry Andric#    ifndef _LIBCPP_ATOMIC_FLAG_TYPE
9330b57cec5SDimitry Andric#      define _LIBCPP_ATOMIC_FLAG_TYPE bool
9340b57cec5SDimitry Andric#    endif
9350b57cec5SDimitry Andric#  endif
9360b57cec5SDimitry Andric
93706c3fb27SDimitry Andric#  if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
93806c3fb27SDimitry Andric#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
93906c3fb27SDimitry Andric#  else
94006c3fb27SDimitry Andric#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
94106c3fb27SDimitry Andric#  endif
94206c3fb27SDimitry Andric
9430b57cec5SDimitry Andric#  if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
9440b57cec5SDimitry Andric#    if defined(__clang__) && __has_attribute(acquire_capability)
9450b57cec5SDimitry Andric// Work around the attribute handling in clang.  When both __declspec and
9460b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition
9471fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
9481fd87a68SDimitry Andric// combining the two does work.
9491fd87a68SDimitry Andric#      if !defined(_MSC_VER)
9500b57cec5SDimitry Andric#        define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
9510b57cec5SDimitry Andric#      endif
9520b57cec5SDimitry Andric#    endif
9530b57cec5SDimitry Andric#  endif
9540b57cec5SDimitry Andric
955480093f4SDimitry Andric#  ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
956480093f4SDimitry Andric#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
957480093f4SDimitry Andric#  else
958480093f4SDimitry Andric#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
959480093f4SDimitry Andric#  endif
960480093f4SDimitry Andric
96106c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
96281ad6265SDimitry Andric#    define _LIBCPP_CONSTINIT constinit
963bdd1243dSDimitry Andric#  elif __has_attribute(__require_constant_initialization__)
96481ad6265SDimitry Andric#    define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
9650b57cec5SDimitry Andric#  else
96681ad6265SDimitry Andric#    define _LIBCPP_CONSTINIT
9670b57cec5SDimitry Andric#  endif
9680b57cec5SDimitry Andric
9697a6dacacSDimitry Andric#  if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
9707a6dacacSDimitry Andric// The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
9717a6dacacSDimitry Andric// which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
9727a6dacacSDimitry Andric// when compiling for CUDA we use the non-underscored version of the noinline
9737a6dacacSDimitry Andric// attribute.
9747a6dacacSDimitry Andric//
9757a6dacacSDimitry Andric// This is a temporary workaround and we still expect the CUDA SDK team to solve
9767a6dacacSDimitry Andric// this issue properly in the SDK headers.
9777a6dacacSDimitry Andric//
9787a6dacacSDimitry Andric// See https://github.com/llvm/llvm-project/pull/73838 for more details.
9797a6dacacSDimitry Andric#    define _LIBCPP_NOINLINE __attribute__((noinline))
9807a6dacacSDimitry Andric#  elif __has_attribute(__noinline__)
9815f757f3fSDimitry Andric#    define _LIBCPP_NOINLINE __attribute__((__noinline__))
9820b57cec5SDimitry Andric#  else
9835f757f3fSDimitry Andric#    define _LIBCPP_NOINLINE
98406c3fb27SDimitry Andric#  endif
98506c3fb27SDimitry Andric
986349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library.
987349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of
988349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger
989349cc55cSDimitry Andric// impact on readability.
990349cc55cSDimitry Andric#  if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
991349cc55cSDimitry Andric#    define _LIBCPP_IF_WIDE_CHARACTERS(...)
992349cc55cSDimitry Andric#  else
993349cc55cSDimitry Andric#    define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
994349cc55cSDimitry Andric#  endif
995349cc55cSDimitry Andric
99606c3fb27SDimitry Andric// clang-format off
997b3edf446SDimitry Andric#  define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")")
998b3edf446SDimitry Andric#  define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")")
99906c3fb27SDimitry Andric// clang-format on
10000b57cec5SDimitry Andric
10010b57cec5SDimitry Andric#  ifndef _LIBCPP_NO_AUTO_LINK
10020b57cec5SDimitry Andric#    if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1003fe6060f1SDimitry Andric#      if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
10040b57cec5SDimitry Andric#        pragma comment(lib, "c++.lib")
10050b57cec5SDimitry Andric#      else
10060b57cec5SDimitry Andric#        pragma comment(lib, "libc++.lib")
10070b57cec5SDimitry Andric#      endif
10080b57cec5SDimitry Andric#    endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
10090b57cec5SDimitry Andric#  endif   // _LIBCPP_NO_AUTO_LINK
10100b57cec5SDimitry Andric
1011e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will
1012e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen.
1013e40139ffSDimitry Andric//
1014e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1015e40139ffSDimitry Andric// do.
1016e40139ffSDimitry Andric#  if defined(__BIONIC__)
1017e40139ffSDimitry Andric#    define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1018e40139ffSDimitry Andric#  else
1019e40139ffSDimitry Andric#    define _LIBCPP_FOPEN_CLOEXEC_MODE
1020e40139ffSDimitry Andric#  endif
1021e40139ffSDimitry Andric
102281ad6265SDimitry Andric#  if __has_cpp_attribute(msvc::no_unique_address)
102381ad6265SDimitry Andric// MSVC implements [[no_unique_address]] as a silent no-op currently.
102481ad6265SDimitry Andric// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
102581ad6265SDimitry Andric// However, MSVC implements [[msvc::no_unique_address]] which does what
102681ad6265SDimitry Andric// [[no_unique_address]] is supposed to do, in general.
102781ad6265SDimitry Andric
102881ad6265SDimitry Andric// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
102981ad6265SDimitry Andric// [[msvc::no_unique_address]] though. If/when it does implement
103081ad6265SDimitry Andric// [[msvc::no_unique_address]], this should be preferred though.
103181ad6265SDimitry Andric#    define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
103281ad6265SDimitry Andric#  elif __has_cpp_attribute(no_unique_address)
103306c3fb27SDimitry Andric#    define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
103481ad6265SDimitry Andric#  else
103581ad6265SDimitry Andric#    define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
103681ad6265SDimitry Andric// Note that this can be replaced by #error as soon as clang-cl
103781ad6265SDimitry Andric// implements msvc::no_unique_address, since there should be no C++20
103881ad6265SDimitry Andric// compiler that doesn't support one of the two attributes at that point.
103981ad6265SDimitry Andric// We generally don't want to use this macro outside of C++20-only code,
104081ad6265SDimitry Andric// because using it conditionally in one language version only would make
104181ad6265SDimitry Andric// the ABI inconsistent.
104281ad6265SDimitry Andric#  endif
104381ad6265SDimitry Andric
1044bdd1243dSDimitry Andric// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1045bdd1243dSDimitry Andric// functions is gradually being added to existing C libraries. The conditions
1046bdd1243dSDimitry Andric// below check for known C library versions and conditions under which these
1047bdd1243dSDimitry Andric// functions are declared by the C library.
1048bdd1243dSDimitry Andric#  define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1049bdd1243dSDimitry Andric// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
10501ac55f4cSDimitry Andric// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
10511ac55f4cSDimitry Andric// the latter depends on internal GNU libc details that are not appropriate
10521ac55f4cSDimitry Andric// to depend on here, so any declarations present when __cpp_char8_t is not
10531ac55f4cSDimitry Andric// defined are ignored.
10541ac55f4cSDimitry Andric#  if defined(_LIBCPP_GLIBC_PREREQ)
10551ac55f4cSDimitry Andric#    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1056bdd1243dSDimitry Andric#      undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1057bdd1243dSDimitry Andric#    endif
1058bdd1243dSDimitry Andric#  endif
1059bdd1243dSDimitry Andric
1060bdd1243dSDimitry Andric// There are a handful of public standard library types that are intended to
1061bdd1243dSDimitry Andric// support CTAD but don't need any explicit deduction guides to do so. This
1062bdd1243dSDimitry Andric// macro is used to mark them as such, which suppresses the
1063bdd1243dSDimitry Andric// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1064bdd1243dSDimitry Andric// with these classes.
1065bdd1243dSDimitry Andric#  if _LIBCPP_STD_VER >= 17
106606c3fb27SDimitry Andric#    ifdef _LIBCPP_COMPILER_CLANG_BASED
1067bdd1243dSDimitry Andric#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName)                                                              \
1068bdd1243dSDimitry Andric        template <class... _Tag>                                                                                       \
106906c3fb27SDimitry Andric        [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
107006c3fb27SDimitry Andric#    else
107106c3fb27SDimitry Andric#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName)                                                               \
107206c3fb27SDimitry Andric        template <class... _Tag>                                                                                       \
107306c3fb27SDimitry Andric        ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
107406c3fb27SDimitry Andric#    endif
1075bdd1243dSDimitry Andric#  else
1076bdd1243dSDimitry Andric#    define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1077bdd1243dSDimitry Andric#  endif
1078bdd1243dSDimitry Andric
10791ac55f4cSDimitry Andric// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
10801ac55f4cSDimitry Andric// compiler intrinsics in the Objective-C++ mode.
10811ac55f4cSDimitry Andric#  ifdef __OBJC__
10821ac55f4cSDimitry Andric#    define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
10831ac55f4cSDimitry Andric#  endif
10841ac55f4cSDimitry Andric
108506c3fb27SDimitry Andric#  define _PSTL_PRAGMA(x) _Pragma(#x)
108606c3fb27SDimitry Andric
108706c3fb27SDimitry Andric// Enable SIMD for compilers that support OpenMP 4.0
108806c3fb27SDimitry Andric#  if (defined(_OPENMP) && _OPENMP >= 201307)
108906c3fb27SDimitry Andric
109006c3fb27SDimitry Andric#    define _PSTL_UDR_PRESENT
109106c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
109206c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
109306c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
109406c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
109506c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
109606c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
109706c3fb27SDimitry Andric
109806c3fb27SDimitry Andric// Declaration of reduction functor, where
109906c3fb27SDimitry Andric// NAME - the name of the functor
110006c3fb27SDimitry Andric// OP - type of the callable object with the reduction operation
110106c3fb27SDimitry Andric// omp_in - refers to the local partial result
110206c3fb27SDimitry Andric// omp_out - refers to the final value of the combiner operator
110306c3fb27SDimitry Andric// omp_priv - refers to the private copy of the initial value
110406c3fb27SDimitry Andric// omp_orig - refers to the original variable to be reduced
110506c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)                                                                   \
110606c3fb27SDimitry Andric      _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
110706c3fb27SDimitry Andric
11085f757f3fSDimitry Andric#  elif defined(_LIBCPP_COMPILER_CLANG_BASED)
11095f757f3fSDimitry Andric
11105f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
11115f757f3fSDimitry Andric#    define _PSTL_PRAGMA_DECLARE_SIMD
11125f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
11135f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
11145f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
11155f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
11165f757f3fSDimitry Andric#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
11175f757f3fSDimitry Andric
111806c3fb27SDimitry Andric#  else // (defined(_OPENMP) && _OPENMP >= 201307)
111906c3fb27SDimitry Andric
112006c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD
112106c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_SIMD
112206c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
112306c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_SCAN(PRM)
112406c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
112506c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
112606c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
112706c3fb27SDimitry Andric
112806c3fb27SDimitry Andric#  endif // (defined(_OPENMP) && _OPENMP >= 201307)
112906c3fb27SDimitry Andric
113006c3fb27SDimitry Andric#  define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
113106c3fb27SDimitry Andric
11325f757f3fSDimitry Andric// Optional attributes - these are useful for a better QoI, but not required to be available
11335f757f3fSDimitry Andric
11345f757f3fSDimitry Andric#  if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
11355f757f3fSDimitry Andric#    define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
11365f757f3fSDimitry Andric#  else
11375f757f3fSDimitry Andric#    define _LIBCPP_NO_CFI
11385f757f3fSDimitry Andric#  endif
11395f757f3fSDimitry Andric
11405f757f3fSDimitry Andric#  if __has_attribute(__malloc__)
11415f757f3fSDimitry Andric#    define _LIBCPP_NOALIAS __attribute__((__malloc__))
11425f757f3fSDimitry Andric#  else
11435f757f3fSDimitry Andric#    define _LIBCPP_NOALIAS
11445f757f3fSDimitry Andric#  endif
11455f757f3fSDimitry Andric
11465f757f3fSDimitry Andric#  if __has_attribute(__using_if_exists__)
11475f757f3fSDimitry Andric#    define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
11485f757f3fSDimitry Andric#  else
11495f757f3fSDimitry Andric#    define _LIBCPP_USING_IF_EXISTS
11505f757f3fSDimitry Andric#  endif
11515f757f3fSDimitry Andric
11520fca6ea1SDimitry Andric#  if __has_cpp_attribute(__nodiscard__)
11535f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD [[__nodiscard__]]
11545f757f3fSDimitry Andric#  else
11555f757f3fSDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and
11565f757f3fSDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via
11575f757f3fSDimitry Andric// (void) cast.
11585f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD
11595f757f3fSDimitry Andric#  endif
11605f757f3fSDimitry Andric
11615f757f3fSDimitry Andric#  if __has_attribute(__no_destroy__)
11625f757f3fSDimitry Andric#    define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
11635f757f3fSDimitry Andric#  else
11645f757f3fSDimitry Andric#    define _LIBCPP_NO_DESTROY
11655f757f3fSDimitry Andric#  endif
11665f757f3fSDimitry Andric
11670fca6ea1SDimitry Andric#  if __has_attribute(__diagnose_if__)
11685f757f3fSDimitry Andric#    define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
11695f757f3fSDimitry Andric#  else
11705f757f3fSDimitry Andric#    define _LIBCPP_DIAGNOSE_WARNING(...)
11715f757f3fSDimitry Andric#  endif
11725f757f3fSDimitry Andric
11735f757f3fSDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon
11745f757f3fSDimitry Andric#  if __has_cpp_attribute(fallthrough)
11755f757f3fSDimitry Andric#    define _LIBCPP_FALLTHROUGH() [[fallthrough]]
11765f757f3fSDimitry Andric#  elif __has_attribute(__fallthrough__)
11775f757f3fSDimitry Andric#    define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
11785f757f3fSDimitry Andric#  else
11795f757f3fSDimitry Andric#    define _LIBCPP_FALLTHROUGH() ((void)0)
11805f757f3fSDimitry Andric#  endif
11815f757f3fSDimitry Andric
11825f757f3fSDimitry Andric#  if __has_cpp_attribute(_Clang::__lifetimebound__)
11835f757f3fSDimitry Andric#    define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
11845f757f3fSDimitry Andric#  else
11855f757f3fSDimitry Andric#    define _LIBCPP_LIFETIMEBOUND
11865f757f3fSDimitry Andric#  endif
11875f757f3fSDimitry Andric
11885f757f3fSDimitry Andric#  if __has_attribute(__nodebug__)
11895f757f3fSDimitry Andric#    define _LIBCPP_NODEBUG __attribute__((__nodebug__))
11905f757f3fSDimitry Andric#  else
11915f757f3fSDimitry Andric#    define _LIBCPP_NODEBUG
11925f757f3fSDimitry Andric#  endif
11935f757f3fSDimitry Andric
11945f757f3fSDimitry Andric#  if __has_attribute(__standalone_debug__)
11955f757f3fSDimitry Andric#    define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
11965f757f3fSDimitry Andric#  else
11975f757f3fSDimitry Andric#    define _LIBCPP_STANDALONE_DEBUG
11985f757f3fSDimitry Andric#  endif
11995f757f3fSDimitry Andric
12005f757f3fSDimitry Andric#  if __has_attribute(__preferred_name__)
12015f757f3fSDimitry Andric#    define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
12025f757f3fSDimitry Andric#  else
12035f757f3fSDimitry Andric#    define _LIBCPP_PREFERRED_NAME(x)
12045f757f3fSDimitry Andric#  endif
12055f757f3fSDimitry Andric
12065f757f3fSDimitry Andric#  if __has_attribute(__no_sanitize__)
12075f757f3fSDimitry Andric#    define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
12085f757f3fSDimitry Andric#  else
12095f757f3fSDimitry Andric#    define _LIBCPP_NO_SANITIZE(...)
12105f757f3fSDimitry Andric#  endif
12115f757f3fSDimitry Andric
12125f757f3fSDimitry Andric#  if __has_attribute(__init_priority__)
12135f757f3fSDimitry Andric#    define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
12145f757f3fSDimitry Andric#  else
12155f757f3fSDimitry Andric#    define _LIBCPP_INIT_PRIORITY_MAX
12165f757f3fSDimitry Andric#  endif
12175f757f3fSDimitry Andric
12185f757f3fSDimitry Andric#  if __has_attribute(__format__)
12195f757f3fSDimitry Andric// The attribute uses 1-based indices for ordinary and static member functions.
12205f757f3fSDimitry Andric// The attribute uses 2-based indices for non-static member functions.
12215f757f3fSDimitry Andric#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index)                           \
12225f757f3fSDimitry Andric      __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
12235f757f3fSDimitry Andric#  else
12245f757f3fSDimitry Andric#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
12255f757f3fSDimitry Andric#  endif
12265f757f3fSDimitry Andric
12275f757f3fSDimitry Andric#  if __has_attribute(__packed__)
12285f757f3fSDimitry Andric#    define _LIBCPP_PACKED __attribute__((__packed__))
12295f757f3fSDimitry Andric#  else
12305f757f3fSDimitry Andric#    define _LIBCPP_PACKED
12315f757f3fSDimitry Andric#  endif
12325f757f3fSDimitry Andric
12335f757f3fSDimitry Andric#  if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
12345f757f3fSDimitry Andric#    define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
12355f757f3fSDimitry Andric#  else
12365f757f3fSDimitry Andric#    define _LIBCPP_DECLSPEC_EMPTY_BASES
12375f757f3fSDimitry Andric#  endif
12385f757f3fSDimitry Andric
12395f757f3fSDimitry Andric// Allow for build-time disabling of unsigned integer sanitization
12405f757f3fSDimitry Andric#  if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
12415f757f3fSDimitry Andric#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
12425f757f3fSDimitry Andric#  else
12435f757f3fSDimitry Andric#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
12445f757f3fSDimitry Andric#  endif
12455f757f3fSDimitry Andric
12467a6dacacSDimitry Andric// Clang-18 has support for deducing this, but it does not set the FTM.
12477a6dacacSDimitry Andric#  if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
12487a6dacacSDimitry Andric#    define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
12497a6dacacSDimitry Andric#  endif
12507a6dacacSDimitry Andric
12510b57cec5SDimitry Andric#endif // __cplusplus
12520b57cec5SDimitry Andric
125381ad6265SDimitry Andric#endif // _LIBCPP___CONFIG
1254