xref: /freebsd/contrib/llvm-project/libcxx/include/__config (revision 7a6dacaca14b62ca4b74406814becb87a3fefac0)
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>
14fe6060f1SDimitry Andric
150b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
160b57cec5SDimitry Andric#  pragma GCC system_header
170b57cec5SDimitry Andric#endif
180b57cec5SDimitry Andric
19*7a6dacacSDimitry Andric#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
20*7a6dacacSDimitry Andric#  pragma clang deprecated(                                                                                            \
21*7a6dacacSDimitry Andric      _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES,                                                                           \
22*7a6dacacSDimitry Andric      "_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES is deprecated in LLVM 18 and will be removed in LLVM 19")
23*7a6dacacSDimitry Andric#endif
24*7a6dacacSDimitry Andric#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
25*7a6dacacSDimitry Andric#  pragma clang deprecated(                                                                                            \
26*7a6dacacSDimitry Andric      _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES,                                                                           \
27*7a6dacacSDimitry Andric      "_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES is deprecated in LLVM 18 and will be removed in LLVM 19")
28*7a6dacacSDimitry Andric#endif
29*7a6dacacSDimitry Andric
306246ae0bSDimitry Andric#if defined(__apple_build_version__)
311ac55f4cSDimitry Andric// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403)
326246ae0bSDimitry Andric#  define _LIBCPP_COMPILER_CLANG_BASED
336246ae0bSDimitry Andric#  define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
346246ae0bSDimitry Andric#elif defined(__clang__)
356246ae0bSDimitry Andric#  define _LIBCPP_COMPILER_CLANG_BASED
366246ae0bSDimitry Andric#  define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
376246ae0bSDimitry Andric#elif defined(__GNUC__)
386246ae0bSDimitry Andric#  define _LIBCPP_COMPILER_GCC
395f757f3fSDimitry Andric#  define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
406246ae0bSDimitry Andric#endif
416246ae0bSDimitry Andric
420b57cec5SDimitry Andric#ifdef __cplusplus
430b57cec5SDimitry Andric
445f757f3fSDimitry Andric// Warn if a compiler version is used that is not supported anymore
455f757f3fSDimitry Andric// LLVM RELEASE Update the minimum compiler versions
46412fa343SDimitry Andric#if defined(_LIBCPP_ENABLE_COMPILER_VERSION_CHECKS) // FreeBSD customization
475f757f3fSDimitry Andric#  if defined(_LIBCPP_CLANG_VER)
485f757f3fSDimitry Andric#    if _LIBCPP_CLANG_VER < 1600
495f757f3fSDimitry Andric#      warning "Libc++ only supports Clang 16 and later"
505f757f3fSDimitry Andric#    endif
515f757f3fSDimitry Andric#  elif defined(_LIBCPP_APPLE_CLANG_VER)
525f757f3fSDimitry Andric#    if _LIBCPP_APPLE_CLANG_VER < 1500
535f757f3fSDimitry Andric#      warning "Libc++ only supports AppleClang 15 and later"
545f757f3fSDimitry Andric#    endif
555f757f3fSDimitry Andric#  elif defined(_LIBCPP_GCC_VER)
565f757f3fSDimitry Andric#    if _LIBCPP_GCC_VER < 1300
575f757f3fSDimitry Andric#      warning "Libc++ only supports GCC 13 and later"
585f757f3fSDimitry Andric#    endif
595f757f3fSDimitry Andric#  endif
60412fa343SDimitry Andric#endif // _LIBCPP_ENABLE_COMPILER_VERSION_CHECKS
615f757f3fSDimitry Andric
6206c3fb27SDimitry Andric// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
6306c3fb27SDimitry Andric
64bdd1243dSDimitry Andric// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
6506c3fb27SDimitry Andric// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
66bdd1243dSDimitry Andric// defined to XXYYZZ.
675f757f3fSDimitry Andric#  define _LIBCPP_VERSION 180000
680b57cec5SDimitry Andric
69753f127fSDimitry Andric#  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
70753f127fSDimitry Andric#  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
71753f127fSDimitry Andric
72e8d8bef9SDimitry Andric#  if __STDC_HOSTED__ == 0
730b57cec5SDimitry Andric#    define _LIBCPP_FREESTANDING
740b57cec5SDimitry Andric#  endif
750b57cec5SDimitry Andric
7606c3fb27SDimitry Andric// NOLINTBEGIN(libcpp-cpp-version-check)
770b57cec5SDimitry Andric#  ifndef _LIBCPP_STD_VER
780b57cec5SDimitry Andric#    if __cplusplus <= 201103L
790b57cec5SDimitry Andric#      define _LIBCPP_STD_VER 11
800b57cec5SDimitry Andric#    elif __cplusplus <= 201402L
810b57cec5SDimitry Andric#      define _LIBCPP_STD_VER 14
820b57cec5SDimitry Andric#    elif __cplusplus <= 201703L
830b57cec5SDimitry Andric#      define _LIBCPP_STD_VER 17
84e8d8bef9SDimitry Andric#    elif __cplusplus <= 202002L
85e8d8bef9SDimitry Andric#      define _LIBCPP_STD_VER 20
8606c3fb27SDimitry Andric#    elif __cplusplus <= 202302L
8706c3fb27SDimitry Andric#      define _LIBCPP_STD_VER 23
880b57cec5SDimitry Andric#    else
89bdd1243dSDimitry Andric// Expected release year of the next C++ standard
9006c3fb27SDimitry Andric#      define _LIBCPP_STD_VER 26
910b57cec5SDimitry Andric#    endif
920b57cec5SDimitry Andric#  endif // _LIBCPP_STD_VER
9306c3fb27SDimitry Andric// NOLINTEND(libcpp-cpp-version-check)
940b57cec5SDimitry Andric
950b57cec5SDimitry Andric#  if defined(__ELF__)
960b57cec5SDimitry Andric#    define _LIBCPP_OBJECT_FORMAT_ELF 1
970b57cec5SDimitry Andric#  elif defined(__MACH__)
980b57cec5SDimitry Andric#    define _LIBCPP_OBJECT_FORMAT_MACHO 1
990b57cec5SDimitry Andric#  elif defined(_WIN32)
1000b57cec5SDimitry Andric#    define _LIBCPP_OBJECT_FORMAT_COFF 1
1010b57cec5SDimitry Andric#  elif defined(__wasm__)
1020b57cec5SDimitry Andric#    define _LIBCPP_OBJECT_FORMAT_WASM 1
10381ad6265SDimitry Andric#  elif defined(_AIX)
10481ad6265SDimitry Andric#    define _LIBCPP_OBJECT_FORMAT_XCOFF 1
1050b57cec5SDimitry Andric#  else
106e8d8bef9SDimitry Andric// ... add new file formats here ...
1070b57cec5SDimitry Andric#  endif
1080b57cec5SDimitry Andric
10906c3fb27SDimitry Andric// ABI {
11006c3fb27SDimitry Andric
11181ad6265SDimitry Andric#  if _LIBCPP_ABI_VERSION >= 2
1120b57cec5SDimitry Andric// Change short string representation so that string data starts at offset 0,
1130b57cec5SDimitry Andric// improving its alignment in some cases.
1140b57cec5SDimitry Andric#    define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1150b57cec5SDimitry Andric// Fix deque iterator type in order to support incomplete types.
1160b57cec5SDimitry Andric#    define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
1170b57cec5SDimitry Andric// Fix undefined behavior in how std::list stores its linked nodes.
1180b57cec5SDimitry Andric#    define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
1190b57cec5SDimitry Andric// Fix undefined behavior in  how __tree stores its end and parent nodes.
1200b57cec5SDimitry Andric#    define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
1210b57cec5SDimitry Andric// Fix undefined behavior in how __hash_table stores its pointer types.
1220b57cec5SDimitry Andric#    define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
1230b57cec5SDimitry Andric#    define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
1240b57cec5SDimitry Andric#    define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
1250b57cec5SDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize
1260b57cec5SDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries
1270b57cec5SDimitry Andric// using that class define their own copies.
1280b57cec5SDimitry Andric#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
129349cc55cSDimitry Andric// Override the default return value of exception::what() for
130349cc55cSDimitry Andric// bad_function_call::what() with a string that is specific to
131349cc55cSDimitry Andric// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
132349cc55cSDimitry Andric// because it changes the vtable layout of bad_function_call.
133349cc55cSDimitry Andric#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
1340b57cec5SDimitry Andric// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
1350b57cec5SDimitry Andric#    define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
136fe6060f1SDimitry Andric// Give reverse_iterator<T> one data member of type T, not two.
137fe6060f1SDimitry Andric// Also, in C++17 and later, don't derive iterator types from std::iterator.
138fe6060f1SDimitry Andric#    define _LIBCPP_ABI_NO_ITERATOR_BASES
1390b57cec5SDimitry Andric// Use the smallest possible integer type to represent the index of the variant.
1400b57cec5SDimitry Andric// Previously libc++ used "unsigned int" exclusively.
1410b57cec5SDimitry Andric#    define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
1420b57cec5SDimitry Andric// Unstable attempt to provide a more optimized std::function
1430b57cec5SDimitry Andric#    define _LIBCPP_ABI_OPTIMIZED_FUNCTION
1440b57cec5SDimitry Andric// All the regex constants must be distinct and nonzero.
1450b57cec5SDimitry Andric#    define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
1465ffd83dbSDimitry Andric// Re-worked external template instantiations for std::string with a focus on
1475ffd83dbSDimitry Andric// performance and fast-path inlining.
1485ffd83dbSDimitry Andric#    define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
149e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::unique_ptr.
150e8d8bef9SDimitry Andric#    define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
151e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
152e8d8bef9SDimitry Andric#    define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
15304eeddc0SDimitry Andric// std::random_device holds some state when it uses an implementation that gets
15404eeddc0SDimitry Andric// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
15504eeddc0SDimitry Andric// implementation to another one on a platform that has already shipped
15604eeddc0SDimitry Andric// std::random_device, one needs to retain the same object layout to remain ABI
15704eeddc0SDimitry Andric// compatible. This switch removes these workarounds for platforms that don't care
15804eeddc0SDimitry Andric// about ABI compatibility.
15904eeddc0SDimitry Andric#    define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
16081ad6265SDimitry Andric// Don't export the legacy __basic_string_common class and its methods from the built library.
1611838bd0fSDimitry Andric#    define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
16281ad6265SDimitry Andric// Don't export the legacy __vector_base_common class and its methods from the built library.
163d56accc7SDimitry Andric#    define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
16481ad6265SDimitry Andric// According to the Standard, `bitset::operator[] const` returns bool
16581ad6265SDimitry Andric#    define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
1661ac55f4cSDimitry Andric// Fix the implementation of CityHash used for std::hash<fundamental-type>.
1671ac55f4cSDimitry Andric// This is an ABI break because `std::hash` will return a different result,
1681ac55f4cSDimitry Andric// which means that hashing the same object in translation units built against
1691ac55f4cSDimitry Andric// different versions of libc++ can return inconsistent results. This is especially
1701ac55f4cSDimitry Andric// tricky since std::hash is used in the implementation of unordered containers.
1711ac55f4cSDimitry Andric//
1721ac55f4cSDimitry Andric// The incorrect implementation of CityHash has the problem that it drops some
1731ac55f4cSDimitry Andric// bits on the floor.
1741ac55f4cSDimitry Andric#    define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
17581ad6265SDimitry Andric// Remove the base 10 implementation of std::to_chars from the dylib.
17681ad6265SDimitry Andric// The implementation moved to the header, but we still export the symbols from
17781ad6265SDimitry Andric// the dylib for backwards compatibility.
17881ad6265SDimitry Andric#    define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
1795f757f3fSDimitry Andric// Save memory by providing the allocator more freedom to allocate the most
1805f757f3fSDimitry Andric// efficient size class by dropping the alignment requirements for std::string's
1815f757f3fSDimitry Andric// pointer from 16 to 8. This changes the output of std::string::max_size,
1825f757f3fSDimitry Andric// which makes it ABI breaking
1835f757f3fSDimitry Andric#    define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
1840b57cec5SDimitry Andric#  elif _LIBCPP_ABI_VERSION == 1
18581ad6265SDimitry Andric#    if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
1860b57cec5SDimitry Andric// Enable compiling copies of now inline methods into the dylib to support
1870b57cec5SDimitry Andric// applications compiled against older libraries. This is unnecessary with
1880b57cec5SDimitry Andric// COFF dllexport semantics, since dllexport forces a non-inline definition
1890b57cec5SDimitry Andric// of inline functions to be emitted anyway. Our own non-inline copy would
19081ad6265SDimitry Andric// conflict with the dllexport-emitted copy, so we disable it. For XCOFF,
19181ad6265SDimitry Andric// the linker will take issue with the symbols in the shared object if the
19281ad6265SDimitry Andric// weak inline methods get visibility (such as from -fvisibility-inlines-hidden),
19381ad6265SDimitry Andric// so disable it.
1940b57cec5SDimitry Andric#      define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
1950b57cec5SDimitry Andric#    endif
1960b57cec5SDimitry Andric// Feature macros for disabling pre ABI v1 features. All of these options
1970b57cec5SDimitry Andric// are deprecated.
1985f757f3fSDimitry Andric#    if defined(__FreeBSD__) && __FreeBSD__ < 14
1990b57cec5SDimitry Andric#      define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
2000b57cec5SDimitry Andric#    endif
20106c3fb27SDimitry Andric// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol
20206c3fb27SDimitry Andric// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def
20306c3fb27SDimitry Andric// in the library, so we need to always rely on the library version.
20406c3fb27SDimitry Andric#    if defined(_AIX)
20506c3fb27SDimitry Andric#      define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
20606c3fb27SDimitry Andric#    endif
2070b57cec5SDimitry Andric#  endif
2080b57cec5SDimitry Andric
20981ad6265SDimitry Andric#  if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
210349cc55cSDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize
211349cc55cSDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries
212349cc55cSDimitry Andric// using that class define their own copies.
213349cc55cSDimitry Andric#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
2140b57cec5SDimitry Andric#  endif
2150b57cec5SDimitry Andric
216647cbc5dSDimitry Andric// We had some bugs where we use [[no_unique_address]] together with construct_at,
217647cbc5dSDimitry Andric// which causes UB as the call on construct_at could write to overlapping subobjects
218647cbc5dSDimitry Andric//
219647cbc5dSDimitry Andric// https://github.com/llvm/llvm-project/issues/70506
220647cbc5dSDimitry Andric// https://github.com/llvm/llvm-project/issues/70494
221647cbc5dSDimitry Andric//
222647cbc5dSDimitry Andric// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions.
223*7a6dacacSDimitry Andric// The macro below is used for all classes whose ABI have changed as part of fixing these bugs.
224*7a6dacacSDimitry Andric#  define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua")))
225647cbc5dSDimitry Andric
22606c3fb27SDimitry Andric// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's
22706c3fb27SDimitry Andric// within the bounds of the original container and asserts it on every dereference.
22806c3fb27SDimitry Andric//
22906c3fb27SDimitry Andric// ABI impact: changes the iterator type of the relevant containers.
23006c3fb27SDimitry Andric//
23106c3fb27SDimitry Andric// Supported containers:
23206c3fb27SDimitry Andric// - `span`;
23306c3fb27SDimitry Andric// - `string_view`;
23406c3fb27SDimitry Andric// - `array`.
23506c3fb27SDimitry Andric// #define _LIBCPP_ABI_BOUNDED_ITERATORS
23606c3fb27SDimitry Andric
23706c3fb27SDimitry Andric// } ABI
23806c3fb27SDimitry Andric
23906c3fb27SDimitry Andric// HARDENING {
24006c3fb27SDimitry Andric
2415f757f3fSDimitry Andric// TODO(hardening): deprecate this in LLVM 19.
2425f757f3fSDimitry Andric// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes)
2435f757f3fSDimitry Andric// equivalent to setting the extensive mode.
2445f757f3fSDimitry Andric#  ifdef _LIBCPP_ENABLE_ASSERTIONS
24506c3fb27SDimitry Andric#    if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
24606c3fb27SDimitry Andric#      error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
24706c3fb27SDimitry Andric#    endif
2485f757f3fSDimitry Andric#    if _LIBCPP_ENABLE_ASSERTIONS
2495f757f3fSDimitry Andric#      define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE
2505f757f3fSDimitry Andric#    endif
2515f757f3fSDimitry Andric#  endif
25206c3fb27SDimitry Andric
2535f757f3fSDimitry Andric// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
2548a4dda33SDimitry Andric//
2555f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE`;
2565f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST`;
2575f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
2585f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG`.
25906c3fb27SDimitry Andric//
2605f757f3fSDimitry Andric// These values have the following effects:
26106c3fb27SDimitry Andric//
2625f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
2635f757f3fSDimitry Andric//
2645f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
2655f757f3fSDimitry Andric//   that can be done with relatively little runtime overhead in constant time;
2665f757f3fSDimitry Andric//
2675f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
2685f757f3fSDimitry Andric//   the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
2695f757f3fSDimitry Andric//   but are not necessarily security-critical;
2705f757f3fSDimitry Andric//
2715f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
2725f757f3fSDimitry Andric//   mode and enables all checks available in the library, including internal assertions. Checks that are part of the
2735f757f3fSDimitry Andric//   debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production.
27406c3fb27SDimitry Andric
27506c3fb27SDimitry Andric// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
27606c3fb27SDimitry Andric// macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
27706c3fb27SDimitry Andric//
27806c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
27906c3fb27SDimitry Andric//   a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
28006c3fb27SDimitry Andric//   - the sentinel is reachable from the begin iterator;
28106c3fb27SDimitry Andric//   - TODO(hardening): both iterators refer to the same container.
28206c3fb27SDimitry Andric//
28306c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
28406c3fb27SDimitry Andric//   the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
28506c3fb27SDimitry Andric//   a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
28606c3fb27SDimitry Andric//   `optional` and `function` are considered one-element containers for the purposes of this check.
28706c3fb27SDimitry Andric//
2885f757f3fSDimitry Andric// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
2895f757f3fSDimitry Andric//   address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
2905f757f3fSDimitry Andric//   memory security of a program (however, it is still undefined behavior that can result in strange errors due to
2915f757f3fSDimitry Andric//   compiler optimizations).
2925f757f3fSDimitry Andric//
29306c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
29406c3fb27SDimitry Andric//   given ranges do not overlap.
29506c3fb27SDimitry Andric//
296*7a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object
297*7a6dacacSDimitry Andric//   was allocated by the given allocator). Violating this category typically results in a memory leak.
298*7a6dacacSDimitry Andric//
299*7a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in
300*7a6dacacSDimitry Andric//   an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like
301*7a6dacacSDimitry Andric//   attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category
302*7a6dacacSDimitry Andric//   (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or
303*7a6dacacSDimitry Andric//   otherwise create an immediate security issue.
304*7a6dacacSDimitry Andric//
30506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
30606c3fb27SDimitry Andric//   the containers have compatible allocators.
30706c3fb27SDimitry Andric//
308*7a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments
309*7a6dacacSDimitry Andric//   for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the
310*7a6dacacSDimitry Andric//   original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g.
311*7a6dacacSDimitry Andric//   a string view where only a subset of elements is possible to access). This category is for assertions violating
312*7a6dacacSDimitry Andric//   which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the
313*7a6dacacSDimitry Andric//   user code.
314*7a6dacacSDimitry Andric//
3151db9f3b2SDimitry Andric// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to
3161db9f3b2SDimitry Andric//   be benign in our implementation.
3171db9f3b2SDimitry Andric//
318*7a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed
319*7a6dacacSDimitry Andric//   by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied;
320*7a6dacacSDimitry Andric//   thus, this would often be a heuristic check and it might be quite expensive.
321*7a6dacacSDimitry Andric//
32206c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
32306c3fb27SDimitry Andric//   user input.
32406c3fb27SDimitry Andric//
32506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
32606c3fb27SDimitry Andric
3275f757f3fSDimitry Andric// clang-format off
3285f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_NONE      (1 << 1)
3295f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_FAST      (1 << 2)
3305f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
3315f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_DEBUG     (1 << 3)
3325f757f3fSDimitry Andric// clang-format on
3335f757f3fSDimitry Andric
3345f757f3fSDimitry Andric#  ifndef _LIBCPP_HARDENING_MODE
3355f757f3fSDimitry Andric#    define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
33606c3fb27SDimitry Andric#  endif
33706c3fb27SDimitry Andric
3385f757f3fSDimitry Andric#  if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE &&                                                         \
3395f757f3fSDimitry Andric      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST &&                                                         \
3405f757f3fSDimitry Andric      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE &&                                                    \
3415f757f3fSDimitry Andric      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
3425f757f3fSDimitry Andric#    error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
3435f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_NONE, \
3445f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_FAST, \
3455f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_EXTENSIVE, \
3465f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_DEBUG
34706c3fb27SDimitry Andric#  endif
34806c3fb27SDimitry Andric
34906c3fb27SDimitry Andric// clang-format off
3505f757f3fSDimitry Andric// Fast hardening mode checks.
3515f757f3fSDimitry Andric
3525f757f3fSDimitry Andric#  if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
35306c3fb27SDimitry Andric
35406c3fb27SDimitry Andric// Enabled checks.
35506c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)        _LIBCPP_ASSERT(expression, message)
35606c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)     _LIBCPP_ASSERT(expression, message)
35706c3fb27SDimitry Andric// Disabled checks.
3585f757f3fSDimitry Andric// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access.
3595f757f3fSDimitry Andric#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                 _LIBCPP_ASSUME(expression)
36006c3fb27SDimitry Andric// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security
36106c3fb27SDimitry Andric// vulnerability.
36206c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)   _LIBCPP_ASSUME(expression)
363*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message)       _LIBCPP_ASSUME(expression)
364*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message)  _LIBCPP_ASSUME(expression)
36506c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)     _LIBCPP_ASSUME(expression)
366*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message)   _LIBCPP_ASSUME(expression)
3671db9f3b2SDimitry Andric#    define _LIBCPP_ASSERT_PEDANTIC(expression, message)                 _LIBCPP_ASSUME(expression)
368*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message)     _LIBCPP_ASSUME(expression)
36906c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                 _LIBCPP_ASSUME(expression)
37006c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)            _LIBCPP_ASSUME(expression)
37106c3fb27SDimitry Andric
3725f757f3fSDimitry Andric// Extensive hardening mode checks.
37306c3fb27SDimitry Andric
3745f757f3fSDimitry Andric#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
37506c3fb27SDimitry Andric
3765f757f3fSDimitry Andric// Enabled checks.
37706c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)        _LIBCPP_ASSERT(expression, message)
37806c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)     _LIBCPP_ASSERT(expression, message)
3795f757f3fSDimitry Andric#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                 _LIBCPP_ASSERT(expression, message)
38006c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)   _LIBCPP_ASSERT(expression, message)
381*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message)       _LIBCPP_ASSERT(expression, message)
382*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message)  _LIBCPP_ASSERT(expression, message)
38306c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)     _LIBCPP_ASSERT(expression, message)
384*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message)   _LIBCPP_ASSERT(expression, message)
3851db9f3b2SDimitry Andric#    define _LIBCPP_ASSERT_PEDANTIC(expression, message)                 _LIBCPP_ASSERT(expression, message)
386*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)            _LIBCPP_ASSERT(expression, message)
3875f757f3fSDimitry Andric// Disabled checks.
388*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message)     _LIBCPP_ASSUME(expression)
3895f757f3fSDimitry Andric#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                 _LIBCPP_ASSUME(expression)
39006c3fb27SDimitry Andric
3915f757f3fSDimitry Andric// Debug hardening mode checks.
3928a4dda33SDimitry Andric
3935f757f3fSDimitry Andric#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
3948a4dda33SDimitry Andric
3958a4dda33SDimitry Andric// All checks enabled.
3968a4dda33SDimitry Andric#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)         _LIBCPP_ASSERT(expression, message)
3978a4dda33SDimitry Andric#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)      _LIBCPP_ASSERT(expression, message)
3985f757f3fSDimitry Andric#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                  _LIBCPP_ASSERT(expression, message)
3998a4dda33SDimitry Andric#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)    _LIBCPP_ASSERT(expression, message)
400*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message)        _LIBCPP_ASSERT(expression, message)
401*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message)   _LIBCPP_ASSERT(expression, message)
4028a4dda33SDimitry Andric#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)      _LIBCPP_ASSERT(expression, message)
403*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message)    _LIBCPP_ASSERT(expression, message)
4041db9f3b2SDimitry Andric#    define _LIBCPP_ASSERT_PEDANTIC(expression, message)                  _LIBCPP_ASSERT(expression, message)
405*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message)      _LIBCPP_ASSERT(expression, message)
4068a4dda33SDimitry Andric#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                  _LIBCPP_ASSERT(expression, message)
4078a4dda33SDimitry Andric#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)             _LIBCPP_ASSERT(expression, message)
4088a4dda33SDimitry Andric
40906c3fb27SDimitry Andric// Disable all checks if hardening is not enabled.
41006c3fb27SDimitry Andric
41106c3fb27SDimitry Andric#  else
41206c3fb27SDimitry Andric
41306c3fb27SDimitry Andric// All checks disabled.
41406c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)         _LIBCPP_ASSUME(expression)
41506c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)      _LIBCPP_ASSUME(expression)
4165f757f3fSDimitry Andric#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                  _LIBCPP_ASSUME(expression)
41706c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)    _LIBCPP_ASSUME(expression)
418*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message)        _LIBCPP_ASSUME(expression)
419*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message)   _LIBCPP_ASSUME(expression)
42006c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)      _LIBCPP_ASSUME(expression)
421*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message)    _LIBCPP_ASSUME(expression)
4221db9f3b2SDimitry Andric#    define _LIBCPP_ASSERT_PEDANTIC(expression, message)                  _LIBCPP_ASSUME(expression)
423*7a6dacacSDimitry Andric#    define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message)      _LIBCPP_ASSUME(expression)
42406c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                  _LIBCPP_ASSUME(expression)
42506c3fb27SDimitry Andric#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)             _LIBCPP_ASSUME(expression)
42606c3fb27SDimitry Andric
4275f757f3fSDimitry Andric#  endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
42806c3fb27SDimitry Andric// clang-format on
42906c3fb27SDimitry Andric
43006c3fb27SDimitry Andric// } HARDENING
43106c3fb27SDimitry Andric
43281ad6265SDimitry Andric#  define _LIBCPP_TOSTRING2(x) #x
43381ad6265SDimitry Andric#  define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
4340b57cec5SDimitry Andric
43506c3fb27SDimitry Andric// NOLINTNEXTLINE(libcpp-cpp-version-check)
4360b57cec5SDimitry Andric#  if __cplusplus < 201103L
4370b57cec5SDimitry Andric#    define _LIBCPP_CXX03_LANG
4380b57cec5SDimitry Andric#  endif
4390b57cec5SDimitry Andric
4400b57cec5SDimitry Andric#  ifndef __has_attribute
4410b57cec5SDimitry Andric#    define __has_attribute(__x) 0
4420b57cec5SDimitry Andric#  endif
4430b57cec5SDimitry Andric
4440b57cec5SDimitry Andric#  ifndef __has_builtin
4450b57cec5SDimitry Andric#    define __has_builtin(__x) 0
4460b57cec5SDimitry Andric#  endif
4470b57cec5SDimitry Andric
4480b57cec5SDimitry Andric#  ifndef __has_extension
4490b57cec5SDimitry Andric#    define __has_extension(__x) 0
4500b57cec5SDimitry Andric#  endif
4510b57cec5SDimitry Andric
4520b57cec5SDimitry Andric#  ifndef __has_feature
4530b57cec5SDimitry Andric#    define __has_feature(__x) 0
4540b57cec5SDimitry Andric#  endif
4550b57cec5SDimitry Andric
4560b57cec5SDimitry Andric#  ifndef __has_cpp_attribute
4570b57cec5SDimitry Andric#    define __has_cpp_attribute(__x) 0
4580b57cec5SDimitry Andric#  endif
4590b57cec5SDimitry Andric
460bdd1243dSDimitry Andric#  ifndef __has_constexpr_builtin
461bdd1243dSDimitry Andric#    define __has_constexpr_builtin(x) 0
462bdd1243dSDimitry Andric#  endif
463bdd1243dSDimitry Andric
4640b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
4650b57cec5SDimitry Andric// the compiler and '1' otherwise.
4660b57cec5SDimitry Andric#  ifndef __is_identifier
4670b57cec5SDimitry Andric#    define __is_identifier(__x) 1
4680b57cec5SDimitry Andric#  endif
4690b57cec5SDimitry Andric
4700b57cec5SDimitry Andric#  ifndef __has_declspec_attribute
4710b57cec5SDimitry Andric#    define __has_declspec_attribute(__x) 0
4720b57cec5SDimitry Andric#  endif
4730b57cec5SDimitry Andric
4740b57cec5SDimitry Andric#  define __has_keyword(__x) !(__is_identifier(__x))
4750b57cec5SDimitry Andric
4760b57cec5SDimitry Andric#  ifndef __has_include
4770b57cec5SDimitry Andric#    define __has_include(...) 0
4780b57cec5SDimitry Andric#  endif
4790b57cec5SDimitry Andric
48081ad6265SDimitry Andric#  if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
48181ad6265SDimitry Andric#    error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
4820b57cec5SDimitry Andric#  endif
4830b57cec5SDimitry Andric
4840b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This
4850b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume
4860b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
4870b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this
4880b57cec5SDimitry Andric// heuristic falls short.
4890b57cec5SDimitry Andric#  if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
4900b57cec5SDimitry Andric#    error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
4910b57cec5SDimitry Andric#  elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
4920b57cec5SDimitry Andric#    define _LIBCPP_ABI_ITANIUM
4930b57cec5SDimitry Andric#  elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
4940b57cec5SDimitry Andric#    define _LIBCPP_ABI_MICROSOFT
4950b57cec5SDimitry Andric#  else
4960b57cec5SDimitry Andric#    if defined(_WIN32) && defined(_MSC_VER)
4970b57cec5SDimitry Andric#      define _LIBCPP_ABI_MICROSOFT
4980b57cec5SDimitry Andric#    else
4990b57cec5SDimitry Andric#      define _LIBCPP_ABI_ITANIUM
5000b57cec5SDimitry Andric#    endif
5010b57cec5SDimitry Andric#  endif
5020b57cec5SDimitry Andric
5030b57cec5SDimitry Andric#  if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
5040b57cec5SDimitry Andric#    define _LIBCPP_ABI_VCRUNTIME
5050b57cec5SDimitry Andric#  endif
5060b57cec5SDimitry Andric
507fcaf7f86SDimitry Andric#  if __has_feature(experimental_library)
508fcaf7f86SDimitry Andric#    ifndef _LIBCPP_ENABLE_EXPERIMENTAL
509fcaf7f86SDimitry Andric#      define _LIBCPP_ENABLE_EXPERIMENTAL
510fcaf7f86SDimitry Andric#    endif
511fcaf7f86SDimitry Andric#  endif
512fcaf7f86SDimitry Andric
513fcaf7f86SDimitry Andric// Incomplete features get their own specific disabling flags. This makes it
514fcaf7f86SDimitry Andric// easier to grep for target specific flags once the feature is complete.
515fcaf7f86SDimitry Andric#  if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
51606c3fb27SDimitry Andric#    define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
51706c3fb27SDimitry Andric#    define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
5185f757f3fSDimitry Andric#    define _LIBCPP_HAS_NO_INCOMPLETE_TZDB
5195f757f3fSDimitry Andric#    define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM
520fcaf7f86SDimitry Andric#  endif
521fcaf7f86SDimitry Andric
5220b57cec5SDimitry Andric// Need to detect which libc we're using if we're on Linux.
5230b57cec5SDimitry Andric#  if defined(__linux__)
5240b57cec5SDimitry Andric#    include <features.h>
5250b57cec5SDimitry Andric#    if defined(__GLIBC_PREREQ)
5260b57cec5SDimitry Andric#      define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
5270b57cec5SDimitry Andric#    else
5280b57cec5SDimitry Andric#      define _LIBCPP_GLIBC_PREREQ(a, b) 0
5290b57cec5SDimitry Andric#    endif // defined(__GLIBC_PREREQ)
5300b57cec5SDimitry Andric#  endif   // defined(__linux__)
5310b57cec5SDimitry Andric
53204eeddc0SDimitry Andric#  if defined(__MVS__)
53304eeddc0SDimitry Andric#    include <features.h> // for __NATIVE_ASCII_F
53404eeddc0SDimitry Andric#  endif
53504eeddc0SDimitry Andric
5365f757f3fSDimitry Andric#  ifndef __BYTE_ORDER__
5375f757f3fSDimitry Andric#    error                                                                                                             \
5385f757f3fSDimitry Andric        "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform"
5395f757f3fSDimitry Andric#  endif
5400b57cec5SDimitry Andric
5410b57cec5SDimitry Andric#  if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
5420b57cec5SDimitry Andric#    define _LIBCPP_LITTLE_ENDIAN
5430b57cec5SDimitry Andric#  elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
5440b57cec5SDimitry Andric#    define _LIBCPP_BIG_ENDIAN
5450b57cec5SDimitry Andric#  endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
5460b57cec5SDimitry Andric
5470b57cec5SDimitry Andric#  if defined(_WIN32)
5480b57cec5SDimitry Andric#    define _LIBCPP_WIN32API
5490b57cec5SDimitry Andric#    define _LIBCPP_SHORT_WCHAR 1
5500b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment
5510b57cec5SDimitry Andric#    define _LIBCPP_MSVCRT_LIKE
5520b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if
5530b57cec5SDimitry Andric// a MS compatibility version is specified.
5540b57cec5SDimitry Andric#    if defined(_MSC_VER) && !defined(__MINGW32__)
5550b57cec5SDimitry Andric#      define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
5560b57cec5SDimitry Andric#    endif
5570b57cec5SDimitry Andric#    if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
5580b57cec5SDimitry Andric#      define _LIBCPP_HAS_BITSCAN64
5590b57cec5SDimitry Andric#    endif
5600b57cec5SDimitry Andric#    define _LIBCPP_HAS_OPEN_WITH_WCHAR
5610b57cec5SDimitry Andric#  endif // defined(_WIN32)
5620b57cec5SDimitry Andric
563349cc55cSDimitry Andric#  if defined(_AIX) && !defined(__64BIT__)
564349cc55cSDimitry Andric// The size of wchar is 2 byte on 32-bit mode on AIX.
565349cc55cSDimitry Andric#    define _LIBCPP_SHORT_WCHAR 1
566349cc55cSDimitry Andric#  endif
567349cc55cSDimitry Andric
5680eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device.
5690eae32dcSDimitry Andric//
5700eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM
5710eae32dcSDimitry Andric//      Read entropy from the given file, by default `/dev/urandom`.
5720eae32dcSDimitry Andric//      If a token is provided, it is assumed to be the path to a file
5730eae32dcSDimitry Andric//      to read entropy from. This is the default behavior if nothing
5740eae32dcSDimitry Andric//      else is specified. This implementation requires storing state
5750eae32dcSDimitry Andric//      inside `std::random_device`.
5760eae32dcSDimitry Andric//
5770eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM
5780eae32dcSDimitry Andric//      Use arc4random(). This allows obtaining random data even when
5790eae32dcSDimitry Andric//      using sandboxing mechanisms. On some platforms like Apple, this
5800eae32dcSDimitry Andric//      is the recommended source of entropy for user-space programs.
5810eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
5820eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
5830eae32dcSDimitry Andric//
5840eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY
5850eae32dcSDimitry Andric//      Use getentropy().
5860eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
5870eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
5880eae32dcSDimitry Andric//
58904eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG
59004eeddc0SDimitry Andric//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
59104eeddc0SDimitry Andric//      deliver high-quality entropy and cannot fail.
59204eeddc0SDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
59304eeddc0SDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
59404eeddc0SDimitry Andric//
5950eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM
5960eae32dcSDimitry Andric//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
5970eae32dcSDimitry Andric//      including accesses to the special files under `/dev`. This implementation
5980eae32dcSDimitry Andric//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
5990eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
6000eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
6010eae32dcSDimitry Andric//
6020eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM
6030eae32dcSDimitry Andric//      Use rand_s(), for use on Windows.
6040eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
6050eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
60681ad6265SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
60706c3fb27SDimitry Andric      defined(__DragonFly__)
6080b57cec5SDimitry Andric#    define _LIBCPP_USING_ARC4_RANDOM
60981ad6265SDimitry Andric#  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
6100b57cec5SDimitry Andric#    define _LIBCPP_USING_GETENTROPY
61104eeddc0SDimitry Andric#  elif defined(__Fuchsia__)
61204eeddc0SDimitry Andric#    define _LIBCPP_USING_FUCHSIA_CPRNG
6130b57cec5SDimitry Andric#  elif defined(__native_client__)
6140b57cec5SDimitry Andric#    define _LIBCPP_USING_NACL_RANDOM
6150b57cec5SDimitry Andric#  elif defined(_LIBCPP_WIN32API)
6160b57cec5SDimitry Andric#    define _LIBCPP_USING_WIN32_RANDOM
6170b57cec5SDimitry Andric#  else
6180b57cec5SDimitry Andric#    define _LIBCPP_USING_DEV_RANDOM
6190b57cec5SDimitry Andric#  endif
6200b57cec5SDimitry Andric
6210b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
62281ad6265SDimitry Andric
6230b57cec5SDimitry Andric#    define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
62481ad6265SDimitry Andric#    define _ALIGNAS_TYPE(x) alignas(x)
62581ad6265SDimitry Andric#    define _ALIGNAS(x) alignas(x)
62681ad6265SDimitry Andric#    define _LIBCPP_NORETURN [[noreturn]]
62781ad6265SDimitry Andric#    define _NOEXCEPT noexcept
62881ad6265SDimitry Andric#    define _NOEXCEPT_(x) noexcept(x)
629bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR constexpr
63081ad6265SDimitry Andric
6310b57cec5SDimitry Andric#  else
63281ad6265SDimitry Andric
63381ad6265SDimitry Andric#    define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
63481ad6265SDimitry Andric#    define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
63581ad6265SDimitry Andric#    define _ALIGNAS(x) __attribute__((__aligned__(x)))
636bdd1243dSDimitry Andric#    define _LIBCPP_NORETURN __attribute__((__noreturn__))
63781ad6265SDimitry Andric#    define _LIBCPP_HAS_NO_NOEXCEPT
63881ad6265SDimitry Andric#    define nullptr __nullptr
63981ad6265SDimitry Andric#    define _NOEXCEPT throw()
64081ad6265SDimitry Andric#    define _NOEXCEPT_(x)
641bdd1243dSDimitry Andric#    define static_assert(...) _Static_assert(__VA_ARGS__)
642bdd1243dSDimitry Andric#    define decltype(...) __decltype(__VA_ARGS__)
643bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR
64481ad6265SDimitry Andric
64581ad6265SDimitry Andrictypedef __char16_t char16_t;
64681ad6265SDimitry Andrictypedef __char32_t char32_t;
64781ad6265SDimitry Andric
64881ad6265SDimitry Andric#  endif
64981ad6265SDimitry Andric
65081ad6265SDimitry Andric#  if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
65106c3fb27SDimitry Andric#    define _LIBCPP_HAS_NO_EXCEPTIONS
6520b57cec5SDimitry Andric#  endif
6530b57cec5SDimitry Andric
6540b57cec5SDimitry Andric#  define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
6550b57cec5SDimitry Andric
656fe6060f1SDimitry Andric#  if defined(_LIBCPP_COMPILER_CLANG_BASED)
6570b57cec5SDimitry Andric
65806c3fb27SDimitry Andric#    if defined(__APPLE__)
65906c3fb27SDimitry Andric#      if defined(__i386__) || defined(__x86_64__)
66006c3fb27SDimitry Andric// use old string layout on x86_64 and i386
66106c3fb27SDimitry Andric#      elif defined(__arm__)
66206c3fb27SDimitry Andric// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs
66306c3fb27SDimitry Andric#        if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2
6640b57cec5SDimitry Andric#          define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
6650b57cec5SDimitry Andric#        endif
66606c3fb27SDimitry Andric#      else
66706c3fb27SDimitry Andric#        define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
66806c3fb27SDimitry Andric#      endif
66906c3fb27SDimitry Andric#    endif
6700b57cec5SDimitry Andric
6710b57cec5SDimitry Andric// Objective-C++ features (opt-in)
6720b57cec5SDimitry Andric#    if __has_feature(objc_arc)
6730b57cec5SDimitry Andric#      define _LIBCPP_HAS_OBJC_ARC
6740b57cec5SDimitry Andric#    endif
6750b57cec5SDimitry Andric
6760b57cec5SDimitry Andric#    if __has_feature(objc_arc_weak)
6770b57cec5SDimitry Andric#      define _LIBCPP_HAS_OBJC_ARC_WEAK
6780b57cec5SDimitry Andric#    endif
6790b57cec5SDimitry Andric
6805ffd83dbSDimitry Andric#    if __has_extension(blocks)
6815ffd83dbSDimitry Andric#      define _LIBCPP_HAS_EXTENSION_BLOCKS
6825ffd83dbSDimitry Andric#    endif
6835ffd83dbSDimitry Andric
6845ffd83dbSDimitry Andric#    if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
6855ffd83dbSDimitry Andric#      define _LIBCPP_HAS_BLOCKS_RUNTIME
6865ffd83dbSDimitry Andric#    endif
6875ffd83dbSDimitry Andric
688fe6060f1SDimitry Andric#    if !__has_feature(address_sanitizer)
6890b57cec5SDimitry Andric#      define _LIBCPP_HAS_NO_ASAN
6900b57cec5SDimitry Andric#    endif
6910b57cec5SDimitry Andric
6920b57cec5SDimitry Andric#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
6930b57cec5SDimitry Andric
694e40139ffSDimitry Andric#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
695e40139ffSDimitry Andric
6960b57cec5SDimitry Andric#  elif defined(_LIBCPP_COMPILER_GCC)
6970b57cec5SDimitry Andric
698fe6060f1SDimitry Andric#    if !defined(__SANITIZE_ADDRESS__)
6990b57cec5SDimitry Andric#      define _LIBCPP_HAS_NO_ASAN
7000b57cec5SDimitry Andric#    endif
7010b57cec5SDimitry Andric
7020b57cec5SDimitry Andric#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
7030b57cec5SDimitry Andric
704e40139ffSDimitry Andric#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
705e40139ffSDimitry Andric
706bdd1243dSDimitry Andric#  endif // _LIBCPP_COMPILER_[CLANG|GCC]
7070b57cec5SDimitry Andric
7080b57cec5SDimitry Andric#  if defined(_LIBCPP_OBJECT_FORMAT_COFF)
7090b57cec5SDimitry Andric
7100b57cec5SDimitry Andric#    ifdef _DLL
7110b57cec5SDimitry Andric#      define _LIBCPP_CRT_FUNC __declspec(dllimport)
7120b57cec5SDimitry Andric#    else
7130b57cec5SDimitry Andric#      define _LIBCPP_CRT_FUNC
7140b57cec5SDimitry Andric#    endif
7150b57cec5SDimitry Andric
71681ad6265SDimitry Andric#    if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
7170b57cec5SDimitry Andric#      define _LIBCPP_DLL_VIS
7180b57cec5SDimitry Andric#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
7190b57cec5SDimitry Andric#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
7200b57cec5SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
7210b57cec5SDimitry Andric#      define _LIBCPP_EXPORTED_FROM_ABI
7220b57cec5SDimitry Andric#    elif defined(_LIBCPP_BUILDING_LIBRARY)
7230b57cec5SDimitry Andric#      define _LIBCPP_DLL_VIS __declspec(dllexport)
7240b57cec5SDimitry Andric#      if defined(__MINGW32__)
7250b57cec5SDimitry Andric#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
7260b57cec5SDimitry Andric#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
7270b57cec5SDimitry Andric#      else
7280b57cec5SDimitry Andric#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
7290b57cec5SDimitry Andric#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
7300b57cec5SDimitry Andric#      endif
7310b57cec5SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
7320b57cec5SDimitry Andric#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
7330b57cec5SDimitry Andric#    else
7340b57cec5SDimitry Andric#      define _LIBCPP_DLL_VIS __declspec(dllimport)
7350b57cec5SDimitry Andric#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
7360b57cec5SDimitry Andric#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
7370b57cec5SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
7380b57cec5SDimitry Andric#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
7390b57cec5SDimitry Andric#    endif
7400b57cec5SDimitry Andric
7410b57cec5SDimitry Andric#    define _LIBCPP_HIDDEN
7420b57cec5SDimitry Andric#    define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
7430b57cec5SDimitry Andric#    define _LIBCPP_TEMPLATE_VIS
744fe6060f1SDimitry Andric#    define _LIBCPP_TEMPLATE_DATA_VIS
7455f757f3fSDimitry Andric#    define _LIBCPP_TYPE_VISIBILITY_DEFAULT
7460b57cec5SDimitry Andric
7470b57cec5SDimitry Andric#  else
74881ad6265SDimitry Andric
74981ad6265SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
75081ad6265SDimitry Andric#      define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
75181ad6265SDimitry Andric#    else
75281ad6265SDimitry Andric#      define _LIBCPP_VISIBILITY(vis)
7530b57cec5SDimitry Andric#    endif
7540b57cec5SDimitry Andric
75581ad6265SDimitry Andric#    define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
75681ad6265SDimitry Andric#    define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
75781ad6265SDimitry Andric#    define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
75881ad6265SDimitry Andric#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
75981ad6265SDimitry Andric#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
76081ad6265SDimitry Andric
761fcaf7f86SDimitry Andric// TODO: Make this a proper customization point or remove the option to override it.
762fcaf7f86SDimitry Andric#    ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
763fcaf7f86SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
764fcaf7f86SDimitry Andric#    endif
765fcaf7f86SDimitry Andric
7660b57cec5SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
7670b57cec5SDimitry Andric// The inline should be removed once PR32114 is resolved
7680b57cec5SDimitry Andric#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
7690b57cec5SDimitry Andric#    else
7700b57cec5SDimitry Andric#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
7710b57cec5SDimitry Andric#    endif
7720b57cec5SDimitry Andric
7735f757f3fSDimitry Andric// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
7745f757f3fSDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
7750b57cec5SDimitry Andric#      define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
7760b57cec5SDimitry Andric#    else
7770b57cec5SDimitry Andric#      define _LIBCPP_TEMPLATE_VIS
7780b57cec5SDimitry Andric#    endif
7790b57cec5SDimitry Andric
78046c59ea9SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) && \
78146c59ea9SDimitry Andric        _LIBCPP_CLANG_VER >= 1500 // FreeBSD customization
7825f757f3fSDimitry Andric#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
7830b57cec5SDimitry Andric#    else
7845f757f3fSDimitry Andric#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT
7850b57cec5SDimitry Andric#    endif
7860b57cec5SDimitry Andric
78781ad6265SDimitry Andric#  endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
7880b57cec5SDimitry Andric
7890b57cec5SDimitry Andric#  if __has_attribute(exclude_from_explicit_instantiation)
7900b57cec5SDimitry Andric#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
7910b57cec5SDimitry Andric#  else
7920b57cec5SDimitry Andric// Try to approximate the effect of exclude_from_explicit_instantiation
7930b57cec5SDimitry Andric// (which is that entities are not assumed to be provided by explicit
7940b57cec5SDimitry Andric// template instantiations in the dylib) by always inlining those entities.
7950b57cec5SDimitry Andric#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
7960b57cec5SDimitry Andric#  endif
7970b57cec5SDimitry Andric
7985f757f3fSDimitry Andric#  if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
7995f757f3fSDimitry Andric#    define _LIBCPP_HARDENING_SIG f
8005f757f3fSDimitry Andric#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
801b121cb00SDimitry Andric#    define _LIBCPP_HARDENING_SIG s
8025f757f3fSDimitry Andric#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
803b121cb00SDimitry Andric#    define _LIBCPP_HARDENING_SIG d
804b121cb00SDimitry Andric#  else
8055f757f3fSDimitry Andric#    define _LIBCPP_HARDENING_SIG n // "none"
806b121cb00SDimitry Andric#  endif
807b121cb00SDimitry Andric
808b121cb00SDimitry Andric#  ifdef _LIBCPP_HAS_NO_EXCEPTIONS
809b121cb00SDimitry Andric#    define _LIBCPP_EXCEPTIONS_SIG n
810b121cb00SDimitry Andric#  else
811b121cb00SDimitry Andric#    define _LIBCPP_EXCEPTIONS_SIG e
812b121cb00SDimitry Andric#  endif
813b121cb00SDimitry Andric
814b121cb00SDimitry Andric#  define _LIBCPP_ODR_SIGNATURE                                                                                        \
815b121cb00SDimitry Andric    _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
816b121cb00SDimitry Andric
817753f127fSDimitry Andric// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
818753f127fSDimitry Andric// on two levels:
819753f127fSDimitry Andric// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
820753f127fSDimitry Andric//    symbols from their dynamic library by means of using the libc++ headers. This ensures
821753f127fSDimitry Andric//    that those symbols stay private to the dynamic library in which it is defined.
822753f127fSDimitry Andric//
823b121cb00SDimitry Andric// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
824b121cb00SDimitry Andric//    This ensures that no ODR violation can arise from mixing two TUs compiled with different
825b121cb00SDimitry Andric//    versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
826b121cb00SDimitry Andric//    program contains two definitions of a function, the ODR requires them to be token-by-token
827b121cb00SDimitry Andric//    equivalent, and the linker is allowed to pick either definition and discard the other one.
828b121cb00SDimitry Andric//
829b121cb00SDimitry Andric//    For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
830b121cb00SDimitry Andric//    *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
831b121cb00SDimitry Andric//    compiled with different settings), the two definitions are both visible by the linker and they
832b121cb00SDimitry Andric//    have the same name, but they have a meaningfully different implementation (one throws an exception
833b121cb00SDimitry Andric//    and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
834b121cb00SDimitry Andric//    practice what will happen is that the linker will pick one of the definitions at random and will
835b121cb00SDimitry Andric//    discard the other one. This can quite clearly lead to incorrect program behavior.
836b121cb00SDimitry Andric//
837b121cb00SDimitry Andric//    A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
838b121cb00SDimitry Andric//    property that causes the code of a function to differ from the code in another configuration
839b121cb00SDimitry Andric//    can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
840b121cb00SDimitry Andric//    tag, but we encode the ones that we think are most important: library version, exceptions, and
841b121cb00SDimitry Andric//    hardening mode.
842b121cb00SDimitry Andric//
843b121cb00SDimitry Andric//    Note that historically, solving this problem has been achieved in various ways, including
844b121cb00SDimitry Andric//    force-inlining all functions or giving internal linkage to all functions. Both these previous
845b121cb00SDimitry Andric//    solutions suffer from drawbacks that lead notably to code bloat.
846753f127fSDimitry Andric//
847753f127fSDimitry Andric// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
848753f127fSDimitry Andric// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
849753f127fSDimitry Andric//
850bdd1243dSDimitry Andric// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
851bdd1243dSDimitry Andric// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
852bdd1243dSDimitry Andric// name of a virtual function is part of its ABI, since some architectures like arm64e can sign
853bdd1243dSDimitry Andric// the virtual function pointer in the vtable based on the mangled name of the function. Since
854bdd1243dSDimitry Andric// we use an ABI tag that changes with each released version, the mangled name of the virtual
855bdd1243dSDimitry Andric// function would change, which is incorrect. Note that it doesn't make much sense to change
856bdd1243dSDimitry Andric// the implementation of a virtual function in an ABI-incompatible way in the first place,
857bdd1243dSDimitry Andric// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
858bdd1243dSDimitry Andric//
859753f127fSDimitry Andric// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
860753f127fSDimitry Andric//       the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
861753f127fSDimitry Andric//       use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
862753f127fSDimitry Andric#  ifndef _LIBCPP_NO_ABI_TAG
863753f127fSDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI                                                                                      \
864753f127fSDimitry Andric      _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION                                                       \
865b121cb00SDimitry Andric          __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
8660b57cec5SDimitry Andric#  else
8670b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
8680b57cec5SDimitry Andric#  endif
869bdd1243dSDimitry Andric#  define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
8700b57cec5SDimitry Andric
8711ac55f4cSDimitry Andric// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern
8721ac55f4cSDimitry Andric// "C" function, as those lack mangling.
8731ac55f4cSDimitry Andric#  define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
8741ac55f4cSDimitry Andric
8750b57cec5SDimitry Andric#  ifdef _LIBCPP_BUILDING_LIBRARY
8760b57cec5SDimitry Andric#    if _LIBCPP_ABI_VERSION > 1
8770b57cec5SDimitry Andric#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
8780b57cec5SDimitry Andric#    else
8790b57cec5SDimitry Andric#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
8800b57cec5SDimitry Andric#    endif
8810b57cec5SDimitry Andric#  else
8820b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
8830b57cec5SDimitry Andric#  endif
8840b57cec5SDimitry Andric
8855f757f3fSDimitry Andric// TODO(LLVM-19): Remove _LIBCPP_INLINE_VISIBILITY and _VSTD, which we're keeping around
8865f757f3fSDimitry Andric//                only to ease the renaming for downstreams.
8870b57cec5SDimitry Andric#  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
8885f757f3fSDimitry Andric#  define _VSTD std
8890b57cec5SDimitry Andric
8900b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
89181ad6265SDimitry Andric// clang-format off
8925f757f3fSDimitry Andric#  define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std {                                  \
8935f757f3fSDimitry Andric                               inline namespace _LIBCPP_ABI_NAMESPACE {
8940b57cec5SDimitry Andric#  define _LIBCPP_END_NAMESPACE_STD }}
89581ad6265SDimitry Andric
8965f757f3fSDimitry Andric#  define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD                                               \
8975f757f3fSDimitry Andric                                             inline namespace __fs { namespace filesystem {
8980b57cec5SDimitry Andric
89981ad6265SDimitry Andric#  define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
90081ad6265SDimitry Andric// clang-format on
9010b57cec5SDimitry Andric
9020b57cec5SDimitry Andric#  if __has_attribute(__enable_if__)
9030b57cec5SDimitry Andric#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
9040b57cec5SDimitry Andric#  endif
9050b57cec5SDimitry Andric
90606c3fb27SDimitry Andric#  if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
9070b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_INT128
9080b57cec5SDimitry Andric#  endif
9090b57cec5SDimitry Andric
91081ad6265SDimitry Andric#  ifdef _LIBCPP_CXX03_LANG
91181ad6265SDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM(x)                                                                             \
91206c3fb27SDimitry Andric      struct _LIBCPP_EXPORTED_FROM_ABI x {                                                                             \
91381ad6265SDimitry Andric        enum __lx
91481ad6265SDimitry Andric// clang-format off
9150b57cec5SDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)                                                                      \
9160b57cec5SDimitry Andric      __lx __v_;                                                                                                       \
9175f757f3fSDimitry Andric      _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {}                                                                 \
9185f757f3fSDimitry Andric      _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {}                                      \
9195f757f3fSDimitry Andric      _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; }                                                      \
9200b57cec5SDimitry Andric      };
92181ad6265SDimitry Andric// clang-format on
92281ad6265SDimitry Andric
92381ad6265SDimitry Andric#  else // _LIBCPP_CXX03_LANG
9245f757f3fSDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
9250b57cec5SDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
92681ad6265SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
9270b57cec5SDimitry Andric
92806c3fb27SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
9290b57cec5SDimitry Andric#    define _LIBCPP_LOCALE__L_EXTENSIONS 1
9300b57cec5SDimitry Andric#  endif
9310b57cec5SDimitry Andric
9320b57cec5SDimitry Andric#  ifdef __FreeBSD__
9330b57cec5SDimitry Andric#    define _DECLARE_C99_LDBL_MATH 1
9340b57cec5SDimitry Andric#  endif
9350b57cec5SDimitry Andric
9360b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads
9370b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
9380b57cec5SDimitry Andric#  if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
9390b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
9400b57cec5SDimitry Andric#  elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
9410b57cec5SDimitry Andric// We're deferring to Microsoft's STL to provide aligned new et al. We don't
9420b57cec5SDimitry Andric// have it unless the language feature test macro is defined.
9430b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
944e8d8bef9SDimitry Andric#  elif defined(__MVS__)
945e8d8bef9SDimitry Andric#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
9460b57cec5SDimitry Andric#  endif
9470b57cec5SDimitry Andric
94881ad6265SDimitry Andric#  if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
9490b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
9500b57cec5SDimitry Andric#  endif
9510b57cec5SDimitry Andric
952bdd1243dSDimitry Andric// It is not yet possible to use aligned_alloc() on all Apple platforms since
953bdd1243dSDimitry Andric// 10.15 was the first version to ship an implementation of aligned_alloc().
954bdd1243dSDimitry Andric#  if defined(__APPLE__)
955bdd1243dSDimitry Andric#    if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                                                     \
956bdd1243dSDimitry Andric         __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
957bdd1243dSDimitry Andric#      define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
958bdd1243dSDimitry Andric#    endif
959bdd1243dSDimitry Andric#  elif defined(__ANDROID__) && __ANDROID_API__ < 28
960bdd1243dSDimitry Andric// Android only provides aligned_alloc when targeting API 28 or higher.
961bdd1243dSDimitry Andric#    define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
962bdd1243dSDimitry Andric#  endif
963bdd1243dSDimitry Andric
9640b57cec5SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__)
9650b57cec5SDimitry Andric#    define _LIBCPP_HAS_DEFAULTRUNELOCALE
9660b57cec5SDimitry Andric#  endif
9670b57cec5SDimitry Andric
96806c3fb27SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__)
9690b57cec5SDimitry Andric#    define _LIBCPP_WCTYPE_IS_MASK
9700b57cec5SDimitry Andric#  endif
9710b57cec5SDimitry Andric
9720b57cec5SDimitry Andric#  if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
973fe6060f1SDimitry Andric#    define _LIBCPP_HAS_NO_CHAR8_T
9740b57cec5SDimitry Andric#  endif
9750b57cec5SDimitry Andric
9760b57cec5SDimitry Andric// Deprecation macros.
9770b57cec5SDimitry Andric//
9780b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out
9790b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
9800b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
98106c3fb27SDimitry Andric#    if __has_attribute(__deprecated__)
98206c3fb27SDimitry Andric#      define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
98306c3fb27SDimitry Andric#      define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
98406c3fb27SDimitry Andric#    elif _LIBCPP_STD_VER >= 14
9850b57cec5SDimitry Andric#      define _LIBCPP_DEPRECATED [[deprecated]]
98681ad6265SDimitry Andric#      define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
9870b57cec5SDimitry Andric#    else
9880b57cec5SDimitry Andric#      define _LIBCPP_DEPRECATED
98981ad6265SDimitry Andric#      define _LIBCPP_DEPRECATED_(m)
9900b57cec5SDimitry Andric#    endif
9910b57cec5SDimitry Andric#  else
9920b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED
99381ad6265SDimitry Andric#    define _LIBCPP_DEPRECATED_(m)
9940b57cec5SDimitry Andric#  endif
9950b57cec5SDimitry Andric
9960b57cec5SDimitry Andric#  if !defined(_LIBCPP_CXX03_LANG)
9970b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
9980b57cec5SDimitry Andric#  else
9990b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX11
10000b57cec5SDimitry Andric#  endif
10010b57cec5SDimitry Andric
100206c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
10030b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
10040b57cec5SDimitry Andric#  else
10050b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX14
10060b57cec5SDimitry Andric#  endif
10070b57cec5SDimitry Andric
100806c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
10090b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
10100b57cec5SDimitry Andric#  else
10110b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX17
10120b57cec5SDimitry Andric#  endif
10130b57cec5SDimitry Andric
101406c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
1015e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
1016e8d8bef9SDimitry Andric#  else
1017e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX20
1018e8d8bef9SDimitry Andric#  endif
1019e8d8bef9SDimitry Andric
1020bdd1243dSDimitry Andric#  if _LIBCPP_STD_VER >= 23
1021bdd1243dSDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
1022bdd1243dSDimitry Andric#  else
1023bdd1243dSDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX23
1024bdd1243dSDimitry Andric#  endif
1025bdd1243dSDimitry Andric
1026fe6060f1SDimitry Andric#  if !defined(_LIBCPP_HAS_NO_CHAR8_T)
1027e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
1028e8d8bef9SDimitry Andric#  else
1029e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T
1030e8d8bef9SDimitry Andric#  endif
1031e8d8bef9SDimitry Andric
1032e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed.
1033fe6060f1SDimitry Andric#  if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
1034e40139ffSDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH                                                                           \
103581ad6265SDimitry Andric      _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")                                \
1036fe6060f1SDimitry Andric          _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
103781ad6265SDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
1038fe6060f1SDimitry Andric#  else
1039e40139ffSDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1040e40139ffSDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_POP
1041e40139ffSDimitry Andric#  endif
1042e40139ffSDimitry Andric
10430b57cec5SDimitry Andric#  if _LIBCPP_STD_VER <= 11
104406c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX14
10450b57cec5SDimitry Andric#  else
104606c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
10470b57cec5SDimitry Andric#  endif
10480b57cec5SDimitry Andric
104906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
105006c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
105106c3fb27SDimitry Andric#  else
105206c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX23
105306c3fb27SDimitry Andric#  endif
105406c3fb27SDimitry Andric
105506c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
1056bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
10570b57cec5SDimitry Andric#  else
1058bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX14
10590b57cec5SDimitry Andric#  endif
10600b57cec5SDimitry Andric
106106c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
1062bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
10630b57cec5SDimitry Andric#  else
1064bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX17
10650b57cec5SDimitry Andric#  endif
10660b57cec5SDimitry Andric
106706c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
1068bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
10690b57cec5SDimitry Andric#  else
1070bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX20
10710b57cec5SDimitry Andric#  endif
10720b57cec5SDimitry Andric
107306c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
1074bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
1075bdd1243dSDimitry Andric#  else
1076bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX23
1077bdd1243dSDimitry Andric#  endif
1078bdd1243dSDimitry Andric
10790b57cec5SDimitry Andric#  ifndef _LIBCPP_HAS_NO_ASAN
108006c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI void
108181ad6265SDimitry Andric__sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
108206c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container(
108306c3fb27SDimitry Andric    const void*, const void*, const void*, const void*, const void*, const void*);
108406c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI int
108506c3fb27SDimitry Andric__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*);
108606c3fb27SDimitry Andric#  endif
10870b57cec5SDimitry Andric
10880b57cec5SDimitry Andric// Try to find out if RTTI is disabled.
108981ad6265SDimitry Andric#  if !defined(__cpp_rtti) || __cpp_rtti < 199711L
10901ac55f4cSDimitry Andric#    define _LIBCPP_HAS_NO_RTTI
10910b57cec5SDimitry Andric#  endif
10920b57cec5SDimitry Andric
10930b57cec5SDimitry Andric#  ifndef _LIBCPP_WEAK
10940b57cec5SDimitry Andric#    define _LIBCPP_WEAK __attribute__((__weak__))
10950b57cec5SDimitry Andric#  endif
10960b57cec5SDimitry Andric
10970b57cec5SDimitry Andric// Thread API
109881ad6265SDimitry Andric// clang-format off
10990b57cec5SDimitry Andric#  if !defined(_LIBCPP_HAS_NO_THREADS) &&                                                                              \
11000b57cec5SDimitry Andric      !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) &&                                                                      \
11010b57cec5SDimitry Andric      !defined(_LIBCPP_HAS_THREAD_API_WIN32) &&                                                                        \
11020b57cec5SDimitry Andric      !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
110381ad6265SDimitry Andric
11040b57cec5SDimitry Andric#    if defined(__FreeBSD__) ||                                                                                        \
11050b57cec5SDimitry Andric        defined(__wasi__) ||                                                                                           \
11060b57cec5SDimitry Andric        defined(__NetBSD__) ||                                                                                         \
1107e8d8bef9SDimitry Andric        defined(__OpenBSD__) ||                                                                                        \
1108e8d8bef9SDimitry Andric        defined(__NuttX__) ||                                                                                          \
11090b57cec5SDimitry Andric        defined(__linux__) ||                                                                                          \
11100b57cec5SDimitry Andric        defined(__GNU__) ||                                                                                            \
11110b57cec5SDimitry Andric        defined(__APPLE__) ||                                                                                          \
1112e8d8bef9SDimitry Andric        defined(__MVS__) ||                                                                                            \
111381ad6265SDimitry Andric        defined(_AIX) ||                                                                                               \
111481ad6265SDimitry Andric        defined(__EMSCRIPTEN__)
111581ad6265SDimitry Andric// clang-format on
11160b57cec5SDimitry Andric#      define _LIBCPP_HAS_THREAD_API_PTHREAD
1117480093f4SDimitry Andric#    elif defined(__Fuchsia__)
11185ffd83dbSDimitry Andric// TODO(44575): Switch to C11 thread API when possible.
11195ffd83dbSDimitry Andric#      define _LIBCPP_HAS_THREAD_API_PTHREAD
11200b57cec5SDimitry Andric#    elif defined(_LIBCPP_WIN32API)
11210b57cec5SDimitry Andric#      define _LIBCPP_HAS_THREAD_API_WIN32
11220b57cec5SDimitry Andric#    else
11230b57cec5SDimitry Andric#      error "No thread API"
11240b57cec5SDimitry Andric#    endif // _LIBCPP_HAS_THREAD_API
11250b57cec5SDimitry Andric#  endif   // _LIBCPP_HAS_NO_THREADS
11260b57cec5SDimitry Andric
1127e40139ffSDimitry Andric#  if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1128e40139ffSDimitry Andric#    if defined(__ANDROID__) && __ANDROID_API__ >= 30
1129e40139ffSDimitry Andric#      define _LIBCPP_HAS_COND_CLOCKWAIT
1130e40139ffSDimitry Andric#    elif defined(_LIBCPP_GLIBC_PREREQ)
1131e40139ffSDimitry Andric#      if _LIBCPP_GLIBC_PREREQ(2, 30)
1132e40139ffSDimitry Andric#        define _LIBCPP_HAS_COND_CLOCKWAIT
1133e40139ffSDimitry Andric#      endif
1134e40139ffSDimitry Andric#    endif
1135e40139ffSDimitry Andric#  endif
1136e40139ffSDimitry Andric
11370b57cec5SDimitry Andric#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
11380b57cec5SDimitry Andric#    error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
11390b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is not defined.
11400b57cec5SDimitry Andric#  endif
11410b57cec5SDimitry Andric
11420b57cec5SDimitry Andric#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
11430b57cec5SDimitry Andric#    error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
11440b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is defined.
11450b57cec5SDimitry Andric#  endif
11460b57cec5SDimitry Andric
11470b57cec5SDimitry Andric#  if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
11480b57cec5SDimitry Andric#    error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
11490b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is defined.
11500b57cec5SDimitry Andric#  endif
11510b57cec5SDimitry Andric
1152e40139ffSDimitry Andric#  if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1153e40139ffSDimitry Andric#    define __STDCPP_THREADS__ 1
1154e40139ffSDimitry Andric#  endif
1155e40139ffSDimitry Andric
1156e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements
11570b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
11580b57cec5SDimitry Andric// mutexes have no destroy mechanism.
1159e40139ffSDimitry Andric//
1160e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where
1161e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources.
1162e40139ffSDimitry Andric// See https://llvm.org/D64298 for details.
1163e40139ffSDimitry Andric//
1164e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their
1165e40139ffSDimitry Andric//               respective stakeholders.
116681ad6265SDimitry Andric// clang-format off
116781ad6265SDimitry Andric#  if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) ||                                               \
116881ad6265SDimitry Andric      (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) ||                                                 \
116981ad6265SDimitry Andric       defined(_LIBCPP_HAS_THREAD_API_WIN32)
117081ad6265SDimitry Andric// clang-format on
11710b57cec5SDimitry Andric#    define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
11720b57cec5SDimitry Andric#  endif
11730b57cec5SDimitry Andric
11740b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows.
1175e40139ffSDimitry Andric//
1176e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where
1177e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources.
1178e40139ffSDimitry Andric// See https://llvm.org/D64298 for details.
1179e40139ffSDimitry Andric//
11800b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations
11810b57cec5SDimitry Andric// as well.
118281ad6265SDimitry Andric#  if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
11830b57cec5SDimitry Andric#    define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
11840b57cec5SDimitry Andric#  endif
11850b57cec5SDimitry Andric
118681ad6265SDimitry Andric#  if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) ||                        \
118704eeddc0SDimitry Andric      defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
11880b57cec5SDimitry Andric#    define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
11890b57cec5SDimitry Andric#  endif
11900b57cec5SDimitry Andric
11910b57cec5SDimitry Andric#  if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
11920b57cec5SDimitry Andric#    define _LIBCPP_HAS_C_ATOMIC_IMP
11930b57cec5SDimitry Andric#  elif defined(_LIBCPP_COMPILER_GCC)
11940b57cec5SDimitry Andric#    define _LIBCPP_HAS_GCC_ATOMIC_IMP
11950b57cec5SDimitry Andric#  endif
11960b57cec5SDimitry Andric
119781ad6265SDimitry Andric#  if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) &&                                    \
1198349cc55cSDimitry Andric      !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
11990b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_ATOMIC_HEADER
12000b57cec5SDimitry Andric#  else
12010b57cec5SDimitry Andric#    ifndef _LIBCPP_ATOMIC_FLAG_TYPE
12020b57cec5SDimitry Andric#      define _LIBCPP_ATOMIC_FLAG_TYPE bool
12030b57cec5SDimitry Andric#    endif
12040b57cec5SDimitry Andric#    ifdef _LIBCPP_FREESTANDING
12050b57cec5SDimitry Andric#      define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
12060b57cec5SDimitry Andric#    endif
12070b57cec5SDimitry Andric#  endif
12080b57cec5SDimitry Andric
120906c3fb27SDimitry Andric#  if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
121006c3fb27SDimitry Andric#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
121106c3fb27SDimitry Andric#  else
121206c3fb27SDimitry Andric#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
121306c3fb27SDimitry Andric#  endif
121406c3fb27SDimitry Andric
12150b57cec5SDimitry Andric#  if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
12160b57cec5SDimitry Andric#    if defined(__clang__) && __has_attribute(acquire_capability)
12170b57cec5SDimitry Andric// Work around the attribute handling in clang.  When both __declspec and
12180b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition
12191fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
12201fd87a68SDimitry Andric// combining the two does work.
12211fd87a68SDimitry Andric#      if !defined(_MSC_VER)
12220b57cec5SDimitry Andric#        define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
12230b57cec5SDimitry Andric#      endif
12240b57cec5SDimitry Andric#    endif
12250b57cec5SDimitry Andric#  endif
12260b57cec5SDimitry Andric
1227480093f4SDimitry Andric#  ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1228480093f4SDimitry Andric#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1229480093f4SDimitry Andric#  else
1230480093f4SDimitry Andric#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1231480093f4SDimitry Andric#  endif
1232480093f4SDimitry Andric
123306c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
123481ad6265SDimitry Andric#    define _LIBCPP_CONSTINIT constinit
1235bdd1243dSDimitry Andric#  elif __has_attribute(__require_constant_initialization__)
123681ad6265SDimitry Andric#    define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
12370b57cec5SDimitry Andric#  else
123881ad6265SDimitry Andric#    define _LIBCPP_CONSTINIT
12390b57cec5SDimitry Andric#  endif
12400b57cec5SDimitry Andric
1241*7a6dacacSDimitry Andric#  if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
1242*7a6dacacSDimitry Andric// The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
1243*7a6dacacSDimitry Andric// which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
1244*7a6dacacSDimitry Andric// when compiling for CUDA we use the non-underscored version of the noinline
1245*7a6dacacSDimitry Andric// attribute.
1246*7a6dacacSDimitry Andric//
1247*7a6dacacSDimitry Andric// This is a temporary workaround and we still expect the CUDA SDK team to solve
1248*7a6dacacSDimitry Andric// this issue properly in the SDK headers.
1249*7a6dacacSDimitry Andric//
1250*7a6dacacSDimitry Andric// See https://github.com/llvm/llvm-project/pull/73838 for more details.
1251*7a6dacacSDimitry Andric#    define _LIBCPP_NOINLINE __attribute__((noinline))
1252*7a6dacacSDimitry Andric#  elif __has_attribute(__noinline__)
12535f757f3fSDimitry Andric#    define _LIBCPP_NOINLINE __attribute__((__noinline__))
12540b57cec5SDimitry Andric#  else
12555f757f3fSDimitry Andric#    define _LIBCPP_NOINLINE
125606c3fb27SDimitry Andric#  endif
125706c3fb27SDimitry Andric
1258349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library.
1259349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of
1260349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger
1261349cc55cSDimitry Andric// impact on readability.
1262349cc55cSDimitry Andric#  if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1263349cc55cSDimitry Andric#    define _LIBCPP_IF_WIDE_CHARACTERS(...)
1264349cc55cSDimitry Andric#  else
1265349cc55cSDimitry Andric#    define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1266349cc55cSDimitry Andric#  endif
1267349cc55cSDimitry Andric
12680b57cec5SDimitry Andric#  if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
12690b57cec5SDimitry Andric#    define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
12700b57cec5SDimitry Andric#    define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1271fe6060f1SDimitry Andric#    define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1272fe6060f1SDimitry Andric#    define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
127381ad6265SDimitry Andric#    define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
12740b57cec5SDimitry Andric#  endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
12750b57cec5SDimitry Andric
1276fe6060f1SDimitry Andric#  if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1277fe6060f1SDimitry Andric#    define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
127881ad6265SDimitry Andric#    define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
1279fe6060f1SDimitry Andric#    define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1280fe6060f1SDimitry Andric#    define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1281fe6060f1SDimitry Andric#    define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1282fe6060f1SDimitry Andric#    define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1283fe6060f1SDimitry Andric#  endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1284fe6060f1SDimitry Andric
128506c3fb27SDimitry Andric// clang-format off
128606c3fb27SDimitry Andric#  define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh()\")") _Pragma("push_macro(\"move(int, int)\")") _Pragma("push_macro(\"erase()\")")
128706c3fb27SDimitry Andric#  define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh()\")") _Pragma("pop_macro(\"move(int, int)\")") _Pragma("pop_macro(\"erase()\")")
128806c3fb27SDimitry Andric// clang-format on
12890b57cec5SDimitry Andric
12900b57cec5SDimitry Andric#  ifndef _LIBCPP_NO_AUTO_LINK
12910b57cec5SDimitry Andric#    if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1292fe6060f1SDimitry Andric#      if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
12930b57cec5SDimitry Andric#        pragma comment(lib, "c++.lib")
12940b57cec5SDimitry Andric#      else
12950b57cec5SDimitry Andric#        pragma comment(lib, "libc++.lib")
12960b57cec5SDimitry Andric#      endif
12970b57cec5SDimitry Andric#    endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
12980b57cec5SDimitry Andric#  endif   // _LIBCPP_NO_AUTO_LINK
12990b57cec5SDimitry Andric
1300e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will
1301e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen.
1302e40139ffSDimitry Andric//
1303e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1304e40139ffSDimitry Andric// do.
1305e40139ffSDimitry Andric#  if defined(__BIONIC__)
1306e40139ffSDimitry Andric#    define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1307e40139ffSDimitry Andric#  else
1308e40139ffSDimitry Andric#    define _LIBCPP_FOPEN_CLOEXEC_MODE
1309e40139ffSDimitry Andric#  endif
1310e40139ffSDimitry Andric
131181ad6265SDimitry Andric#  if __has_cpp_attribute(msvc::no_unique_address)
131281ad6265SDimitry Andric// MSVC implements [[no_unique_address]] as a silent no-op currently.
131381ad6265SDimitry Andric// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
131481ad6265SDimitry Andric// However, MSVC implements [[msvc::no_unique_address]] which does what
131581ad6265SDimitry Andric// [[no_unique_address]] is supposed to do, in general.
131681ad6265SDimitry Andric
131781ad6265SDimitry Andric// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
131881ad6265SDimitry Andric// [[msvc::no_unique_address]] though. If/when it does implement
131981ad6265SDimitry Andric// [[msvc::no_unique_address]], this should be preferred though.
132081ad6265SDimitry Andric#    define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
132181ad6265SDimitry Andric#  elif __has_cpp_attribute(no_unique_address)
132206c3fb27SDimitry Andric#    define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
132381ad6265SDimitry Andric#  else
132481ad6265SDimitry Andric#    define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
132581ad6265SDimitry Andric// Note that this can be replaced by #error as soon as clang-cl
132681ad6265SDimitry Andric// implements msvc::no_unique_address, since there should be no C++20
132781ad6265SDimitry Andric// compiler that doesn't support one of the two attributes at that point.
132881ad6265SDimitry Andric// We generally don't want to use this macro outside of C++20-only code,
132981ad6265SDimitry Andric// because using it conditionally in one language version only would make
133081ad6265SDimitry Andric// the ABI inconsistent.
133181ad6265SDimitry Andric#  endif
133281ad6265SDimitry Andric
133381ad6265SDimitry Andric#  ifdef _LIBCPP_COMPILER_CLANG_BASED
133481ad6265SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
133581ad6265SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
133681ad6265SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
133781ad6265SDimitry Andric#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
133881ad6265SDimitry Andric#  elif defined(_LIBCPP_COMPILER_GCC)
133981ad6265SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
134081ad6265SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
134181ad6265SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
134281ad6265SDimitry Andric#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
134381ad6265SDimitry Andric#  else
134481ad6265SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_PUSH
134581ad6265SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_POP
134681ad6265SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
134781ad6265SDimitry Andric#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
134881ad6265SDimitry Andric#  endif
134981ad6265SDimitry Andric
1350bdd1243dSDimitry Andric// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1351bdd1243dSDimitry Andric// functions is gradually being added to existing C libraries. The conditions
1352bdd1243dSDimitry Andric// below check for known C library versions and conditions under which these
1353bdd1243dSDimitry Andric// functions are declared by the C library.
1354bdd1243dSDimitry Andric#  define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1355bdd1243dSDimitry Andric// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
13561ac55f4cSDimitry Andric// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
13571ac55f4cSDimitry Andric// the latter depends on internal GNU libc details that are not appropriate
13581ac55f4cSDimitry Andric// to depend on here, so any declarations present when __cpp_char8_t is not
13591ac55f4cSDimitry Andric// defined are ignored.
13601ac55f4cSDimitry Andric#  if defined(_LIBCPP_GLIBC_PREREQ)
13611ac55f4cSDimitry Andric#    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1362bdd1243dSDimitry Andric#      undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1363bdd1243dSDimitry Andric#    endif
1364bdd1243dSDimitry Andric#  endif
1365bdd1243dSDimitry Andric
1366bdd1243dSDimitry Andric// There are a handful of public standard library types that are intended to
1367bdd1243dSDimitry Andric// support CTAD but don't need any explicit deduction guides to do so. This
1368bdd1243dSDimitry Andric// macro is used to mark them as such, which suppresses the
1369bdd1243dSDimitry Andric// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1370bdd1243dSDimitry Andric// with these classes.
1371bdd1243dSDimitry Andric#  if _LIBCPP_STD_VER >= 17
137206c3fb27SDimitry Andric#    ifdef _LIBCPP_COMPILER_CLANG_BASED
1373bdd1243dSDimitry Andric#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName)                                                              \
1374bdd1243dSDimitry Andric        template <class... _Tag>                                                                                       \
137506c3fb27SDimitry Andric        [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
137606c3fb27SDimitry Andric#    else
137706c3fb27SDimitry Andric#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName)                                                               \
137806c3fb27SDimitry Andric        template <class... _Tag>                                                                                       \
137906c3fb27SDimitry Andric        ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
138006c3fb27SDimitry Andric#    endif
1381bdd1243dSDimitry Andric#  else
1382bdd1243dSDimitry Andric#    define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1383bdd1243dSDimitry Andric#  endif
1384bdd1243dSDimitry Andric
13851ac55f4cSDimitry Andric// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
13861ac55f4cSDimitry Andric// compiler intrinsics in the Objective-C++ mode.
13871ac55f4cSDimitry Andric#  ifdef __OBJC__
13881ac55f4cSDimitry Andric#    define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
13891ac55f4cSDimitry Andric#  endif
13901ac55f4cSDimitry Andric
139106c3fb27SDimitry Andric#  define _PSTL_PRAGMA(x) _Pragma(#x)
139206c3fb27SDimitry Andric
139306c3fb27SDimitry Andric// Enable SIMD for compilers that support OpenMP 4.0
139406c3fb27SDimitry Andric#  if (defined(_OPENMP) && _OPENMP >= 201307)
139506c3fb27SDimitry Andric
139606c3fb27SDimitry Andric#    define _PSTL_UDR_PRESENT
139706c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
139806c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
139906c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
140006c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
140106c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
140206c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
140306c3fb27SDimitry Andric
140406c3fb27SDimitry Andric// Declaration of reduction functor, where
140506c3fb27SDimitry Andric// NAME - the name of the functor
140606c3fb27SDimitry Andric// OP - type of the callable object with the reduction operation
140706c3fb27SDimitry Andric// omp_in - refers to the local partial result
140806c3fb27SDimitry Andric// omp_out - refers to the final value of the combiner operator
140906c3fb27SDimitry Andric// omp_priv - refers to the private copy of the initial value
141006c3fb27SDimitry Andric// omp_orig - refers to the original variable to be reduced
141106c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)                                                                   \
141206c3fb27SDimitry Andric      _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
141306c3fb27SDimitry Andric
14145f757f3fSDimitry Andric#  elif defined(_LIBCPP_COMPILER_CLANG_BASED)
14155f757f3fSDimitry Andric
14165f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
14175f757f3fSDimitry Andric#    define _PSTL_PRAGMA_DECLARE_SIMD
14185f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
14195f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
14205f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
14215f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
14225f757f3fSDimitry Andric#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
14235f757f3fSDimitry Andric
142406c3fb27SDimitry Andric#  else // (defined(_OPENMP) && _OPENMP >= 201307)
142506c3fb27SDimitry Andric
142606c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD
142706c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_SIMD
142806c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
142906c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_SCAN(PRM)
143006c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
143106c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
143206c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
143306c3fb27SDimitry Andric
143406c3fb27SDimitry Andric#  endif // (defined(_OPENMP) && _OPENMP >= 201307)
143506c3fb27SDimitry Andric
143606c3fb27SDimitry Andric#  define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
143706c3fb27SDimitry Andric
14385f757f3fSDimitry Andric// Optional attributes - these are useful for a better QoI, but not required to be available
14395f757f3fSDimitry Andric
14405f757f3fSDimitry Andric#  if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
14415f757f3fSDimitry Andric#    define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
14425f757f3fSDimitry Andric#  else
14435f757f3fSDimitry Andric#    define _LIBCPP_NO_CFI
14445f757f3fSDimitry Andric#  endif
14455f757f3fSDimitry Andric
14465f757f3fSDimitry Andric#  if __has_attribute(__malloc__)
14475f757f3fSDimitry Andric#    define _LIBCPP_NOALIAS __attribute__((__malloc__))
14485f757f3fSDimitry Andric#  else
14495f757f3fSDimitry Andric#    define _LIBCPP_NOALIAS
14505f757f3fSDimitry Andric#  endif
14515f757f3fSDimitry Andric
14525f757f3fSDimitry Andric#  if __has_attribute(__using_if_exists__)
14535f757f3fSDimitry Andric#    define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
14545f757f3fSDimitry Andric#  else
14555f757f3fSDimitry Andric#    define _LIBCPP_USING_IF_EXISTS
14565f757f3fSDimitry Andric#  endif
14575f757f3fSDimitry Andric
14585f757f3fSDimitry Andric#  if __has_cpp_attribute(nodiscard)
14595f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD [[__nodiscard__]]
14605f757f3fSDimitry Andric#  else
14615f757f3fSDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and
14625f757f3fSDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via
14635f757f3fSDimitry Andric// (void) cast.
14645f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD
14655f757f3fSDimitry Andric#  endif
14665f757f3fSDimitry Andric
14675f757f3fSDimitry Andric// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
14685f757f3fSDimitry Andric// specified as such as an extension.
14695f757f3fSDimitry Andric#  if !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
14705f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
14715f757f3fSDimitry Andric#  else
14725f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD_EXT
14735f757f3fSDimitry Andric#  endif
14745f757f3fSDimitry Andric
14755f757f3fSDimitry Andric#  if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
14765f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
14775f757f3fSDimitry Andric#  else
14785f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD_AFTER_CXX17
14795f757f3fSDimitry Andric#  endif
14805f757f3fSDimitry Andric
14815f757f3fSDimitry Andric#  if __has_attribute(__no_destroy__)
14825f757f3fSDimitry Andric#    define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
14835f757f3fSDimitry Andric#  else
14845f757f3fSDimitry Andric#    define _LIBCPP_NO_DESTROY
14855f757f3fSDimitry Andric#  endif
14865f757f3fSDimitry Andric
14875f757f3fSDimitry Andric#  if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
14885f757f3fSDimitry Andric#    define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
14895f757f3fSDimitry Andric#  else
14905f757f3fSDimitry Andric#    define _LIBCPP_DIAGNOSE_WARNING(...)
14915f757f3fSDimitry Andric#  endif
14925f757f3fSDimitry Andric
14935f757f3fSDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon
14945f757f3fSDimitry Andric#  if __has_cpp_attribute(fallthrough)
14955f757f3fSDimitry Andric#    define _LIBCPP_FALLTHROUGH() [[fallthrough]]
14965f757f3fSDimitry Andric#  elif __has_attribute(__fallthrough__)
14975f757f3fSDimitry Andric#    define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
14985f757f3fSDimitry Andric#  else
14995f757f3fSDimitry Andric#    define _LIBCPP_FALLTHROUGH() ((void)0)
15005f757f3fSDimitry Andric#  endif
15015f757f3fSDimitry Andric
15025f757f3fSDimitry Andric#  if __has_cpp_attribute(_Clang::__lifetimebound__)
15035f757f3fSDimitry Andric#    define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
15045f757f3fSDimitry Andric#  else
15055f757f3fSDimitry Andric#    define _LIBCPP_LIFETIMEBOUND
15065f757f3fSDimitry Andric#  endif
15075f757f3fSDimitry Andric
15085f757f3fSDimitry Andric#  if __has_attribute(__nodebug__)
15095f757f3fSDimitry Andric#    define _LIBCPP_NODEBUG __attribute__((__nodebug__))
15105f757f3fSDimitry Andric#  else
15115f757f3fSDimitry Andric#    define _LIBCPP_NODEBUG
15125f757f3fSDimitry Andric#  endif
15135f757f3fSDimitry Andric
15145f757f3fSDimitry Andric#  if __has_attribute(__standalone_debug__)
15155f757f3fSDimitry Andric#    define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
15165f757f3fSDimitry Andric#  else
15175f757f3fSDimitry Andric#    define _LIBCPP_STANDALONE_DEBUG
15185f757f3fSDimitry Andric#  endif
15195f757f3fSDimitry Andric
15205f757f3fSDimitry Andric#  if __has_attribute(__preferred_name__)
15215f757f3fSDimitry Andric#    define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
15225f757f3fSDimitry Andric#  else
15235f757f3fSDimitry Andric#    define _LIBCPP_PREFERRED_NAME(x)
15245f757f3fSDimitry Andric#  endif
15255f757f3fSDimitry Andric
15265f757f3fSDimitry Andric#  if __has_attribute(__no_sanitize__)
15275f757f3fSDimitry Andric#    define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
15285f757f3fSDimitry Andric#  else
15295f757f3fSDimitry Andric#    define _LIBCPP_NO_SANITIZE(...)
15305f757f3fSDimitry Andric#  endif
15315f757f3fSDimitry Andric
15325f757f3fSDimitry Andric#  if __has_attribute(__init_priority__)
15335f757f3fSDimitry Andric#    define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
15345f757f3fSDimitry Andric#  else
15355f757f3fSDimitry Andric#    define _LIBCPP_INIT_PRIORITY_MAX
15365f757f3fSDimitry Andric#  endif
15375f757f3fSDimitry Andric
15385f757f3fSDimitry Andric#  if __has_attribute(__format__)
15395f757f3fSDimitry Andric// The attribute uses 1-based indices for ordinary and static member functions.
15405f757f3fSDimitry Andric// The attribute uses 2-based indices for non-static member functions.
15415f757f3fSDimitry Andric#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index)                           \
15425f757f3fSDimitry Andric      __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
15435f757f3fSDimitry Andric#  else
15445f757f3fSDimitry Andric#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
15455f757f3fSDimitry Andric#  endif
15465f757f3fSDimitry Andric
15475f757f3fSDimitry Andric#  if __has_attribute(__packed__)
15485f757f3fSDimitry Andric#    define _LIBCPP_PACKED __attribute__((__packed__))
15495f757f3fSDimitry Andric#  else
15505f757f3fSDimitry Andric#    define _LIBCPP_PACKED
15515f757f3fSDimitry Andric#  endif
15525f757f3fSDimitry Andric
15535f757f3fSDimitry Andric#  if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
15545f757f3fSDimitry Andric#    define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
15555f757f3fSDimitry Andric#  else
15565f757f3fSDimitry Andric#    define _LIBCPP_DECLSPEC_EMPTY_BASES
15575f757f3fSDimitry Andric#  endif
15585f757f3fSDimitry Andric
15595f757f3fSDimitry Andric// Allow for build-time disabling of unsigned integer sanitization
15605f757f3fSDimitry Andric#  if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
15615f757f3fSDimitry Andric#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
15625f757f3fSDimitry Andric#  else
15635f757f3fSDimitry Andric#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
15645f757f3fSDimitry Andric#  endif
15655f757f3fSDimitry Andric
1566*7a6dacacSDimitry Andric// Clang-18 has support for deducing this, but it does not set the FTM.
1567*7a6dacacSDimitry Andric#  if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
1568*7a6dacacSDimitry Andric#    define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
1569*7a6dacacSDimitry Andric#  endif
1570*7a6dacacSDimitry Andric
15710b57cec5SDimitry Andric#endif // __cplusplus
15720b57cec5SDimitry Andric
157381ad6265SDimitry Andric#endif // _LIBCPP___CONFIG
1574