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 196246ae0bSDimitry Andric#if defined(__apple_build_version__) 201ac55f4cSDimitry Andric// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) 216246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 226246ae0bSDimitry Andric# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) 236246ae0bSDimitry Andric#elif defined(__clang__) 246246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 256246ae0bSDimitry Andric# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) 266246ae0bSDimitry Andric#elif defined(__GNUC__) 276246ae0bSDimitry Andric# define _LIBCPP_COMPILER_GCC 285f757f3fSDimitry Andric# define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__) 296246ae0bSDimitry Andric#endif 306246ae0bSDimitry Andric 310b57cec5SDimitry Andric#ifdef __cplusplus 320b57cec5SDimitry Andric 335f757f3fSDimitry Andric// Warn if a compiler version is used that is not supported anymore 345f757f3fSDimitry Andric// LLVM RELEASE Update the minimum compiler versions 355f757f3fSDimitry Andric# if defined(_LIBCPP_CLANG_VER) 365f757f3fSDimitry Andric# if _LIBCPP_CLANG_VER < 1600 375f757f3fSDimitry Andric# warning "Libc++ only supports Clang 16 and later" 385f757f3fSDimitry Andric# endif 395f757f3fSDimitry Andric# elif defined(_LIBCPP_APPLE_CLANG_VER) 405f757f3fSDimitry Andric# if _LIBCPP_APPLE_CLANG_VER < 1500 415f757f3fSDimitry Andric# warning "Libc++ only supports AppleClang 15 and later" 425f757f3fSDimitry Andric# endif 435f757f3fSDimitry Andric# elif defined(_LIBCPP_GCC_VER) 445f757f3fSDimitry Andric# if _LIBCPP_GCC_VER < 1300 455f757f3fSDimitry Andric# warning "Libc++ only supports GCC 13 and later" 465f757f3fSDimitry Andric# endif 475f757f3fSDimitry Andric# endif 485f757f3fSDimitry Andric 4906c3fb27SDimitry Andric// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html 5006c3fb27SDimitry Andric 51bdd1243dSDimitry Andric// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 5206c3fb27SDimitry Andric// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is 53bdd1243dSDimitry Andric// defined to XXYYZZ. 545f757f3fSDimitry Andric# define _LIBCPP_VERSION 180000 550b57cec5SDimitry Andric 56753f127fSDimitry Andric# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 57753f127fSDimitry Andric# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 58753f127fSDimitry Andric 59e8d8bef9SDimitry Andric# if __STDC_HOSTED__ == 0 600b57cec5SDimitry Andric# define _LIBCPP_FREESTANDING 610b57cec5SDimitry Andric# endif 620b57cec5SDimitry Andric 6306c3fb27SDimitry Andric// NOLINTBEGIN(libcpp-cpp-version-check) 640b57cec5SDimitry Andric# ifndef _LIBCPP_STD_VER 650b57cec5SDimitry Andric# if __cplusplus <= 201103L 660b57cec5SDimitry Andric# define _LIBCPP_STD_VER 11 670b57cec5SDimitry Andric# elif __cplusplus <= 201402L 680b57cec5SDimitry Andric# define _LIBCPP_STD_VER 14 690b57cec5SDimitry Andric# elif __cplusplus <= 201703L 700b57cec5SDimitry Andric# define _LIBCPP_STD_VER 17 71e8d8bef9SDimitry Andric# elif __cplusplus <= 202002L 72e8d8bef9SDimitry Andric# define _LIBCPP_STD_VER 20 7306c3fb27SDimitry Andric# elif __cplusplus <= 202302L 7406c3fb27SDimitry Andric# define _LIBCPP_STD_VER 23 750b57cec5SDimitry Andric# else 76bdd1243dSDimitry Andric// Expected release year of the next C++ standard 7706c3fb27SDimitry Andric# define _LIBCPP_STD_VER 26 780b57cec5SDimitry Andric# endif 790b57cec5SDimitry Andric# endif // _LIBCPP_STD_VER 8006c3fb27SDimitry Andric// NOLINTEND(libcpp-cpp-version-check) 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric# if defined(__ELF__) 830b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_ELF 1 840b57cec5SDimitry Andric# elif defined(__MACH__) 850b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_MACHO 1 860b57cec5SDimitry Andric# elif defined(_WIN32) 870b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_COFF 1 880b57cec5SDimitry Andric# elif defined(__wasm__) 890b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_WASM 1 9081ad6265SDimitry Andric# elif defined(_AIX) 9181ad6265SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 920b57cec5SDimitry Andric# else 93e8d8bef9SDimitry Andric// ... add new file formats here ... 940b57cec5SDimitry Andric# endif 950b57cec5SDimitry Andric 9606c3fb27SDimitry Andric// ABI { 9706c3fb27SDimitry Andric 9881ad6265SDimitry Andric# if _LIBCPP_ABI_VERSION >= 2 990b57cec5SDimitry Andric// Change short string representation so that string data starts at offset 0, 1000b57cec5SDimitry Andric// improving its alignment in some cases. 1010b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 1020b57cec5SDimitry Andric// Fix deque iterator type in order to support incomplete types. 1030b57cec5SDimitry Andric# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 1040b57cec5SDimitry Andric// Fix undefined behavior in how std::list stores its linked nodes. 1050b57cec5SDimitry Andric# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB 1060b57cec5SDimitry Andric// Fix undefined behavior in how __tree stores its end and parent nodes. 1070b57cec5SDimitry Andric# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB 1080b57cec5SDimitry Andric// Fix undefined behavior in how __hash_table stores its pointer types. 1090b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB 1100b57cec5SDimitry Andric# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB 1110b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 1120b57cec5SDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 1130b57cec5SDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 1140b57cec5SDimitry Andric// using that class define their own copies. 1150b57cec5SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 116349cc55cSDimitry Andric// Override the default return value of exception::what() for 117349cc55cSDimitry Andric// bad_function_call::what() with a string that is specific to 118349cc55cSDimitry Andric// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break 119349cc55cSDimitry Andric// because it changes the vtable layout of bad_function_call. 120349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE 1210b57cec5SDimitry Andric// Enable optimized version of __do_get_(un)signed which avoids redundant copies. 1220b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET 123fe6060f1SDimitry Andric// Give reverse_iterator<T> one data member of type T, not two. 124fe6060f1SDimitry Andric// Also, in C++17 and later, don't derive iterator types from std::iterator. 125fe6060f1SDimitry Andric# define _LIBCPP_ABI_NO_ITERATOR_BASES 1260b57cec5SDimitry Andric// Use the smallest possible integer type to represent the index of the variant. 1270b57cec5SDimitry Andric// Previously libc++ used "unsigned int" exclusively. 1280b57cec5SDimitry Andric# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION 1290b57cec5SDimitry Andric// Unstable attempt to provide a more optimized std::function 1300b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_FUNCTION 1310b57cec5SDimitry Andric// All the regex constants must be distinct and nonzero. 1320b57cec5SDimitry Andric# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO 1335ffd83dbSDimitry Andric// Re-worked external template instantiations for std::string with a focus on 1345ffd83dbSDimitry Andric// performance and fast-path inlining. 1355ffd83dbSDimitry Andric# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 136e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::unique_ptr. 137e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI 138e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr 139e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI 14004eeddc0SDimitry Andric// std::random_device holds some state when it uses an implementation that gets 14104eeddc0SDimitry Andric// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this 14204eeddc0SDimitry Andric// implementation to another one on a platform that has already shipped 14304eeddc0SDimitry Andric// std::random_device, one needs to retain the same object layout to remain ABI 14404eeddc0SDimitry Andric// compatible. This switch removes these workarounds for platforms that don't care 14504eeddc0SDimitry Andric// about ABI compatibility. 14604eeddc0SDimitry Andric# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT 14781ad6265SDimitry Andric// Don't export the legacy __basic_string_common class and its methods from the built library. 1481838bd0fSDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON 14981ad6265SDimitry Andric// Don't export the legacy __vector_base_common class and its methods from the built library. 150d56accc7SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON 15181ad6265SDimitry Andric// According to the Standard, `bitset::operator[] const` returns bool 15281ad6265SDimitry Andric# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 1531ac55f4cSDimitry Andric// Fix the implementation of CityHash used for std::hash<fundamental-type>. 1541ac55f4cSDimitry Andric// This is an ABI break because `std::hash` will return a different result, 1551ac55f4cSDimitry Andric// which means that hashing the same object in translation units built against 1561ac55f4cSDimitry Andric// different versions of libc++ can return inconsistent results. This is especially 1571ac55f4cSDimitry Andric// tricky since std::hash is used in the implementation of unordered containers. 1581ac55f4cSDimitry Andric// 1591ac55f4cSDimitry Andric// The incorrect implementation of CityHash has the problem that it drops some 1601ac55f4cSDimitry Andric// bits on the floor. 1611ac55f4cSDimitry Andric# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION 16281ad6265SDimitry Andric// Remove the base 10 implementation of std::to_chars from the dylib. 16381ad6265SDimitry Andric// The implementation moved to the header, but we still export the symbols from 16481ad6265SDimitry Andric// the dylib for backwards compatibility. 16581ad6265SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 1665f757f3fSDimitry Andric// Save memory by providing the allocator more freedom to allocate the most 1675f757f3fSDimitry Andric// efficient size class by dropping the alignment requirements for std::string's 1685f757f3fSDimitry Andric// pointer from 16 to 8. This changes the output of std::string::max_size, 1695f757f3fSDimitry Andric// which makes it ABI breaking 1705f757f3fSDimitry Andric# define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT 1710b57cec5SDimitry Andric# elif _LIBCPP_ABI_VERSION == 1 17281ad6265SDimitry Andric# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) 1730b57cec5SDimitry Andric// Enable compiling copies of now inline methods into the dylib to support 1740b57cec5SDimitry Andric// applications compiled against older libraries. This is unnecessary with 1750b57cec5SDimitry Andric// COFF dllexport semantics, since dllexport forces a non-inline definition 1760b57cec5SDimitry Andric// of inline functions to be emitted anyway. Our own non-inline copy would 17781ad6265SDimitry Andric// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, 17881ad6265SDimitry Andric// the linker will take issue with the symbols in the shared object if the 17981ad6265SDimitry Andric// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), 18081ad6265SDimitry Andric// so disable it. 1810b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS 1820b57cec5SDimitry Andric# endif 1830b57cec5SDimitry Andric// Feature macros for disabling pre ABI v1 features. All of these options 1840b57cec5SDimitry Andric// are deprecated. 1855f757f3fSDimitry Andric# if defined(__FreeBSD__) && __FreeBSD__ < 14 1860b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 1870b57cec5SDimitry Andric# endif 18806c3fb27SDimitry Andric// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol 18906c3fb27SDimitry Andric// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def 19006c3fb27SDimitry Andric// in the library, so we need to always rely on the library version. 19106c3fb27SDimitry Andric# if defined(_AIX) 19206c3fb27SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 19306c3fb27SDimitry Andric# endif 1940b57cec5SDimitry Andric# endif 1950b57cec5SDimitry Andric 19681ad6265SDimitry Andric# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 197349cc55cSDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 198349cc55cSDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 199349cc55cSDimitry Andric// using that class define their own copies. 200349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 2010b57cec5SDimitry Andric# endif 2020b57cec5SDimitry Andric 203*647cbc5dSDimitry Andric// We had some bugs where we use [[no_unique_address]] together with construct_at, 204*647cbc5dSDimitry Andric// which causes UB as the call on construct_at could write to overlapping subobjects 205*647cbc5dSDimitry Andric// 206*647cbc5dSDimitry Andric// https://github.com/llvm/llvm-project/issues/70506 207*647cbc5dSDimitry Andric// https://github.com/llvm/llvm-project/issues/70494 208*647cbc5dSDimitry Andric// 209*647cbc5dSDimitry Andric// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions. 210*647cbc5dSDimitry Andric// The below macro is used for all classes whose ABI have changed as part of fixing these bugs. 211*647cbc5dSDimitry Andric# define _LIBCPP_ABI_2023_OVERLAPPING_SUBOBJECT_FIX_TAG __attribute__((__abi_tag__("subobj_fix_2023"))) 212*647cbc5dSDimitry Andric 21306c3fb27SDimitry Andric// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's 21406c3fb27SDimitry Andric// within the bounds of the original container and asserts it on every dereference. 21506c3fb27SDimitry Andric// 21606c3fb27SDimitry Andric// ABI impact: changes the iterator type of the relevant containers. 21706c3fb27SDimitry Andric// 21806c3fb27SDimitry Andric// Supported containers: 21906c3fb27SDimitry Andric// - `span`; 22006c3fb27SDimitry Andric// - `string_view`; 22106c3fb27SDimitry Andric// - `array`. 22206c3fb27SDimitry Andric// #define _LIBCPP_ABI_BOUNDED_ITERATORS 22306c3fb27SDimitry Andric 22406c3fb27SDimitry Andric// } ABI 22506c3fb27SDimitry Andric 22606c3fb27SDimitry Andric// HARDENING { 22706c3fb27SDimitry Andric 2285f757f3fSDimitry Andric// TODO(hardening): deprecate this in LLVM 19. 2295f757f3fSDimitry Andric// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) 2305f757f3fSDimitry Andric// equivalent to setting the extensive mode. 2315f757f3fSDimitry Andric# ifdef _LIBCPP_ENABLE_ASSERTIONS 23206c3fb27SDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 23306c3fb27SDimitry Andric# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" 23406c3fb27SDimitry Andric# endif 2355f757f3fSDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS 2365f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE 2375f757f3fSDimitry Andric# endif 2385f757f3fSDimitry Andric# endif 23906c3fb27SDimitry Andric 2405f757f3fSDimitry Andric// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: 2418a4dda33SDimitry Andric// 2425f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE`; 2435f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST`; 2445f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; 2455f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG`. 24606c3fb27SDimitry Andric// 2475f757f3fSDimitry Andric// These values have the following effects: 24806c3fb27SDimitry Andric// 2495f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; 2505f757f3fSDimitry Andric// 2515f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks 2525f757f3fSDimitry Andric// that can be done with relatively little runtime overhead in constant time; 2535f757f3fSDimitry Andric// 2545f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of 2555f757f3fSDimitry Andric// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors 2565f757f3fSDimitry Andric// but are not necessarily security-critical; 2575f757f3fSDimitry Andric// 2585f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive 2595f757f3fSDimitry Andric// mode and enables all checks available in the library, including internal assertions. Checks that are part of the 2605f757f3fSDimitry Andric// debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. 26106c3fb27SDimitry Andric 26206c3fb27SDimitry Andric// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These 26306c3fb27SDimitry Andric// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. 26406c3fb27SDimitry Andric// 26506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and 26606c3fb27SDimitry Andric// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: 26706c3fb27SDimitry Andric// - the sentinel is reachable from the begin iterator; 26806c3fb27SDimitry Andric// - TODO(hardening): both iterators refer to the same container. 26906c3fb27SDimitry Andric// 27006c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through 27106c3fb27SDimitry Andric// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access 27206c3fb27SDimitry Andric// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like 27306c3fb27SDimitry Andric// `optional` and `function` are considered one-element containers for the purposes of this check. 27406c3fb27SDimitry Andric// 2755f757f3fSDimitry Andric// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero 2765f757f3fSDimitry Andric// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the 2775f757f3fSDimitry Andric// memory security of a program (however, it is still undefined behavior that can result in strange errors due to 2785f757f3fSDimitry Andric// compiler optimizations). 2795f757f3fSDimitry Andric// 28006c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the 28106c3fb27SDimitry Andric// given ranges do not overlap. 28206c3fb27SDimitry Andric// 28306c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure 28406c3fb27SDimitry Andric// the containers have compatible allocators. 28506c3fb27SDimitry Andric// 28606c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on 28706c3fb27SDimitry Andric// user input. 28806c3fb27SDimitry Andric// 28906c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. 29006c3fb27SDimitry Andric 2915f757f3fSDimitry Andric// clang-format off 2925f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_NONE (1 << 1) 2935f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_FAST (1 << 2) 2945f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. 2955f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) 2965f757f3fSDimitry Andric// clang-format on 2975f757f3fSDimitry Andric 2985f757f3fSDimitry Andric# ifndef _LIBCPP_HARDENING_MODE 2995f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT 30006c3fb27SDimitry Andric# endif 30106c3fb27SDimitry Andric 3025f757f3fSDimitry Andric# if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \ 3035f757f3fSDimitry Andric _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ 3045f757f3fSDimitry Andric _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ 3055f757f3fSDimitry Andric _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG 3065f757f3fSDimitry Andric# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ 3075f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_NONE, \ 3085f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_FAST, \ 3095f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_EXTENSIVE, \ 3105f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_DEBUG 31106c3fb27SDimitry Andric# endif 31206c3fb27SDimitry Andric 31306c3fb27SDimitry Andric// clang-format off 3145f757f3fSDimitry Andric// Fast hardening mode checks. 3155f757f3fSDimitry Andric 3165f757f3fSDimitry Andric# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 31706c3fb27SDimitry Andric 31806c3fb27SDimitry Andric// Enabled checks. 31906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 32006c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 32106c3fb27SDimitry Andric// Disabled checks. 3225f757f3fSDimitry Andric// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access. 3235f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) 32406c3fb27SDimitry Andric// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security 32506c3fb27SDimitry Andric// vulnerability. 32606c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 32706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 32806c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 32906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 33006c3fb27SDimitry Andric 3315f757f3fSDimitry Andric// Extensive hardening mode checks. 33206c3fb27SDimitry Andric 3335f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 33406c3fb27SDimitry Andric 3355f757f3fSDimitry Andric// Enabled checks. 33606c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 33706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 3385f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) 33906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 34006c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 34106c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 3425f757f3fSDimitry Andric// Disabled checks. 3435f757f3fSDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 34406c3fb27SDimitry Andric 3455f757f3fSDimitry Andric// Debug hardening mode checks. 3468a4dda33SDimitry Andric 3475f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 3488a4dda33SDimitry Andric 3498a4dda33SDimitry Andric// All checks enabled. 3508a4dda33SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 3518a4dda33SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 3525f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) 3538a4dda33SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 3548a4dda33SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 3558a4dda33SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) 3568a4dda33SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 3578a4dda33SDimitry Andric 35806c3fb27SDimitry Andric// Disable all checks if hardening is not enabled. 35906c3fb27SDimitry Andric 36006c3fb27SDimitry Andric# else 36106c3fb27SDimitry Andric 36206c3fb27SDimitry Andric// All checks disabled. 36306c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression) 36406c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression) 3655f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) 36606c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 36706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 36806c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 36906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 37006c3fb27SDimitry Andric 3715f757f3fSDimitry Andric# endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 37206c3fb27SDimitry Andric// clang-format on 37306c3fb27SDimitry Andric 37406c3fb27SDimitry Andric// } HARDENING 37506c3fb27SDimitry Andric 37681ad6265SDimitry Andric# define _LIBCPP_TOSTRING2(x) #x 37781ad6265SDimitry Andric# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 3780b57cec5SDimitry Andric 37906c3fb27SDimitry Andric// NOLINTNEXTLINE(libcpp-cpp-version-check) 3800b57cec5SDimitry Andric# if __cplusplus < 201103L 3810b57cec5SDimitry Andric# define _LIBCPP_CXX03_LANG 3820b57cec5SDimitry Andric# endif 3830b57cec5SDimitry Andric 3840b57cec5SDimitry Andric# ifndef __has_attribute 3850b57cec5SDimitry Andric# define __has_attribute(__x) 0 3860b57cec5SDimitry Andric# endif 3870b57cec5SDimitry Andric 3880b57cec5SDimitry Andric# ifndef __has_builtin 3890b57cec5SDimitry Andric# define __has_builtin(__x) 0 3900b57cec5SDimitry Andric# endif 3910b57cec5SDimitry Andric 3920b57cec5SDimitry Andric# ifndef __has_extension 3930b57cec5SDimitry Andric# define __has_extension(__x) 0 3940b57cec5SDimitry Andric# endif 3950b57cec5SDimitry Andric 3960b57cec5SDimitry Andric# ifndef __has_feature 3970b57cec5SDimitry Andric# define __has_feature(__x) 0 3980b57cec5SDimitry Andric# endif 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andric# ifndef __has_cpp_attribute 4010b57cec5SDimitry Andric# define __has_cpp_attribute(__x) 0 4020b57cec5SDimitry Andric# endif 4030b57cec5SDimitry Andric 404bdd1243dSDimitry Andric# ifndef __has_constexpr_builtin 405bdd1243dSDimitry Andric# define __has_constexpr_builtin(x) 0 406bdd1243dSDimitry Andric# endif 407bdd1243dSDimitry Andric 4080b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 4090b57cec5SDimitry Andric// the compiler and '1' otherwise. 4100b57cec5SDimitry Andric# ifndef __is_identifier 4110b57cec5SDimitry Andric# define __is_identifier(__x) 1 4120b57cec5SDimitry Andric# endif 4130b57cec5SDimitry Andric 4140b57cec5SDimitry Andric# ifndef __has_declspec_attribute 4150b57cec5SDimitry Andric# define __has_declspec_attribute(__x) 0 4160b57cec5SDimitry Andric# endif 4170b57cec5SDimitry Andric 4180b57cec5SDimitry Andric# define __has_keyword(__x) !(__is_identifier(__x)) 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andric# ifndef __has_include 4210b57cec5SDimitry Andric# define __has_include(...) 0 4220b57cec5SDimitry Andric# endif 4230b57cec5SDimitry Andric 42481ad6265SDimitry Andric# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 42581ad6265SDimitry Andric# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 4260b57cec5SDimitry Andric# endif 4270b57cec5SDimitry Andric 4280b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This 4290b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume 4300b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, 4310b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this 4320b57cec5SDimitry Andric// heuristic falls short. 4330b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) 4340b57cec5SDimitry Andric# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" 4350b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) 4360b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 4370b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) 4380b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 4390b57cec5SDimitry Andric# else 4400b57cec5SDimitry Andric# if defined(_WIN32) && defined(_MSC_VER) 4410b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 4420b57cec5SDimitry Andric# else 4430b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 4440b57cec5SDimitry Andric# endif 4450b57cec5SDimitry Andric# endif 4460b57cec5SDimitry Andric 4470b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 4480b57cec5SDimitry Andric# define _LIBCPP_ABI_VCRUNTIME 4490b57cec5SDimitry Andric# endif 4500b57cec5SDimitry Andric 451fcaf7f86SDimitry Andric# if __has_feature(experimental_library) 452fcaf7f86SDimitry Andric# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 453fcaf7f86SDimitry Andric# define _LIBCPP_ENABLE_EXPERIMENTAL 454fcaf7f86SDimitry Andric# endif 455fcaf7f86SDimitry Andric# endif 456fcaf7f86SDimitry Andric 457fcaf7f86SDimitry Andric// Incomplete features get their own specific disabling flags. This makes it 458fcaf7f86SDimitry Andric// easier to grep for target specific flags once the feature is complete. 459fcaf7f86SDimitry Andric# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 46006c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL 46106c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN 4625f757f3fSDimitry Andric# define _LIBCPP_HAS_NO_INCOMPLETE_TZDB 4635f757f3fSDimitry Andric# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM 464fcaf7f86SDimitry Andric# endif 465fcaf7f86SDimitry Andric 4660b57cec5SDimitry Andric// Need to detect which libc we're using if we're on Linux. 4670b57cec5SDimitry Andric# if defined(__linux__) 4680b57cec5SDimitry Andric# include <features.h> 4690b57cec5SDimitry Andric# if defined(__GLIBC_PREREQ) 4700b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) 4710b57cec5SDimitry Andric# else 4720b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) 0 4730b57cec5SDimitry Andric# endif // defined(__GLIBC_PREREQ) 4740b57cec5SDimitry Andric# endif // defined(__linux__) 4750b57cec5SDimitry Andric 47604eeddc0SDimitry Andric# if defined(__MVS__) 47704eeddc0SDimitry Andric# include <features.h> // for __NATIVE_ASCII_F 47804eeddc0SDimitry Andric# endif 47904eeddc0SDimitry Andric 4805f757f3fSDimitry Andric# ifndef __BYTE_ORDER__ 4815f757f3fSDimitry Andric# error \ 4825f757f3fSDimitry Andric "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform" 4835f757f3fSDimitry Andric# endif 4840b57cec5SDimitry Andric 4850b57cec5SDimitry Andric# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 4860b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4870b57cec5SDimitry Andric# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4880b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4890b57cec5SDimitry Andric# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4900b57cec5SDimitry Andric 4910b57cec5SDimitry Andric# if defined(_WIN32) 4920b57cec5SDimitry Andric# define _LIBCPP_WIN32API 4930b57cec5SDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 4940b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment 4950b57cec5SDimitry Andric# define _LIBCPP_MSVCRT_LIKE 4960b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if 4970b57cec5SDimitry Andric// a MS compatibility version is specified. 4980b57cec5SDimitry Andric# if defined(_MSC_VER) && !defined(__MINGW32__) 4990b57cec5SDimitry Andric# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 5000b57cec5SDimitry Andric# endif 5010b57cec5SDimitry Andric# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 5020b57cec5SDimitry Andric# define _LIBCPP_HAS_BITSCAN64 5030b57cec5SDimitry Andric# endif 5040b57cec5SDimitry Andric# define _LIBCPP_HAS_OPEN_WITH_WCHAR 5050b57cec5SDimitry Andric# endif // defined(_WIN32) 5060b57cec5SDimitry Andric 507349cc55cSDimitry Andric# if defined(_AIX) && !defined(__64BIT__) 508349cc55cSDimitry Andric// The size of wchar is 2 byte on 32-bit mode on AIX. 509349cc55cSDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 510349cc55cSDimitry Andric# endif 511349cc55cSDimitry Andric 5120eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device. 5130eae32dcSDimitry Andric// 5140eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM 5150eae32dcSDimitry Andric// Read entropy from the given file, by default `/dev/urandom`. 5160eae32dcSDimitry Andric// If a token is provided, it is assumed to be the path to a file 5170eae32dcSDimitry Andric// to read entropy from. This is the default behavior if nothing 5180eae32dcSDimitry Andric// else is specified. This implementation requires storing state 5190eae32dcSDimitry Andric// inside `std::random_device`. 5200eae32dcSDimitry Andric// 5210eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM 5220eae32dcSDimitry Andric// Use arc4random(). This allows obtaining random data even when 5230eae32dcSDimitry Andric// using sandboxing mechanisms. On some platforms like Apple, this 5240eae32dcSDimitry Andric// is the recommended source of entropy for user-space programs. 5250eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5260eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5270eae32dcSDimitry Andric// 5280eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY 5290eae32dcSDimitry Andric// Use getentropy(). 5300eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5310eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5320eae32dcSDimitry Andric// 53304eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG 53404eeddc0SDimitry Andric// Use Fuchsia's zx_cprng_draw() system call, which is specified to 53504eeddc0SDimitry Andric// deliver high-quality entropy and cannot fail. 53604eeddc0SDimitry Andric// When this option is used, the token passed to `std::random_device`'s 53704eeddc0SDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 53804eeddc0SDimitry Andric// 5390eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM 5400eae32dcSDimitry Andric// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 5410eae32dcSDimitry Andric// including accesses to the special files under `/dev`. This implementation 5420eae32dcSDimitry Andric// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 5430eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5440eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5450eae32dcSDimitry Andric// 5460eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM 5470eae32dcSDimitry Andric// Use rand_s(), for use on Windows. 5480eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5490eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 55081ad6265SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 55106c3fb27SDimitry Andric defined(__DragonFly__) 5520b57cec5SDimitry Andric# define _LIBCPP_USING_ARC4_RANDOM 55381ad6265SDimitry Andric# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 5540b57cec5SDimitry Andric# define _LIBCPP_USING_GETENTROPY 55504eeddc0SDimitry Andric# elif defined(__Fuchsia__) 55604eeddc0SDimitry Andric# define _LIBCPP_USING_FUCHSIA_CPRNG 5570b57cec5SDimitry Andric# elif defined(__native_client__) 5580b57cec5SDimitry Andric# define _LIBCPP_USING_NACL_RANDOM 5590b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 5600b57cec5SDimitry Andric# define _LIBCPP_USING_WIN32_RANDOM 5610b57cec5SDimitry Andric# else 5620b57cec5SDimitry Andric# define _LIBCPP_USING_DEV_RANDOM 5630b57cec5SDimitry Andric# endif 5640b57cec5SDimitry Andric 5650b57cec5SDimitry Andric# ifndef _LIBCPP_CXX03_LANG 56681ad6265SDimitry Andric 5670b57cec5SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 56881ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) alignas(x) 56981ad6265SDimitry Andric# define _ALIGNAS(x) alignas(x) 57081ad6265SDimitry Andric# define _LIBCPP_NORETURN [[noreturn]] 57181ad6265SDimitry Andric# define _NOEXCEPT noexcept 57281ad6265SDimitry Andric# define _NOEXCEPT_(x) noexcept(x) 573bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR constexpr 57481ad6265SDimitry Andric 5750b57cec5SDimitry Andric# else 57681ad6265SDimitry Andric 57781ad6265SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 57881ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 57981ad6265SDimitry Andric# define _ALIGNAS(x) __attribute__((__aligned__(x))) 580bdd1243dSDimitry Andric# define _LIBCPP_NORETURN __attribute__((__noreturn__)) 58181ad6265SDimitry Andric# define _LIBCPP_HAS_NO_NOEXCEPT 58281ad6265SDimitry Andric# define nullptr __nullptr 58381ad6265SDimitry Andric# define _NOEXCEPT throw() 58481ad6265SDimitry Andric# define _NOEXCEPT_(x) 585bdd1243dSDimitry Andric# define static_assert(...) _Static_assert(__VA_ARGS__) 586bdd1243dSDimitry Andric# define decltype(...) __decltype(__VA_ARGS__) 587bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR 58881ad6265SDimitry Andric 58981ad6265SDimitry Andrictypedef __char16_t char16_t; 59081ad6265SDimitry Andrictypedef __char32_t char32_t; 59181ad6265SDimitry Andric 59281ad6265SDimitry Andric# endif 59381ad6265SDimitry Andric 59481ad6265SDimitry Andric# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L 59506c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXCEPTIONS 5960b57cec5SDimitry Andric# endif 5970b57cec5SDimitry Andric 5980b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 5990b57cec5SDimitry Andric 600fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) 6010b57cec5SDimitry Andric 60206c3fb27SDimitry Andric# if defined(__APPLE__) 60306c3fb27SDimitry Andric# if defined(__i386__) || defined(__x86_64__) 60406c3fb27SDimitry Andric// use old string layout on x86_64 and i386 60506c3fb27SDimitry Andric# elif defined(__arm__) 60606c3fb27SDimitry Andric// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs 60706c3fb27SDimitry Andric# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 6080b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 6090b57cec5SDimitry Andric# endif 61006c3fb27SDimitry Andric# else 61106c3fb27SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 61206c3fb27SDimitry Andric# endif 61306c3fb27SDimitry Andric# endif 6140b57cec5SDimitry Andric 6150b57cec5SDimitry Andric// Objective-C++ features (opt-in) 6160b57cec5SDimitry Andric# if __has_feature(objc_arc) 6170b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC 6180b57cec5SDimitry Andric# endif 6190b57cec5SDimitry Andric 6200b57cec5SDimitry Andric# if __has_feature(objc_arc_weak) 6210b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC_WEAK 6220b57cec5SDimitry Andric# endif 6230b57cec5SDimitry Andric 6245ffd83dbSDimitry Andric# if __has_extension(blocks) 6255ffd83dbSDimitry Andric# define _LIBCPP_HAS_EXTENSION_BLOCKS 6265ffd83dbSDimitry Andric# endif 6275ffd83dbSDimitry Andric 6285ffd83dbSDimitry Andric# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) 6295ffd83dbSDimitry Andric# define _LIBCPP_HAS_BLOCKS_RUNTIME 6305ffd83dbSDimitry Andric# endif 6315ffd83dbSDimitry Andric 632fe6060f1SDimitry Andric# if !__has_feature(address_sanitizer) 6330b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 6340b57cec5SDimitry Andric# endif 6350b57cec5SDimitry Andric 6360b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 6370b57cec5SDimitry Andric 638e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 639e40139ffSDimitry Andric 6400b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 6410b57cec5SDimitry Andric 642fe6060f1SDimitry Andric# if !defined(__SANITIZE_ADDRESS__) 6430b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 6440b57cec5SDimitry Andric# endif 6450b57cec5SDimitry Andric 6460b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 6470b57cec5SDimitry Andric 648e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 649e40139ffSDimitry Andric 650bdd1243dSDimitry Andric# endif // _LIBCPP_COMPILER_[CLANG|GCC] 6510b57cec5SDimitry Andric 6520b57cec5SDimitry Andric# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 6530b57cec5SDimitry Andric 6540b57cec5SDimitry Andric# ifdef _DLL 6550b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC __declspec(dllimport) 6560b57cec5SDimitry Andric# else 6570b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC 6580b57cec5SDimitry Andric# endif 6590b57cec5SDimitry Andric 66081ad6265SDimitry Andric# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 6610b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS 6620b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 6630b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6640b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 6650b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI 6660b57cec5SDimitry Andric# elif defined(_LIBCPP_BUILDING_LIBRARY) 6670b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllexport) 6680b57cec5SDimitry Andric# if defined(__MINGW32__) 6690b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 6700b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6710b57cec5SDimitry Andric# else 6720b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 6730b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 6740b57cec5SDimitry Andric# endif 6750b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 6760b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 6770b57cec5SDimitry Andric# else 6780b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllimport) 6790b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 6800b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6810b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 6820b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 6830b57cec5SDimitry Andric# endif 6840b57cec5SDimitry Andric 6850b57cec5SDimitry Andric# define _LIBCPP_HIDDEN 6860b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 6870b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 688fe6060f1SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS 6895f757f3fSDimitry Andric# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 6900b57cec5SDimitry Andric 6910b57cec5SDimitry Andric# else 69281ad6265SDimitry Andric 69381ad6265SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 69481ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 69581ad6265SDimitry Andric# else 69681ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) 6970b57cec5SDimitry Andric# endif 6980b57cec5SDimitry Andric 69981ad6265SDimitry Andric# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 70081ad6265SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 70181ad6265SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 70281ad6265SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 70381ad6265SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 70481ad6265SDimitry Andric 705fcaf7f86SDimitry Andric// TODO: Make this a proper customization point or remove the option to override it. 706fcaf7f86SDimitry Andric# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 707fcaf7f86SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 708fcaf7f86SDimitry Andric# endif 709fcaf7f86SDimitry Andric 7100b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 7110b57cec5SDimitry Andric// The inline should be removed once PR32114 is resolved 7120b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 7130b57cec5SDimitry Andric# else 7140b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 7150b57cec5SDimitry Andric# endif 7160b57cec5SDimitry Andric 7175f757f3fSDimitry Andric// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates 7185f757f3fSDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__) 7190b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 7200b57cec5SDimitry Andric# else 7210b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 7220b57cec5SDimitry Andric# endif 7230b57cec5SDimitry Andric 7240b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) 7255f757f3fSDimitry Andric# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default"))) 7260b57cec5SDimitry Andric# else 7275f757f3fSDimitry Andric# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 7280b57cec5SDimitry Andric# endif 7290b57cec5SDimitry Andric 73081ad6265SDimitry Andric# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 7310b57cec5SDimitry Andric 7320b57cec5SDimitry Andric# if __has_attribute(exclude_from_explicit_instantiation) 7330b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 7340b57cec5SDimitry Andric# else 7350b57cec5SDimitry Andric// Try to approximate the effect of exclude_from_explicit_instantiation 7360b57cec5SDimitry Andric// (which is that entities are not assumed to be provided by explicit 7370b57cec5SDimitry Andric// template instantiations in the dylib) by always inlining those entities. 7380b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 7390b57cec5SDimitry Andric# endif 7400b57cec5SDimitry Andric 7415f757f3fSDimitry Andric# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 7425f757f3fSDimitry Andric# define _LIBCPP_HARDENING_SIG f 7435f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 744b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG s 7455f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 746b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG d 747b121cb00SDimitry Andric# else 7485f757f3fSDimitry Andric# define _LIBCPP_HARDENING_SIG n // "none" 749b121cb00SDimitry Andric# endif 750b121cb00SDimitry Andric 751b121cb00SDimitry Andric# ifdef _LIBCPP_HAS_NO_EXCEPTIONS 752b121cb00SDimitry Andric# define _LIBCPP_EXCEPTIONS_SIG n 753b121cb00SDimitry Andric# else 754b121cb00SDimitry Andric# define _LIBCPP_EXCEPTIONS_SIG e 755b121cb00SDimitry Andric# endif 756b121cb00SDimitry Andric 757b121cb00SDimitry Andric# define _LIBCPP_ODR_SIGNATURE \ 758b121cb00SDimitry Andric _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) 759b121cb00SDimitry Andric 760753f127fSDimitry Andric// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 761753f127fSDimitry Andric// on two levels: 762753f127fSDimitry Andric// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 763753f127fSDimitry Andric// symbols from their dynamic library by means of using the libc++ headers. This ensures 764753f127fSDimitry Andric// that those symbols stay private to the dynamic library in which it is defined. 765753f127fSDimitry Andric// 766b121cb00SDimitry Andric// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. 767b121cb00SDimitry Andric// This ensures that no ODR violation can arise from mixing two TUs compiled with different 768b121cb00SDimitry Andric// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the 769b121cb00SDimitry Andric// program contains two definitions of a function, the ODR requires them to be token-by-token 770b121cb00SDimitry Andric// equivalent, and the linker is allowed to pick either definition and discard the other one. 771b121cb00SDimitry Andric// 772b121cb00SDimitry Andric// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled 773b121cb00SDimitry Andric// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs 774b121cb00SDimitry Andric// compiled with different settings), the two definitions are both visible by the linker and they 775b121cb00SDimitry Andric// have the same name, but they have a meaningfully different implementation (one throws an exception 776b121cb00SDimitry Andric// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in 777b121cb00SDimitry Andric// practice what will happen is that the linker will pick one of the definitions at random and will 778b121cb00SDimitry Andric// discard the other one. This can quite clearly lead to incorrect program behavior. 779b121cb00SDimitry Andric// 780b121cb00SDimitry Andric// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any 781b121cb00SDimitry Andric// property that causes the code of a function to differ from the code in another configuration 782b121cb00SDimitry Andric// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI 783b121cb00SDimitry Andric// tag, but we encode the ones that we think are most important: library version, exceptions, and 784b121cb00SDimitry Andric// hardening mode. 785b121cb00SDimitry Andric// 786b121cb00SDimitry Andric// Note that historically, solving this problem has been achieved in various ways, including 787b121cb00SDimitry Andric// force-inlining all functions or giving internal linkage to all functions. Both these previous 788b121cb00SDimitry Andric// solutions suffer from drawbacks that lead notably to code bloat. 789753f127fSDimitry Andric// 790753f127fSDimitry Andric// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 791753f127fSDimitry Andric// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 792753f127fSDimitry Andric// 793bdd1243dSDimitry Andric// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 794bdd1243dSDimitry Andric// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 795bdd1243dSDimitry Andric// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 796bdd1243dSDimitry Andric// the virtual function pointer in the vtable based on the mangled name of the function. Since 797bdd1243dSDimitry Andric// we use an ABI tag that changes with each released version, the mangled name of the virtual 798bdd1243dSDimitry Andric// function would change, which is incorrect. Note that it doesn't make much sense to change 799bdd1243dSDimitry Andric// the implementation of a virtual function in an ABI-incompatible way in the first place, 800bdd1243dSDimitry Andric// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 801bdd1243dSDimitry Andric// 802753f127fSDimitry Andric// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 803753f127fSDimitry Andric// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 804753f127fSDimitry Andric// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 805753f127fSDimitry Andric# ifndef _LIBCPP_NO_ABI_TAG 806753f127fSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI \ 807753f127fSDimitry Andric _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 808b121cb00SDimitry Andric __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) 8090b57cec5SDimitry Andric# else 8100b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8110b57cec5SDimitry Andric# endif 812bdd1243dSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8130b57cec5SDimitry Andric 8141ac55f4cSDimitry Andric// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern 8151ac55f4cSDimitry Andric// "C" function, as those lack mangling. 8161ac55f4cSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8171ac55f4cSDimitry Andric 8180b57cec5SDimitry Andric# ifdef _LIBCPP_BUILDING_LIBRARY 8190b57cec5SDimitry Andric# if _LIBCPP_ABI_VERSION > 1 8200b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 8210b57cec5SDimitry Andric# else 8220b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 8230b57cec5SDimitry Andric# endif 8240b57cec5SDimitry Andric# else 8250b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 8260b57cec5SDimitry Andric# endif 8270b57cec5SDimitry Andric 8285f757f3fSDimitry Andric// TODO(LLVM-19): Remove _LIBCPP_INLINE_VISIBILITY and _VSTD, which we're keeping around 8295f757f3fSDimitry Andric// only to ease the renaming for downstreams. 8300b57cec5SDimitry Andric# define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI 8315f757f3fSDimitry Andric# define _VSTD std 8320b57cec5SDimitry Andric 8330b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 83481ad6265SDimitry Andric// clang-format off 8355f757f3fSDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \ 8365f757f3fSDimitry Andric inline namespace _LIBCPP_ABI_NAMESPACE { 8370b57cec5SDimitry Andric# define _LIBCPP_END_NAMESPACE_STD }} 83881ad6265SDimitry Andric 8395f757f3fSDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ 8405f757f3fSDimitry Andric inline namespace __fs { namespace filesystem { 8410b57cec5SDimitry Andric 84281ad6265SDimitry Andric# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }} 84381ad6265SDimitry Andric// clang-format on 8440b57cec5SDimitry Andric 8450b57cec5SDimitry Andric# if __has_attribute(__enable_if__) 8460b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 8470b57cec5SDimitry Andric# endif 8480b57cec5SDimitry Andric 84906c3fb27SDimitry Andric# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) 8500b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_INT128 8510b57cec5SDimitry Andric# endif 8520b57cec5SDimitry Andric 85381ad6265SDimitry Andric# ifdef _LIBCPP_CXX03_LANG 85481ad6265SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 85506c3fb27SDimitry Andric struct _LIBCPP_EXPORTED_FROM_ABI x { \ 85681ad6265SDimitry Andric enum __lx 85781ad6265SDimitry Andric// clang-format off 8580b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 8590b57cec5SDimitry Andric __lx __v_; \ 8605f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ 8615f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 8625f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ 8630b57cec5SDimitry Andric }; 86481ad6265SDimitry Andric// clang-format on 86581ad6265SDimitry Andric 86681ad6265SDimitry Andric# else // _LIBCPP_CXX03_LANG 8675f757f3fSDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x 8680b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 86981ad6265SDimitry Andric# endif // _LIBCPP_CXX03_LANG 8700b57cec5SDimitry Andric 87106c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) 8720b57cec5SDimitry Andric# define _LIBCPP_LOCALE__L_EXTENSIONS 1 8730b57cec5SDimitry Andric# endif 8740b57cec5SDimitry Andric 8750b57cec5SDimitry Andric# ifdef __FreeBSD__ 8760b57cec5SDimitry Andric# define _DECLARE_C99_LDBL_MATH 1 8770b57cec5SDimitry Andric# endif 8780b57cec5SDimitry Andric 8790b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads 8800b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 8810b57cec5SDimitry Andric# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 8820b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 8830b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 8840b57cec5SDimitry Andric// We're deferring to Microsoft's STL to provide aligned new et al. We don't 8850b57cec5SDimitry Andric// have it unless the language feature test macro is defined. 8860b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 887e8d8bef9SDimitry Andric# elif defined(__MVS__) 888e8d8bef9SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 8890b57cec5SDimitry Andric# endif 8900b57cec5SDimitry Andric 89181ad6265SDimitry Andric# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 8920b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 8930b57cec5SDimitry Andric# endif 8940b57cec5SDimitry Andric 895bdd1243dSDimitry Andric// It is not yet possible to use aligned_alloc() on all Apple platforms since 896bdd1243dSDimitry Andric// 10.15 was the first version to ship an implementation of aligned_alloc(). 897bdd1243dSDimitry Andric# if defined(__APPLE__) 898bdd1243dSDimitry Andric# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 899bdd1243dSDimitry Andric __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) 900bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 901bdd1243dSDimitry Andric# endif 902bdd1243dSDimitry Andric# elif defined(__ANDROID__) && __ANDROID_API__ < 28 903bdd1243dSDimitry Andric// Android only provides aligned_alloc when targeting API 28 or higher. 904bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 905bdd1243dSDimitry Andric# endif 906bdd1243dSDimitry Andric 9070b57cec5SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 9080b57cec5SDimitry Andric# define _LIBCPP_HAS_DEFAULTRUNELOCALE 9090b57cec5SDimitry Andric# endif 9100b57cec5SDimitry Andric 91106c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 9120b57cec5SDimitry Andric# define _LIBCPP_WCTYPE_IS_MASK 9130b57cec5SDimitry Andric# endif 9140b57cec5SDimitry Andric 9150b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 916fe6060f1SDimitry Andric# define _LIBCPP_HAS_NO_CHAR8_T 9170b57cec5SDimitry Andric# endif 9180b57cec5SDimitry Andric 9190b57cec5SDimitry Andric// Deprecation macros. 9200b57cec5SDimitry Andric// 9210b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out 9220b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 9230b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 92406c3fb27SDimitry Andric# if __has_attribute(__deprecated__) 92506c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) 92606c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) 92706c3fb27SDimitry Andric# elif _LIBCPP_STD_VER >= 14 9280b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED [[deprecated]] 92981ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 9300b57cec5SDimitry Andric# else 9310b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 93281ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9330b57cec5SDimitry Andric# endif 9340b57cec5SDimitry Andric# else 9350b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 93681ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9370b57cec5SDimitry Andric# endif 9380b57cec5SDimitry Andric 9390b57cec5SDimitry Andric# if !defined(_LIBCPP_CXX03_LANG) 9400b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 9410b57cec5SDimitry Andric# else 9420b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 9430b57cec5SDimitry Andric# endif 9440b57cec5SDimitry Andric 94506c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 9460b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 9470b57cec5SDimitry Andric# else 9480b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 9490b57cec5SDimitry Andric# endif 9500b57cec5SDimitry Andric 95106c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 9520b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 9530b57cec5SDimitry Andric# else 9540b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 9550b57cec5SDimitry Andric# endif 9560b57cec5SDimitry Andric 95706c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 958e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 959e8d8bef9SDimitry Andric# else 960e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 961e8d8bef9SDimitry Andric# endif 962e8d8bef9SDimitry Andric 963bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 23 964bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 965bdd1243dSDimitry Andric# else 966bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 967bdd1243dSDimitry Andric# endif 968bdd1243dSDimitry Andric 969fe6060f1SDimitry Andric# if !defined(_LIBCPP_HAS_NO_CHAR8_T) 970e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 971e8d8bef9SDimitry Andric# else 972e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 973e8d8bef9SDimitry Andric# endif 974e8d8bef9SDimitry Andric 975e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed. 976fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 977e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 97881ad6265SDimitry Andric _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 979fe6060f1SDimitry Andric _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 98081ad6265SDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 981fe6060f1SDimitry Andric# else 982e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 983e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP 984e40139ffSDimitry Andric# endif 985e40139ffSDimitry Andric 9860b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 11 98706c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 9880b57cec5SDimitry Andric# else 98906c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit 9900b57cec5SDimitry Andric# endif 9910b57cec5SDimitry Andric 99206c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 99306c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit 99406c3fb27SDimitry Andric# else 99506c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 99606c3fb27SDimitry Andric# endif 99706c3fb27SDimitry Andric 99806c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 999bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 10000b57cec5SDimitry Andric# else 1001bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 10020b57cec5SDimitry Andric# endif 10030b57cec5SDimitry Andric 100406c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 1005bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 10060b57cec5SDimitry Andric# else 1007bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 10080b57cec5SDimitry Andric# endif 10090b57cec5SDimitry Andric 101006c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 1011bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 10120b57cec5SDimitry Andric# else 1013bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 10140b57cec5SDimitry Andric# endif 10150b57cec5SDimitry Andric 101606c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 1017bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 1018bdd1243dSDimitry Andric# else 1019bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 1020bdd1243dSDimitry Andric# endif 1021bdd1243dSDimitry Andric 10220b57cec5SDimitry Andric# ifndef _LIBCPP_HAS_NO_ASAN 102306c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI void 102481ad6265SDimitry Andric__sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); 102506c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container( 102606c3fb27SDimitry Andric const void*, const void*, const void*, const void*, const void*, const void*); 102706c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI int 102806c3fb27SDimitry Andric__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*); 102906c3fb27SDimitry Andric# endif 10300b57cec5SDimitry Andric 10310b57cec5SDimitry Andric// Try to find out if RTTI is disabled. 103281ad6265SDimitry Andric# if !defined(__cpp_rtti) || __cpp_rtti < 199711L 10331ac55f4cSDimitry Andric# define _LIBCPP_HAS_NO_RTTI 10340b57cec5SDimitry Andric# endif 10350b57cec5SDimitry Andric 10360b57cec5SDimitry Andric# ifndef _LIBCPP_WEAK 10370b57cec5SDimitry Andric# define _LIBCPP_WEAK __attribute__((__weak__)) 10380b57cec5SDimitry Andric# endif 10390b57cec5SDimitry Andric 10400b57cec5SDimitry Andric// Thread API 104181ad6265SDimitry Andric// clang-format off 10420b57cec5SDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && \ 10430b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 10440b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 10450b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 104681ad6265SDimitry Andric 10470b57cec5SDimitry Andric# if defined(__FreeBSD__) || \ 10480b57cec5SDimitry Andric defined(__wasi__) || \ 10490b57cec5SDimitry Andric defined(__NetBSD__) || \ 1050e8d8bef9SDimitry Andric defined(__OpenBSD__) || \ 1051e8d8bef9SDimitry Andric defined(__NuttX__) || \ 10520b57cec5SDimitry Andric defined(__linux__) || \ 10530b57cec5SDimitry Andric defined(__GNU__) || \ 10540b57cec5SDimitry Andric defined(__APPLE__) || \ 1055e8d8bef9SDimitry Andric defined(__MVS__) || \ 105681ad6265SDimitry Andric defined(_AIX) || \ 105781ad6265SDimitry Andric defined(__EMSCRIPTEN__) 105881ad6265SDimitry Andric// clang-format on 10590b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 1060480093f4SDimitry Andric# elif defined(__Fuchsia__) 10615ffd83dbSDimitry Andric// TODO(44575): Switch to C11 thread API when possible. 10625ffd83dbSDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 10630b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 10640b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_WIN32 10650b57cec5SDimitry Andric# else 10660b57cec5SDimitry Andric# error "No thread API" 10670b57cec5SDimitry Andric# endif // _LIBCPP_HAS_THREAD_API 10680b57cec5SDimitry Andric# endif // _LIBCPP_HAS_NO_THREADS 10690b57cec5SDimitry Andric 1070e40139ffSDimitry Andric# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1071e40139ffSDimitry Andric# if defined(__ANDROID__) && __ANDROID_API__ >= 30 1072e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1073e40139ffSDimitry Andric# elif defined(_LIBCPP_GLIBC_PREREQ) 1074e40139ffSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 30) 1075e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1076e40139ffSDimitry Andric# endif 1077e40139ffSDimitry Andric# endif 1078e40139ffSDimitry Andric# endif 1079e40139ffSDimitry Andric 10800b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 10810b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 10820b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is not defined. 10830b57cec5SDimitry Andric# endif 10840b57cec5SDimitry Andric 10850b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 10860b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 10870b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 10880b57cec5SDimitry Andric# endif 10890b57cec5SDimitry Andric 10900b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 10910b57cec5SDimitry Andric# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 10920b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 10930b57cec5SDimitry Andric# endif 10940b57cec5SDimitry Andric 1095e40139ffSDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 1096e40139ffSDimitry Andric# define __STDCPP_THREADS__ 1 1097e40139ffSDimitry Andric# endif 1098e40139ffSDimitry Andric 1099e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements 11000b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 11010b57cec5SDimitry Andric// mutexes have no destroy mechanism. 1102e40139ffSDimitry Andric// 1103e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1104e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources. 1105e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1106e40139ffSDimitry Andric// 1107e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their 1108e40139ffSDimitry Andric// respective stakeholders. 110981ad6265SDimitry Andric// clang-format off 111081ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ 111181ad6265SDimitry Andric (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 111281ad6265SDimitry Andric defined(_LIBCPP_HAS_THREAD_API_WIN32) 111381ad6265SDimitry Andric// clang-format on 11140b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 11150b57cec5SDimitry Andric# endif 11160b57cec5SDimitry Andric 11170b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows. 1118e40139ffSDimitry Andric// 1119e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1120e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources. 1121e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1122e40139ffSDimitry Andric// 11230b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations 11240b57cec5SDimitry Andric// as well. 112581ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) 11260b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 11270b57cec5SDimitry Andric# endif 11280b57cec5SDimitry Andric 11290b57cec5SDimitry Andric// Some systems do not provide gets() in their C library, for security reasons. 113081ad6265SDimitry Andric# if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__) 11310b57cec5SDimitry Andric# define _LIBCPP_C_HAS_NO_GETS 11320b57cec5SDimitry Andric# endif 11330b57cec5SDimitry Andric 113481ad6265SDimitry Andric# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 113504eeddc0SDimitry Andric defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 11360b57cec5SDimitry Andric# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 11370b57cec5SDimitry Andric# endif 11380b57cec5SDimitry Andric 11390b57cec5SDimitry Andric# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 11400b57cec5SDimitry Andric# define _LIBCPP_HAS_C_ATOMIC_IMP 11410b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 11420b57cec5SDimitry Andric# define _LIBCPP_HAS_GCC_ATOMIC_IMP 11430b57cec5SDimitry Andric# endif 11440b57cec5SDimitry Andric 114581ad6265SDimitry Andric# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1146349cc55cSDimitry Andric !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 11470b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ATOMIC_HEADER 11480b57cec5SDimitry Andric# else 11490b57cec5SDimitry Andric# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 11500b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_FLAG_TYPE bool 11510b57cec5SDimitry Andric# endif 11520b57cec5SDimitry Andric# ifdef _LIBCPP_FREESTANDING 11530b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS 11540b57cec5SDimitry Andric# endif 11550b57cec5SDimitry Andric# endif 11560b57cec5SDimitry Andric 115706c3fb27SDimitry Andric# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) 115806c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) 115906c3fb27SDimitry Andric# else 116006c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 116106c3fb27SDimitry Andric# endif 116206c3fb27SDimitry Andric 11630b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 11640b57cec5SDimitry Andric# if defined(__clang__) && __has_attribute(acquire_capability) 11650b57cec5SDimitry Andric// Work around the attribute handling in clang. When both __declspec and 11660b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition 11671fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 11681fd87a68SDimitry Andric// combining the two does work. 11691fd87a68SDimitry Andric# if !defined(_MSC_VER) 11700b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 11710b57cec5SDimitry Andric# endif 11720b57cec5SDimitry Andric# endif 11730b57cec5SDimitry Andric# endif 11740b57cec5SDimitry Andric 1175480093f4SDimitry Andric# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1176480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1177480093f4SDimitry Andric# else 1178480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1179480093f4SDimitry Andric# endif 1180480093f4SDimitry Andric 118106c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 118281ad6265SDimitry Andric# define _LIBCPP_CONSTINIT constinit 1183bdd1243dSDimitry Andric# elif __has_attribute(__require_constant_initialization__) 118481ad6265SDimitry Andric# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 11850b57cec5SDimitry Andric# else 118681ad6265SDimitry Andric# define _LIBCPP_CONSTINIT 11870b57cec5SDimitry Andric# endif 11880b57cec5SDimitry Andric 11895f757f3fSDimitry Andric# if __has_attribute(__noinline__) 11905f757f3fSDimitry Andric# define _LIBCPP_NOINLINE __attribute__((__noinline__)) 11910b57cec5SDimitry Andric# else 11925f757f3fSDimitry Andric# define _LIBCPP_NOINLINE 119306c3fb27SDimitry Andric# endif 119406c3fb27SDimitry Andric 1195349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library. 1196349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of 1197349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger 1198349cc55cSDimitry Andric// impact on readability. 1199349cc55cSDimitry Andric# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1200349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1201349cc55cSDimitry Andric# else 1202349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1203349cc55cSDimitry Andric# endif 1204349cc55cSDimitry Andric 12050b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) 12060b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR 12070b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS 1208fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE 1209fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 121081ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION 12110b57cec5SDimitry Andric# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 12120b57cec5SDimitry Andric 1213fe6060f1SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) 1214fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS 121581ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION 1216fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS 1217fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS 1218fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR 1219fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS 1220fe6060f1SDimitry Andric# endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES 1221fe6060f1SDimitry Andric 122206c3fb27SDimitry Andric// clang-format off 122306c3fb27SDimitry 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()\")") 122406c3fb27SDimitry 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()\")") 122506c3fb27SDimitry Andric// clang-format on 12260b57cec5SDimitry Andric 12270b57cec5SDimitry Andric# ifndef _LIBCPP_NO_AUTO_LINK 12280b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1229fe6060f1SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 12300b57cec5SDimitry Andric# pragma comment(lib, "c++.lib") 12310b57cec5SDimitry Andric# else 12320b57cec5SDimitry Andric# pragma comment(lib, "libc++.lib") 12330b57cec5SDimitry Andric# endif 12340b57cec5SDimitry Andric# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 12350b57cec5SDimitry Andric# endif // _LIBCPP_NO_AUTO_LINK 12360b57cec5SDimitry Andric 1237e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will 1238e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen. 1239e40139ffSDimitry Andric// 1240e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1241e40139ffSDimitry Andric// do. 1242e40139ffSDimitry Andric# if defined(__BIONIC__) 1243e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1244e40139ffSDimitry Andric# else 1245e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE 1246e40139ffSDimitry Andric# endif 1247e40139ffSDimitry Andric 124881ad6265SDimitry Andric# if __has_cpp_attribute(msvc::no_unique_address) 124981ad6265SDimitry Andric// MSVC implements [[no_unique_address]] as a silent no-op currently. 125081ad6265SDimitry Andric// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 125181ad6265SDimitry Andric// However, MSVC implements [[msvc::no_unique_address]] which does what 125281ad6265SDimitry Andric// [[no_unique_address]] is supposed to do, in general. 125381ad6265SDimitry Andric 125481ad6265SDimitry Andric// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 125581ad6265SDimitry Andric// [[msvc::no_unique_address]] though. If/when it does implement 125681ad6265SDimitry Andric// [[msvc::no_unique_address]], this should be preferred though. 125781ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 125881ad6265SDimitry Andric# elif __has_cpp_attribute(no_unique_address) 125906c3fb27SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] 126081ad6265SDimitry Andric# else 126181ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 126281ad6265SDimitry Andric// Note that this can be replaced by #error as soon as clang-cl 126381ad6265SDimitry Andric// implements msvc::no_unique_address, since there should be no C++20 126481ad6265SDimitry Andric// compiler that doesn't support one of the two attributes at that point. 126581ad6265SDimitry Andric// We generally don't want to use this macro outside of C++20-only code, 126681ad6265SDimitry Andric// because using it conditionally in one language version only would make 126781ad6265SDimitry Andric// the ABI inconsistent. 126881ad6265SDimitry Andric# endif 126981ad6265SDimitry Andric 127081ad6265SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 127181ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 127281ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 127381ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 127481ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 127581ad6265SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 127681ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 127781ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 127881ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 127981ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 128081ad6265SDimitry Andric# else 128181ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH 128281ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP 128381ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 128481ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 128581ad6265SDimitry Andric# endif 128681ad6265SDimitry Andric 1287bdd1243dSDimitry Andric// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1288bdd1243dSDimitry Andric// functions is gradually being added to existing C libraries. The conditions 1289bdd1243dSDimitry Andric// below check for known C library versions and conditions under which these 1290bdd1243dSDimitry Andric// functions are declared by the C library. 1291bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1292bdd1243dSDimitry Andric// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 12931ac55f4cSDimitry Andric// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 12941ac55f4cSDimitry Andric// the latter depends on internal GNU libc details that are not appropriate 12951ac55f4cSDimitry Andric// to depend on here, so any declarations present when __cpp_char8_t is not 12961ac55f4cSDimitry Andric// defined are ignored. 12971ac55f4cSDimitry Andric# if defined(_LIBCPP_GLIBC_PREREQ) 12981ac55f4cSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1299bdd1243dSDimitry Andric# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1300bdd1243dSDimitry Andric# endif 1301bdd1243dSDimitry Andric# endif 1302bdd1243dSDimitry Andric 1303bdd1243dSDimitry Andric// There are a handful of public standard library types that are intended to 1304bdd1243dSDimitry Andric// support CTAD but don't need any explicit deduction guides to do so. This 1305bdd1243dSDimitry Andric// macro is used to mark them as such, which suppresses the 1306bdd1243dSDimitry Andric// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1307bdd1243dSDimitry Andric// with these classes. 1308bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 17 130906c3fb27SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 1310bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1311bdd1243dSDimitry Andric template <class... _Tag> \ 131206c3fb27SDimitry Andric [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> 131306c3fb27SDimitry Andric# else 131406c3fb27SDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ 131506c3fb27SDimitry Andric template <class... _Tag> \ 131606c3fb27SDimitry Andric ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> 131706c3fb27SDimitry Andric# endif 1318bdd1243dSDimitry Andric# else 1319bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1320bdd1243dSDimitry Andric# endif 1321bdd1243dSDimitry Andric 13221ac55f4cSDimitry Andric// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 13231ac55f4cSDimitry Andric// compiler intrinsics in the Objective-C++ mode. 13241ac55f4cSDimitry Andric# ifdef __OBJC__ 13251ac55f4cSDimitry Andric# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 13261ac55f4cSDimitry Andric# endif 13271ac55f4cSDimitry Andric 132806c3fb27SDimitry Andric# define _PSTL_PRAGMA(x) _Pragma(#x) 132906c3fb27SDimitry Andric 133006c3fb27SDimitry Andric// Enable SIMD for compilers that support OpenMP 4.0 133106c3fb27SDimitry Andric# if (defined(_OPENMP) && _OPENMP >= 201307) 133206c3fb27SDimitry Andric 133306c3fb27SDimitry Andric# define _PSTL_UDR_PRESENT 133406c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) 133506c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) 133606c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) 133706c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) 133806c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) 133906c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) 134006c3fb27SDimitry Andric 134106c3fb27SDimitry Andric// Declaration of reduction functor, where 134206c3fb27SDimitry Andric// NAME - the name of the functor 134306c3fb27SDimitry Andric// OP - type of the callable object with the reduction operation 134406c3fb27SDimitry Andric// omp_in - refers to the local partial result 134506c3fb27SDimitry Andric// omp_out - refers to the final value of the combiner operator 134606c3fb27SDimitry Andric// omp_priv - refers to the private copy of the initial value 134706c3fb27SDimitry Andric// omp_orig - refers to the original variable to be reduced 134806c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ 134906c3fb27SDimitry Andric _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) 135006c3fb27SDimitry Andric 13515f757f3fSDimitry Andric# elif defined(_LIBCPP_COMPILER_CLANG_BASED) 13525f757f3fSDimitry Andric 13535f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") 13545f757f3fSDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD 13555f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 13565f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 13575f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 13585f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 13595f757f3fSDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 13605f757f3fSDimitry Andric 136106c3fb27SDimitry Andric# else // (defined(_OPENMP) && _OPENMP >= 201307) 136206c3fb27SDimitry Andric 136306c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD 136406c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD 136506c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) 136606c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) 136706c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 136806c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 136906c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 137006c3fb27SDimitry Andric 137106c3fb27SDimitry Andric# endif // (defined(_OPENMP) && _OPENMP >= 201307) 137206c3fb27SDimitry Andric 137306c3fb27SDimitry Andric# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED 137406c3fb27SDimitry Andric 13755f757f3fSDimitry Andric// Optional attributes - these are useful for a better QoI, but not required to be available 13765f757f3fSDimitry Andric 13775f757f3fSDimitry Andric# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 13785f757f3fSDimitry Andric# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 13795f757f3fSDimitry Andric# else 13805f757f3fSDimitry Andric# define _LIBCPP_NO_CFI 13815f757f3fSDimitry Andric# endif 13825f757f3fSDimitry Andric 13835f757f3fSDimitry Andric# if __has_attribute(__malloc__) 13845f757f3fSDimitry Andric# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 13855f757f3fSDimitry Andric# else 13865f757f3fSDimitry Andric# define _LIBCPP_NOALIAS 13875f757f3fSDimitry Andric# endif 13885f757f3fSDimitry Andric 13895f757f3fSDimitry Andric# if __has_attribute(__using_if_exists__) 13905f757f3fSDimitry Andric# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 13915f757f3fSDimitry Andric# else 13925f757f3fSDimitry Andric# define _LIBCPP_USING_IF_EXISTS 13935f757f3fSDimitry Andric# endif 13945f757f3fSDimitry Andric 13955f757f3fSDimitry Andric# if __has_cpp_attribute(nodiscard) 13965f757f3fSDimitry Andric# define _LIBCPP_NODISCARD [[__nodiscard__]] 13975f757f3fSDimitry Andric# else 13985f757f3fSDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and 13995f757f3fSDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via 14005f757f3fSDimitry Andric// (void) cast. 14015f757f3fSDimitry Andric# define _LIBCPP_NODISCARD 14025f757f3fSDimitry Andric# endif 14035f757f3fSDimitry Andric 14045f757f3fSDimitry Andric// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not 14055f757f3fSDimitry Andric// specified as such as an extension. 14065f757f3fSDimitry Andric# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 14075f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD 14085f757f3fSDimitry Andric# else 14095f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_EXT 14105f757f3fSDimitry Andric# endif 14115f757f3fSDimitry Andric 14125f757f3fSDimitry Andric# if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 14135f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD 14145f757f3fSDimitry Andric# else 14155f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 14165f757f3fSDimitry Andric# endif 14175f757f3fSDimitry Andric 14185f757f3fSDimitry Andric# if __has_attribute(__no_destroy__) 14195f757f3fSDimitry Andric# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 14205f757f3fSDimitry Andric# else 14215f757f3fSDimitry Andric# define _LIBCPP_NO_DESTROY 14225f757f3fSDimitry Andric# endif 14235f757f3fSDimitry Andric 14245f757f3fSDimitry Andric# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) 14255f757f3fSDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 14265f757f3fSDimitry Andric# else 14275f757f3fSDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) 14285f757f3fSDimitry Andric# endif 14295f757f3fSDimitry Andric 14305f757f3fSDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon 14315f757f3fSDimitry Andric# if __has_cpp_attribute(fallthrough) 14325f757f3fSDimitry Andric# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 14335f757f3fSDimitry Andric# elif __has_attribute(__fallthrough__) 14345f757f3fSDimitry Andric# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 14355f757f3fSDimitry Andric# else 14365f757f3fSDimitry Andric# define _LIBCPP_FALLTHROUGH() ((void)0) 14375f757f3fSDimitry Andric# endif 14385f757f3fSDimitry Andric 14395f757f3fSDimitry Andric# if __has_cpp_attribute(_Clang::__lifetimebound__) 14405f757f3fSDimitry Andric# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 14415f757f3fSDimitry Andric# else 14425f757f3fSDimitry Andric# define _LIBCPP_LIFETIMEBOUND 14435f757f3fSDimitry Andric# endif 14445f757f3fSDimitry Andric 14455f757f3fSDimitry Andric# if __has_attribute(__nodebug__) 14465f757f3fSDimitry Andric# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 14475f757f3fSDimitry Andric# else 14485f757f3fSDimitry Andric# define _LIBCPP_NODEBUG 14495f757f3fSDimitry Andric# endif 14505f757f3fSDimitry Andric 14515f757f3fSDimitry Andric# if __has_attribute(__standalone_debug__) 14525f757f3fSDimitry Andric# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 14535f757f3fSDimitry Andric# else 14545f757f3fSDimitry Andric# define _LIBCPP_STANDALONE_DEBUG 14555f757f3fSDimitry Andric# endif 14565f757f3fSDimitry Andric 14575f757f3fSDimitry Andric# if __has_attribute(__preferred_name__) 14585f757f3fSDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 14595f757f3fSDimitry Andric# else 14605f757f3fSDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) 14615f757f3fSDimitry Andric# endif 14625f757f3fSDimitry Andric 14635f757f3fSDimitry Andric# if __has_attribute(__no_sanitize__) 14645f757f3fSDimitry Andric# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) 14655f757f3fSDimitry Andric# else 14665f757f3fSDimitry Andric# define _LIBCPP_NO_SANITIZE(...) 14675f757f3fSDimitry Andric# endif 14685f757f3fSDimitry Andric 14695f757f3fSDimitry Andric# if __has_attribute(__init_priority__) 14705f757f3fSDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 14715f757f3fSDimitry Andric# else 14725f757f3fSDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX 14735f757f3fSDimitry Andric# endif 14745f757f3fSDimitry Andric 14755f757f3fSDimitry Andric# if __has_attribute(__format__) 14765f757f3fSDimitry Andric// The attribute uses 1-based indices for ordinary and static member functions. 14775f757f3fSDimitry Andric// The attribute uses 2-based indices for non-static member functions. 14785f757f3fSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 14795f757f3fSDimitry Andric __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 14805f757f3fSDimitry Andric# else 14815f757f3fSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 14825f757f3fSDimitry Andric# endif 14835f757f3fSDimitry Andric 14845f757f3fSDimitry Andric# if __has_attribute(__packed__) 14855f757f3fSDimitry Andric# define _LIBCPP_PACKED __attribute__((__packed__)) 14865f757f3fSDimitry Andric# else 14875f757f3fSDimitry Andric# define _LIBCPP_PACKED 14885f757f3fSDimitry Andric# endif 14895f757f3fSDimitry Andric 14905f757f3fSDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 14915f757f3fSDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 14925f757f3fSDimitry Andric# else 14935f757f3fSDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES 14945f757f3fSDimitry Andric# endif 14955f757f3fSDimitry Andric 14965f757f3fSDimitry Andric// Allow for build-time disabling of unsigned integer sanitization 14975f757f3fSDimitry Andric# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) 14985f757f3fSDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 14995f757f3fSDimitry Andric# else 15005f757f3fSDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 15015f757f3fSDimitry Andric# endif 15025f757f3fSDimitry Andric 15030b57cec5SDimitry Andric#endif // __cplusplus 15040b57cec5SDimitry Andric 150581ad6265SDimitry Andric#endif // _LIBCPP___CONFIG 1506