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#if defined(_MSC_VER) && !defined(__clang__) 160b57cec5SDimitry Andric# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 170b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 180b57cec5SDimitry Andric# endif 190b57cec5SDimitry Andric#endif 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 220b57cec5SDimitry Andric# pragma GCC system_header 230b57cec5SDimitry Andric#endif 240b57cec5SDimitry Andric 256246ae0bSDimitry Andric#if defined(__apple_build_version__) 261ac55f4cSDimitry Andric// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) 276246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 286246ae0bSDimitry Andric# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) 296246ae0bSDimitry Andric#elif defined(__clang__) 306246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 316246ae0bSDimitry Andric# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) 326246ae0bSDimitry Andric#elif defined(__GNUC__) 336246ae0bSDimitry Andric# define _LIBCPP_COMPILER_GCC 346246ae0bSDimitry Andric#endif 356246ae0bSDimitry Andric 360b57cec5SDimitry Andric#ifdef __cplusplus 370b57cec5SDimitry Andric 38*06c3fb27SDimitry Andric// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html 39*06c3fb27SDimitry Andric 40bdd1243dSDimitry Andric// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 41*06c3fb27SDimitry Andric// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is 42bdd1243dSDimitry Andric// defined to XXYYZZ. 43*06c3fb27SDimitry Andric# define _LIBCPP_VERSION 170000 440b57cec5SDimitry Andric 45753f127fSDimitry Andric# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 46753f127fSDimitry Andric# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 47753f127fSDimitry Andric 48753f127fSDimitry Andric// Valid C++ identifier that revs with every libc++ version. This can be used to 49753f127fSDimitry Andric// generate identifiers that must be unique for every released libc++ version. 50753f127fSDimitry Andric# define _LIBCPP_VERSIONED_IDENTIFIER _LIBCPP_CONCAT(v, _LIBCPP_VERSION) 51753f127fSDimitry Andric 52e8d8bef9SDimitry Andric# if __STDC_HOSTED__ == 0 530b57cec5SDimitry Andric# define _LIBCPP_FREESTANDING 540b57cec5SDimitry Andric# endif 550b57cec5SDimitry Andric 56*06c3fb27SDimitry Andric// NOLINTBEGIN(libcpp-cpp-version-check) 570b57cec5SDimitry Andric# ifndef _LIBCPP_STD_VER 580b57cec5SDimitry Andric# if __cplusplus <= 201103L 590b57cec5SDimitry Andric# define _LIBCPP_STD_VER 11 600b57cec5SDimitry Andric# elif __cplusplus <= 201402L 610b57cec5SDimitry Andric# define _LIBCPP_STD_VER 14 620b57cec5SDimitry Andric# elif __cplusplus <= 201703L 630b57cec5SDimitry Andric# define _LIBCPP_STD_VER 17 64e8d8bef9SDimitry Andric# elif __cplusplus <= 202002L 65e8d8bef9SDimitry Andric# define _LIBCPP_STD_VER 20 66*06c3fb27SDimitry Andric# elif __cplusplus <= 202302L 67*06c3fb27SDimitry Andric# define _LIBCPP_STD_VER 23 680b57cec5SDimitry Andric# else 69bdd1243dSDimitry Andric// Expected release year of the next C++ standard 70*06c3fb27SDimitry Andric# define _LIBCPP_STD_VER 26 710b57cec5SDimitry Andric# endif 720b57cec5SDimitry Andric# endif // _LIBCPP_STD_VER 73*06c3fb27SDimitry Andric// NOLINTEND(libcpp-cpp-version-check) 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric# if defined(__ELF__) 760b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_ELF 1 770b57cec5SDimitry Andric# elif defined(__MACH__) 780b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_MACHO 1 790b57cec5SDimitry Andric# elif defined(_WIN32) 800b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_COFF 1 810b57cec5SDimitry Andric# elif defined(__wasm__) 820b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_WASM 1 8381ad6265SDimitry Andric# elif defined(_AIX) 8481ad6265SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 850b57cec5SDimitry Andric# else 86e8d8bef9SDimitry Andric// ... add new file formats here ... 870b57cec5SDimitry Andric# endif 880b57cec5SDimitry Andric 89*06c3fb27SDimitry Andric// ABI { 90*06c3fb27SDimitry Andric 9181ad6265SDimitry Andric# if _LIBCPP_ABI_VERSION >= 2 920b57cec5SDimitry Andric// Change short string representation so that string data starts at offset 0, 930b57cec5SDimitry Andric// improving its alignment in some cases. 940b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 950b57cec5SDimitry Andric// Fix deque iterator type in order to support incomplete types. 960b57cec5SDimitry Andric# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 970b57cec5SDimitry Andric// Fix undefined behavior in how std::list stores its linked nodes. 980b57cec5SDimitry Andric# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB 990b57cec5SDimitry Andric// Fix undefined behavior in how __tree stores its end and parent nodes. 1000b57cec5SDimitry Andric# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB 1010b57cec5SDimitry Andric// Fix undefined behavior in how __hash_table stores its pointer types. 1020b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB 1030b57cec5SDimitry Andric# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB 1040b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 1050b57cec5SDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 1060b57cec5SDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 1070b57cec5SDimitry Andric// using that class define their own copies. 1080b57cec5SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 109349cc55cSDimitry Andric// Override the default return value of exception::what() for 110349cc55cSDimitry Andric// bad_function_call::what() with a string that is specific to 111349cc55cSDimitry Andric// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break 112349cc55cSDimitry Andric// because it changes the vtable layout of bad_function_call. 113349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE 1140b57cec5SDimitry Andric// Enable optimized version of __do_get_(un)signed which avoids redundant copies. 1150b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET 116fe6060f1SDimitry Andric// Give reverse_iterator<T> one data member of type T, not two. 117fe6060f1SDimitry Andric// Also, in C++17 and later, don't derive iterator types from std::iterator. 118fe6060f1SDimitry Andric# define _LIBCPP_ABI_NO_ITERATOR_BASES 1190b57cec5SDimitry Andric// Use the smallest possible integer type to represent the index of the variant. 1200b57cec5SDimitry Andric// Previously libc++ used "unsigned int" exclusively. 1210b57cec5SDimitry Andric# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION 1220b57cec5SDimitry Andric// Unstable attempt to provide a more optimized std::function 1230b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_FUNCTION 1240b57cec5SDimitry Andric// All the regex constants must be distinct and nonzero. 1250b57cec5SDimitry Andric# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO 1265ffd83dbSDimitry Andric// Re-worked external template instantiations for std::string with a focus on 1275ffd83dbSDimitry Andric// performance and fast-path inlining. 1285ffd83dbSDimitry Andric# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 129e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::unique_ptr. 130e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI 131e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr 132e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI 13304eeddc0SDimitry Andric// std::random_device holds some state when it uses an implementation that gets 13404eeddc0SDimitry Andric// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this 13504eeddc0SDimitry Andric// implementation to another one on a platform that has already shipped 13604eeddc0SDimitry Andric// std::random_device, one needs to retain the same object layout to remain ABI 13704eeddc0SDimitry Andric// compatible. This switch removes these workarounds for platforms that don't care 13804eeddc0SDimitry Andric// about ABI compatibility. 13904eeddc0SDimitry Andric# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT 14081ad6265SDimitry Andric// Don't export the legacy __basic_string_common class and its methods from the built library. 1411838bd0fSDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON 14281ad6265SDimitry Andric// Don't export the legacy __vector_base_common class and its methods from the built library. 143d56accc7SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON 14481ad6265SDimitry Andric// According to the Standard, `bitset::operator[] const` returns bool 14581ad6265SDimitry Andric# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 1461ac55f4cSDimitry Andric// Fix the implementation of CityHash used for std::hash<fundamental-type>. 1471ac55f4cSDimitry Andric// This is an ABI break because `std::hash` will return a different result, 1481ac55f4cSDimitry Andric// which means that hashing the same object in translation units built against 1491ac55f4cSDimitry Andric// different versions of libc++ can return inconsistent results. This is especially 1501ac55f4cSDimitry Andric// tricky since std::hash is used in the implementation of unordered containers. 1511ac55f4cSDimitry Andric// 1521ac55f4cSDimitry Andric// The incorrect implementation of CityHash has the problem that it drops some 1531ac55f4cSDimitry Andric// bits on the floor. 1541ac55f4cSDimitry Andric# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION 15581ad6265SDimitry Andric// Remove the base 10 implementation of std::to_chars from the dylib. 15681ad6265SDimitry Andric// The implementation moved to the header, but we still export the symbols from 15781ad6265SDimitry Andric// the dylib for backwards compatibility. 15881ad6265SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 1590b57cec5SDimitry Andric# elif _LIBCPP_ABI_VERSION == 1 16081ad6265SDimitry Andric# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) 1610b57cec5SDimitry Andric// Enable compiling copies of now inline methods into the dylib to support 1620b57cec5SDimitry Andric// applications compiled against older libraries. This is unnecessary with 1630b57cec5SDimitry Andric// COFF dllexport semantics, since dllexport forces a non-inline definition 1640b57cec5SDimitry Andric// of inline functions to be emitted anyway. Our own non-inline copy would 16581ad6265SDimitry Andric// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, 16681ad6265SDimitry Andric// the linker will take issue with the symbols in the shared object if the 16781ad6265SDimitry Andric// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), 16881ad6265SDimitry Andric// so disable it. 1690b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS 1700b57cec5SDimitry Andric# endif 1710b57cec5SDimitry Andric// Feature macros for disabling pre ABI v1 features. All of these options 1720b57cec5SDimitry Andric// are deprecated. 1730b57cec5SDimitry Andric# if defined(__FreeBSD__) 1740b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 1750b57cec5SDimitry Andric# endif 176*06c3fb27SDimitry Andric// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol 177*06c3fb27SDimitry Andric// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def 178*06c3fb27SDimitry Andric// in the library, so we need to always rely on the library version. 179*06c3fb27SDimitry Andric# if defined(_AIX) 180*06c3fb27SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 181*06c3fb27SDimitry Andric# endif 1820b57cec5SDimitry Andric# endif 1830b57cec5SDimitry Andric 18481ad6265SDimitry Andric# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 185e8d8bef9SDimitry Andric// Enable additional explicit instantiations of iostreams components. This 186e8d8bef9SDimitry Andric// reduces the number of weak definitions generated in programs that use 187e8d8bef9SDimitry Andric// iostreams by providing a single strong definition in the shared library. 188e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 189349cc55cSDimitry Andric 190349cc55cSDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 191349cc55cSDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 192349cc55cSDimitry Andric// using that class define their own copies. 193349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 1940b57cec5SDimitry Andric# endif 1950b57cec5SDimitry Andric 196*06c3fb27SDimitry Andric// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's 197*06c3fb27SDimitry Andric// within the bounds of the original container and asserts it on every dereference. 198*06c3fb27SDimitry Andric// 199*06c3fb27SDimitry Andric// ABI impact: changes the iterator type of the relevant containers. 200*06c3fb27SDimitry Andric// 201*06c3fb27SDimitry Andric// Supported containers: 202*06c3fb27SDimitry Andric// - `span`; 203*06c3fb27SDimitry Andric// - `string_view`; 204*06c3fb27SDimitry Andric// - `array`. 205*06c3fb27SDimitry Andric// #define _LIBCPP_ABI_BOUNDED_ITERATORS 206*06c3fb27SDimitry Andric 207*06c3fb27SDimitry Andric// } ABI 208*06c3fb27SDimitry Andric 209*06c3fb27SDimitry Andric// HARDENING { 210*06c3fb27SDimitry Andric 211*06c3fb27SDimitry Andric// TODO(hardening): remove this in LLVM 18. 212*06c3fb27SDimitry Andric// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) 213*06c3fb27SDimitry Andric// equivalent to setting the hardened mode. 214*06c3fb27SDimitry Andric# ifdef _LIBCPP_ENABLE_ASSERTIONS 215*06c3fb27SDimitry Andric# warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_ENABLE_HARDENED_MODE instead." 216*06c3fb27SDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 217*06c3fb27SDimitry Andric# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" 218*06c3fb27SDimitry Andric# endif 219*06c3fb27SDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS 220*06c3fb27SDimitry Andric# define _LIBCPP_ENABLE_HARDENED_MODE 1 221*06c3fb27SDimitry Andric# endif 222*06c3fb27SDimitry Andric# endif 223*06c3fb27SDimitry Andric 224*06c3fb27SDimitry Andric// Enables the hardened mode which consists of all checks intended to be used in production. Hardened mode prioritizes 225*06c3fb27SDimitry Andric// security-critical checks that can be done with relatively little overhead in constant time. Mutually exclusive with 226*06c3fb27SDimitry Andric// `_LIBCPP_ENABLE_DEBUG_MODE`. 227*06c3fb27SDimitry Andric// 228*06c3fb27SDimitry Andric// #define _LIBCPP_ENABLE_HARDENED_MODE 1 229*06c3fb27SDimitry Andric 230*06c3fb27SDimitry Andric// Enables the debug mode which contains all the checks from the hardened mode and additionally more expensive checks 231*06c3fb27SDimitry Andric// that may affect the complexity of algorithms. The debug mode is intended to be used for testing, not in production. 232*06c3fb27SDimitry Andric// Mutually exclusive with `_LIBCPP_ENABLE_HARDENED_MODE`. 233*06c3fb27SDimitry Andric// 234*06c3fb27SDimitry Andric// #define _LIBCPP_ENABLE_DEBUG_MODE 1 235*06c3fb27SDimitry Andric 236*06c3fb27SDimitry Andric// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These 237*06c3fb27SDimitry Andric// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. 238*06c3fb27SDimitry Andric// 239*06c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and 240*06c3fb27SDimitry Andric// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: 241*06c3fb27SDimitry Andric// - the sentinel is reachable from the begin iterator; 242*06c3fb27SDimitry Andric// - TODO(hardening): both iterators refer to the same container. 243*06c3fb27SDimitry Andric// 244*06c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through 245*06c3fb27SDimitry Andric// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access 246*06c3fb27SDimitry Andric// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like 247*06c3fb27SDimitry Andric// `optional` and `function` are considered one-element containers for the purposes of this check. 248*06c3fb27SDimitry Andric// 249*06c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the 250*06c3fb27SDimitry Andric// given ranges do not overlap. 251*06c3fb27SDimitry Andric// 252*06c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure 253*06c3fb27SDimitry Andric// the containers have compatible allocators. 254*06c3fb27SDimitry Andric// 255*06c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on 256*06c3fb27SDimitry Andric// user input. 257*06c3fb27SDimitry Andric// 258*06c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. 259*06c3fb27SDimitry Andric 260*06c3fb27SDimitry Andric# ifndef _LIBCPP_ENABLE_HARDENED_MODE 261*06c3fb27SDimitry Andric# define _LIBCPP_ENABLE_HARDENED_MODE _LIBCPP_ENABLE_HARDENED_MODE_DEFAULT 262*06c3fb27SDimitry Andric# endif 263*06c3fb27SDimitry Andric# if _LIBCPP_ENABLE_HARDENED_MODE != 0 && _LIBCPP_ENABLE_HARDENED_MODE != 1 264*06c3fb27SDimitry Andric# error "_LIBCPP_ENABLE_HARDENED_MODE must be set to 0 or 1." 265*06c3fb27SDimitry Andric# endif 266*06c3fb27SDimitry Andric 267*06c3fb27SDimitry Andric# ifndef _LIBCPP_ENABLE_DEBUG_MODE 268*06c3fb27SDimitry Andric# define _LIBCPP_ENABLE_DEBUG_MODE _LIBCPP_ENABLE_DEBUG_MODE_DEFAULT 269*06c3fb27SDimitry Andric# endif 270*06c3fb27SDimitry Andric# if _LIBCPP_ENABLE_DEBUG_MODE != 0 && _LIBCPP_ENABLE_DEBUG_MODE != 1 271*06c3fb27SDimitry Andric# error "_LIBCPP_ENABLE_DEBUG_MODE must be set to 0 or 1." 272*06c3fb27SDimitry Andric# endif 273*06c3fb27SDimitry Andric 274*06c3fb27SDimitry Andric# if _LIBCPP_ENABLE_HARDENED_MODE && _LIBCPP_ENABLE_DEBUG_MODE 275*06c3fb27SDimitry Andric# error "Only one of _LIBCPP_ENABLE_HARDENED_MODE and _LIBCPP_ENABLE_DEBUG_MODE can be enabled." 276*06c3fb27SDimitry Andric# endif 277*06c3fb27SDimitry Andric 278*06c3fb27SDimitry Andric// Hardened mode checks. 279*06c3fb27SDimitry Andric 280*06c3fb27SDimitry Andric// clang-format off 281*06c3fb27SDimitry Andric# if _LIBCPP_ENABLE_HARDENED_MODE 282*06c3fb27SDimitry Andric 283*06c3fb27SDimitry Andric// Enabled checks. 284*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 285*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 286*06c3fb27SDimitry Andric// Disabled checks. 287*06c3fb27SDimitry Andric// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security 288*06c3fb27SDimitry Andric// vulnerability. 289*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 290*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 291*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 292*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 293*06c3fb27SDimitry Andric 294*06c3fb27SDimitry Andric// Debug mode checks. 295*06c3fb27SDimitry Andric 296*06c3fb27SDimitry Andric# elif _LIBCPP_ENABLE_DEBUG_MODE 297*06c3fb27SDimitry Andric 298*06c3fb27SDimitry Andric// All checks enabled. 299*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 300*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 301*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 302*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 303*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) 304*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 305*06c3fb27SDimitry Andric 306*06c3fb27SDimitry Andric// Disable all checks if hardening is not enabled. 307*06c3fb27SDimitry Andric 308*06c3fb27SDimitry Andric# else 309*06c3fb27SDimitry Andric 310*06c3fb27SDimitry Andric// All checks disabled. 311*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression) 312*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression) 313*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 314*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 315*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 316*06c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 317*06c3fb27SDimitry Andric 318*06c3fb27SDimitry Andric# endif // _LIBCPP_ENABLE_HARDENED_MODE 319*06c3fb27SDimitry Andric// clang-format on 320*06c3fb27SDimitry Andric 321*06c3fb27SDimitry Andric// } HARDENING 322*06c3fb27SDimitry Andric 32381ad6265SDimitry Andric# define _LIBCPP_TOSTRING2(x) #x 32481ad6265SDimitry Andric# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 3250b57cec5SDimitry Andric 326*06c3fb27SDimitry Andric// NOLINTNEXTLINE(libcpp-cpp-version-check) 3270b57cec5SDimitry Andric# if __cplusplus < 201103L 3280b57cec5SDimitry Andric# define _LIBCPP_CXX03_LANG 3290b57cec5SDimitry Andric# endif 3300b57cec5SDimitry Andric 3310b57cec5SDimitry Andric# ifndef __has_attribute 3320b57cec5SDimitry Andric# define __has_attribute(__x) 0 3330b57cec5SDimitry Andric# endif 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andric# ifndef __has_builtin 3360b57cec5SDimitry Andric# define __has_builtin(__x) 0 3370b57cec5SDimitry Andric# endif 3380b57cec5SDimitry Andric 3390b57cec5SDimitry Andric# ifndef __has_extension 3400b57cec5SDimitry Andric# define __has_extension(__x) 0 3410b57cec5SDimitry Andric# endif 3420b57cec5SDimitry Andric 3430b57cec5SDimitry Andric# ifndef __has_feature 3440b57cec5SDimitry Andric# define __has_feature(__x) 0 3450b57cec5SDimitry Andric# endif 3460b57cec5SDimitry Andric 3470b57cec5SDimitry Andric# ifndef __has_cpp_attribute 3480b57cec5SDimitry Andric# define __has_cpp_attribute(__x) 0 3490b57cec5SDimitry Andric# endif 3500b57cec5SDimitry Andric 351bdd1243dSDimitry Andric# ifndef __has_constexpr_builtin 352bdd1243dSDimitry Andric# define __has_constexpr_builtin(x) 0 353bdd1243dSDimitry Andric# endif 354bdd1243dSDimitry Andric 3550b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 3560b57cec5SDimitry Andric// the compiler and '1' otherwise. 3570b57cec5SDimitry Andric# ifndef __is_identifier 3580b57cec5SDimitry Andric# define __is_identifier(__x) 1 3590b57cec5SDimitry Andric# endif 3600b57cec5SDimitry Andric 3610b57cec5SDimitry Andric# ifndef __has_declspec_attribute 3620b57cec5SDimitry Andric# define __has_declspec_attribute(__x) 0 3630b57cec5SDimitry Andric# endif 3640b57cec5SDimitry Andric 3650b57cec5SDimitry Andric# define __has_keyword(__x) !(__is_identifier(__x)) 3660b57cec5SDimitry Andric 3670b57cec5SDimitry Andric# ifndef __has_include 3680b57cec5SDimitry Andric# define __has_include(...) 0 3690b57cec5SDimitry Andric# endif 3700b57cec5SDimitry Andric 37181ad6265SDimitry Andric# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 37281ad6265SDimitry Andric# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 3730b57cec5SDimitry Andric# endif 3740b57cec5SDimitry Andric 3750b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This 3760b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume 3770b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, 3780b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this 3790b57cec5SDimitry Andric// heuristic falls short. 3800b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) 3810b57cec5SDimitry Andric# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" 3820b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) 3830b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 3840b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) 3850b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 3860b57cec5SDimitry Andric# else 3870b57cec5SDimitry Andric# if defined(_WIN32) && defined(_MSC_VER) 3880b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 3890b57cec5SDimitry Andric# else 3900b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 3910b57cec5SDimitry Andric# endif 3920b57cec5SDimitry Andric# endif 3930b57cec5SDimitry Andric 3940b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 3950b57cec5SDimitry Andric# define _LIBCPP_ABI_VCRUNTIME 3960b57cec5SDimitry Andric# endif 3970b57cec5SDimitry Andric 398fcaf7f86SDimitry Andric# if __has_feature(experimental_library) 399fcaf7f86SDimitry Andric# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 400fcaf7f86SDimitry Andric# define _LIBCPP_ENABLE_EXPERIMENTAL 401fcaf7f86SDimitry Andric# endif 402fcaf7f86SDimitry Andric# endif 403fcaf7f86SDimitry Andric 404fcaf7f86SDimitry Andric// Incomplete features get their own specific disabling flags. This makes it 405fcaf7f86SDimitry Andric// easier to grep for target specific flags once the feature is complete. 406fcaf7f86SDimitry Andric# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 407*06c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL 408*06c3fb27SDimitry Andric# endif 409*06c3fb27SDimitry Andric 410*06c3fb27SDimitry Andric# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 411*06c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN 412fcaf7f86SDimitry Andric# endif 413fcaf7f86SDimitry Andric 4140b57cec5SDimitry Andric// Need to detect which libc we're using if we're on Linux. 4150b57cec5SDimitry Andric# if defined(__linux__) 4160b57cec5SDimitry Andric# include <features.h> 4170b57cec5SDimitry Andric# if defined(__GLIBC_PREREQ) 4180b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) 4190b57cec5SDimitry Andric# else 4200b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) 0 4210b57cec5SDimitry Andric# endif // defined(__GLIBC_PREREQ) 4220b57cec5SDimitry Andric# endif // defined(__linux__) 4230b57cec5SDimitry Andric 42404eeddc0SDimitry Andric# if defined(__MVS__) 42504eeddc0SDimitry Andric# include <features.h> // for __NATIVE_ASCII_F 42604eeddc0SDimitry Andric# endif 42704eeddc0SDimitry Andric 4280b57cec5SDimitry Andric# ifdef __LITTLE_ENDIAN__ 4290b57cec5SDimitry Andric# if __LITTLE_ENDIAN__ 4300b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4310b57cec5SDimitry Andric# endif // __LITTLE_ENDIAN__ 4320b57cec5SDimitry Andric# endif // __LITTLE_ENDIAN__ 4330b57cec5SDimitry Andric 4340b57cec5SDimitry Andric# ifdef __BIG_ENDIAN__ 4350b57cec5SDimitry Andric# if __BIG_ENDIAN__ 4360b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4370b57cec5SDimitry Andric# endif // __BIG_ENDIAN__ 4380b57cec5SDimitry Andric# endif // __BIG_ENDIAN__ 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andric# ifdef __BYTE_ORDER__ 4410b57cec5SDimitry Andric# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 4420b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4430b57cec5SDimitry Andric# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4440b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4450b57cec5SDimitry Andric# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4460b57cec5SDimitry Andric# endif // __BYTE_ORDER__ 4470b57cec5SDimitry Andric 4480b57cec5SDimitry Andric# ifdef __FreeBSD__ 4490b57cec5SDimitry Andric# include <osreldate.h> 450*06c3fb27SDimitry Andric# include <sys/endian.h> 4510b57cec5SDimitry Andric# if _BYTE_ORDER == _LITTLE_ENDIAN 4520b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4530b57cec5SDimitry Andric# else // _BYTE_ORDER == _LITTLE_ENDIAN 4540b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4550b57cec5SDimitry Andric# endif // _BYTE_ORDER == _LITTLE_ENDIAN 4560b57cec5SDimitry Andric# endif // __FreeBSD__ 4570b57cec5SDimitry Andric 458e8d8bef9SDimitry Andric# if defined(__NetBSD__) || defined(__OpenBSD__) 4590b57cec5SDimitry Andric# include <sys/endian.h> 4600b57cec5SDimitry Andric# if _BYTE_ORDER == _LITTLE_ENDIAN 4610b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4620b57cec5SDimitry Andric# else // _BYTE_ORDER == _LITTLE_ENDIAN 4630b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4640b57cec5SDimitry Andric# endif // _BYTE_ORDER == _LITTLE_ENDIAN 465e8d8bef9SDimitry Andric# endif // defined(__NetBSD__) || defined(__OpenBSD__) 4660b57cec5SDimitry Andric 4670b57cec5SDimitry Andric# if defined(_WIN32) 4680b57cec5SDimitry Andric# define _LIBCPP_WIN32API 4690b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4700b57cec5SDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 4710b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment 4720b57cec5SDimitry Andric# define _LIBCPP_MSVCRT_LIKE 4730b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if 4740b57cec5SDimitry Andric// a MS compatibility version is specified. 4750b57cec5SDimitry Andric# if defined(_MSC_VER) && !defined(__MINGW32__) 4760b57cec5SDimitry Andric# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 4770b57cec5SDimitry Andric# endif 4780b57cec5SDimitry Andric# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 4790b57cec5SDimitry Andric# define _LIBCPP_HAS_BITSCAN64 4800b57cec5SDimitry Andric# endif 4810b57cec5SDimitry Andric# define _LIBCPP_HAS_OPEN_WITH_WCHAR 4820b57cec5SDimitry Andric# endif // defined(_WIN32) 4830b57cec5SDimitry Andric 484349cc55cSDimitry Andric# if defined(_AIX) && !defined(__64BIT__) 485349cc55cSDimitry Andric// The size of wchar is 2 byte on 32-bit mode on AIX. 486349cc55cSDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 487349cc55cSDimitry Andric# endif 488349cc55cSDimitry Andric 4890eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device. 4900eae32dcSDimitry Andric// 4910eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM 4920eae32dcSDimitry Andric// Read entropy from the given file, by default `/dev/urandom`. 4930eae32dcSDimitry Andric// If a token is provided, it is assumed to be the path to a file 4940eae32dcSDimitry Andric// to read entropy from. This is the default behavior if nothing 4950eae32dcSDimitry Andric// else is specified. This implementation requires storing state 4960eae32dcSDimitry Andric// inside `std::random_device`. 4970eae32dcSDimitry Andric// 4980eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM 4990eae32dcSDimitry Andric// Use arc4random(). This allows obtaining random data even when 5000eae32dcSDimitry Andric// using sandboxing mechanisms. On some platforms like Apple, this 5010eae32dcSDimitry Andric// is the recommended source of entropy for user-space programs. 5020eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5030eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5040eae32dcSDimitry Andric// 5050eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY 5060eae32dcSDimitry Andric// Use getentropy(). 5070eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5080eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5090eae32dcSDimitry Andric// 51004eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG 51104eeddc0SDimitry Andric// Use Fuchsia's zx_cprng_draw() system call, which is specified to 51204eeddc0SDimitry Andric// deliver high-quality entropy and cannot fail. 51304eeddc0SDimitry Andric// When this option is used, the token passed to `std::random_device`'s 51404eeddc0SDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 51504eeddc0SDimitry Andric// 5160eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM 5170eae32dcSDimitry Andric// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 5180eae32dcSDimitry Andric// including accesses to the special files under `/dev`. This implementation 5190eae32dcSDimitry Andric// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 5200eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5210eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5220eae32dcSDimitry Andric// 5230eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM 5240eae32dcSDimitry Andric// Use rand_s(), for use on Windows. 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. 52781ad6265SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 528*06c3fb27SDimitry Andric defined(__DragonFly__) 5290b57cec5SDimitry Andric# define _LIBCPP_USING_ARC4_RANDOM 53081ad6265SDimitry Andric# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 5310b57cec5SDimitry Andric# define _LIBCPP_USING_GETENTROPY 53204eeddc0SDimitry Andric# elif defined(__Fuchsia__) 53304eeddc0SDimitry Andric# define _LIBCPP_USING_FUCHSIA_CPRNG 5340b57cec5SDimitry Andric# elif defined(__native_client__) 5350b57cec5SDimitry Andric# define _LIBCPP_USING_NACL_RANDOM 5360b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 5370b57cec5SDimitry Andric# define _LIBCPP_USING_WIN32_RANDOM 5380b57cec5SDimitry Andric# else 5390b57cec5SDimitry Andric# define _LIBCPP_USING_DEV_RANDOM 5400b57cec5SDimitry Andric# endif 5410b57cec5SDimitry Andric 5420b57cec5SDimitry Andric# if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) 5430b57cec5SDimitry Andric# include <endian.h> 5440b57cec5SDimitry Andric# if __BYTE_ORDER == __LITTLE_ENDIAN 5450b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 5460b57cec5SDimitry Andric# elif __BYTE_ORDER == __BIG_ENDIAN 5470b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 5480b57cec5SDimitry Andric# else // __BYTE_ORDER == __BIG_ENDIAN 5490b57cec5SDimitry Andric# error unable to determine endian 5500b57cec5SDimitry Andric# endif 5510b57cec5SDimitry Andric# endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) 5520b57cec5SDimitry Andric 5530b57cec5SDimitry Andric# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 5540b57cec5SDimitry Andric# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 5550b57cec5SDimitry Andric# else 5560b57cec5SDimitry Andric# define _LIBCPP_NO_CFI 5570b57cec5SDimitry Andric# endif 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andric# ifndef _LIBCPP_CXX03_LANG 56081ad6265SDimitry Andric 5610b57cec5SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 56281ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) alignas(x) 56381ad6265SDimitry Andric# define _ALIGNAS(x) alignas(x) 56481ad6265SDimitry Andric# define _LIBCPP_NORETURN [[noreturn]] 56581ad6265SDimitry Andric# define _NOEXCEPT noexcept 56681ad6265SDimitry Andric# define _NOEXCEPT_(x) noexcept(x) 567bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR constexpr 56881ad6265SDimitry Andric 5690b57cec5SDimitry Andric# else 57081ad6265SDimitry Andric 57181ad6265SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 57281ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 57381ad6265SDimitry Andric# define _ALIGNAS(x) __attribute__((__aligned__(x))) 574bdd1243dSDimitry Andric# define _LIBCPP_NORETURN __attribute__((__noreturn__)) 57581ad6265SDimitry Andric# define _LIBCPP_HAS_NO_NOEXCEPT 57681ad6265SDimitry Andric# define nullptr __nullptr 57781ad6265SDimitry Andric# define _NOEXCEPT throw() 57881ad6265SDimitry Andric# define _NOEXCEPT_(x) 579bdd1243dSDimitry Andric# define static_assert(...) _Static_assert(__VA_ARGS__) 580bdd1243dSDimitry Andric# define decltype(...) __decltype(__VA_ARGS__) 581bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR 58281ad6265SDimitry Andric 58381ad6265SDimitry Andrictypedef __char16_t char16_t; 58481ad6265SDimitry Andrictypedef __char32_t char32_t; 58581ad6265SDimitry Andric 58681ad6265SDimitry Andric# endif 58781ad6265SDimitry Andric 58881ad6265SDimitry Andric# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L 589*06c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXCEPTIONS 5900b57cec5SDimitry Andric# endif 5910b57cec5SDimitry Andric 5920b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 5930b57cec5SDimitry Andric 594fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) 5950b57cec5SDimitry Andric 596*06c3fb27SDimitry Andric# if defined(__APPLE__) 597*06c3fb27SDimitry Andric# if defined(__i386__) || defined(__x86_64__) 598*06c3fb27SDimitry Andric// use old string layout on x86_64 and i386 599*06c3fb27SDimitry Andric# elif defined(__arm__) 600*06c3fb27SDimitry Andric// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs 601*06c3fb27SDimitry Andric# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 6020b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 6030b57cec5SDimitry Andric# endif 604*06c3fb27SDimitry Andric# else 605*06c3fb27SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 606*06c3fb27SDimitry Andric# endif 607*06c3fb27SDimitry Andric# endif 6080b57cec5SDimitry Andric 6090b57cec5SDimitry Andric// Objective-C++ features (opt-in) 6100b57cec5SDimitry Andric# if __has_feature(objc_arc) 6110b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC 6120b57cec5SDimitry Andric# endif 6130b57cec5SDimitry Andric 6140b57cec5SDimitry Andric# if __has_feature(objc_arc_weak) 6150b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC_WEAK 6160b57cec5SDimitry Andric# endif 6170b57cec5SDimitry Andric 6185ffd83dbSDimitry Andric# if __has_extension(blocks) 6195ffd83dbSDimitry Andric# define _LIBCPP_HAS_EXTENSION_BLOCKS 6205ffd83dbSDimitry Andric# endif 6215ffd83dbSDimitry Andric 6225ffd83dbSDimitry Andric# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) 6235ffd83dbSDimitry Andric# define _LIBCPP_HAS_BLOCKS_RUNTIME 6245ffd83dbSDimitry Andric# endif 6255ffd83dbSDimitry Andric 626fe6060f1SDimitry Andric# if !__has_feature(address_sanitizer) 6270b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 6280b57cec5SDimitry Andric# endif 6290b57cec5SDimitry Andric 6300b57cec5SDimitry Andric// Allow for build-time disabling of unsigned integer sanitization 631fe6060f1SDimitry Andric# if __has_attribute(no_sanitize) 6320b57cec5SDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 6330b57cec5SDimitry Andric# endif 6340b57cec5SDimitry Andric 6350b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 6360b57cec5SDimitry Andric 637e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 638e40139ffSDimitry Andric 6390b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 6400b57cec5SDimitry Andric 641fe6060f1SDimitry Andric# if !defined(__SANITIZE_ADDRESS__) 6420b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 6430b57cec5SDimitry Andric# endif 6440b57cec5SDimitry Andric 6450b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 6460b57cec5SDimitry Andric 647e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 648e40139ffSDimitry Andric 649bdd1243dSDimitry Andric# endif // _LIBCPP_COMPILER_[CLANG|GCC] 6500b57cec5SDimitry Andric 6510b57cec5SDimitry Andric# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 6520b57cec5SDimitry Andric 6530b57cec5SDimitry Andric# ifdef _DLL 6540b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC __declspec(dllimport) 6550b57cec5SDimitry Andric# else 6560b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC 6570b57cec5SDimitry Andric# endif 6580b57cec5SDimitry Andric 65981ad6265SDimitry Andric# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 6600b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS 6610b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 6620b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6630b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 6640b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI 6650b57cec5SDimitry Andric# elif defined(_LIBCPP_BUILDING_LIBRARY) 6660b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllexport) 6670b57cec5SDimitry Andric# if defined(__MINGW32__) 6680b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 6690b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6700b57cec5SDimitry Andric# else 6710b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 6720b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 6730b57cec5SDimitry Andric# endif 6740b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 6750b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 6760b57cec5SDimitry Andric# else 6770b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllimport) 6780b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 6790b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6800b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 6810b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 6820b57cec5SDimitry Andric# endif 6830b57cec5SDimitry Andric 6840b57cec5SDimitry Andric# define _LIBCPP_HIDDEN 6850b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 6860b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 687fe6060f1SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS 6880b57cec5SDimitry Andric# define _LIBCPP_ENUM_VIS 6890b57cec5SDimitry Andric 6900b57cec5SDimitry Andric# else 69181ad6265SDimitry Andric 69281ad6265SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 69381ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 69481ad6265SDimitry Andric# else 69581ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) 6960b57cec5SDimitry Andric# endif 6970b57cec5SDimitry Andric 69881ad6265SDimitry Andric# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 69981ad6265SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 70081ad6265SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 70181ad6265SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 70281ad6265SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 70381ad6265SDimitry Andric 704fcaf7f86SDimitry Andric// TODO: Make this a proper customization point or remove the option to override it. 705fcaf7f86SDimitry Andric# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 706fcaf7f86SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 707fcaf7f86SDimitry Andric# endif 708fcaf7f86SDimitry Andric 7090b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 7100b57cec5SDimitry Andric// The inline should be removed once PR32114 is resolved 7110b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 7120b57cec5SDimitry Andric# else 7130b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 7140b57cec5SDimitry Andric# endif 7150b57cec5SDimitry Andric 7160b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 7170b57cec5SDimitry Andric# if __has_attribute(__type_visibility__) 7180b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default"))) 7190b57cec5SDimitry Andric# else 7200b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 7210b57cec5SDimitry Andric# endif 7220b57cec5SDimitry Andric# else 7230b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 7240b57cec5SDimitry Andric# endif 7250b57cec5SDimitry Andric 7260b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) 7270b57cec5SDimitry Andric# define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default"))) 7280b57cec5SDimitry Andric# else 7290b57cec5SDimitry Andric# define _LIBCPP_ENUM_VIS 7300b57cec5SDimitry Andric# endif 7310b57cec5SDimitry Andric 73281ad6265SDimitry Andric# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 7330b57cec5SDimitry Andric 7340b57cec5SDimitry Andric# if __has_attribute(exclude_from_explicit_instantiation) 7350b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 7360b57cec5SDimitry Andric# else 7370b57cec5SDimitry Andric// Try to approximate the effect of exclude_from_explicit_instantiation 7380b57cec5SDimitry Andric// (which is that entities are not assumed to be provided by explicit 7390b57cec5SDimitry Andric// template instantiations in the dylib) by always inlining those entities. 7400b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 7410b57cec5SDimitry Andric# endif 7420b57cec5SDimitry Andric 743753f127fSDimitry Andric// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 744753f127fSDimitry Andric// on two levels: 745753f127fSDimitry Andric// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 746753f127fSDimitry Andric// symbols from their dynamic library by means of using the libc++ headers. This ensures 747753f127fSDimitry Andric// that those symbols stay private to the dynamic library in which it is defined. 748753f127fSDimitry Andric// 749753f127fSDimitry Andric// 2. The symbol is given an ABI tag that changes with each version of libc++. This ensures 750753f127fSDimitry Andric// that no ODR violation can arise from mixing two TUs compiled with different versions 751753f127fSDimitry Andric// of libc++ where we would have changed the definition of a symbol. If the symbols shared 752753f127fSDimitry Andric// the same name, the ODR would require that their definitions be token-by-token equivalent, 753753f127fSDimitry Andric// which basically prevents us from being able to make any change to any function in our 754753f127fSDimitry Andric// headers. Using this ABI tag ensures that the symbol name is "bumped" artificially at 755753f127fSDimitry Andric// each release, which lets us change the definition of these symbols at our leisure. 756753f127fSDimitry Andric// Note that historically, this has been achieved in various ways, including force-inlining 757753f127fSDimitry Andric// all functions or giving internal linkage to all functions. Both these (previous) solutions 758753f127fSDimitry Andric// suffer from drawbacks that lead notably to code bloat. 759753f127fSDimitry Andric// 760753f127fSDimitry Andric// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 761753f127fSDimitry Andric// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 762753f127fSDimitry Andric// 763bdd1243dSDimitry Andric// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 764bdd1243dSDimitry Andric// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 765bdd1243dSDimitry Andric// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 766bdd1243dSDimitry Andric// the virtual function pointer in the vtable based on the mangled name of the function. Since 767bdd1243dSDimitry Andric// we use an ABI tag that changes with each released version, the mangled name of the virtual 768bdd1243dSDimitry Andric// function would change, which is incorrect. Note that it doesn't make much sense to change 769bdd1243dSDimitry Andric// the implementation of a virtual function in an ABI-incompatible way in the first place, 770bdd1243dSDimitry Andric// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 771bdd1243dSDimitry Andric// 772753f127fSDimitry Andric// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 773753f127fSDimitry Andric// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 774753f127fSDimitry Andric// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 775753f127fSDimitry Andric# ifndef _LIBCPP_NO_ABI_TAG 776753f127fSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI \ 777753f127fSDimitry Andric _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 778753f127fSDimitry Andric __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER)))) 7790b57cec5SDimitry Andric# else 7800b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 7810b57cec5SDimitry Andric# endif 782bdd1243dSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 7830b57cec5SDimitry Andric 7841ac55f4cSDimitry Andric// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern 7851ac55f4cSDimitry Andric// "C" function, as those lack mangling. 7861ac55f4cSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 7871ac55f4cSDimitry Andric 7880b57cec5SDimitry Andric# ifdef _LIBCPP_BUILDING_LIBRARY 7890b57cec5SDimitry Andric# if _LIBCPP_ABI_VERSION > 1 7900b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 7910b57cec5SDimitry Andric# else 7920b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 7930b57cec5SDimitry Andric# endif 7940b57cec5SDimitry Andric# else 7950b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 7960b57cec5SDimitry Andric# endif 7970b57cec5SDimitry Andric 7980b57cec5SDimitry Andric// Just so we can migrate to the new macros gradually. 7990b57cec5SDimitry Andric# define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI 8000b57cec5SDimitry Andric 8010b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 80281ad6265SDimitry Andric// clang-format off 8030b57cec5SDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { 8040b57cec5SDimitry Andric# define _LIBCPP_END_NAMESPACE_STD }} 8051fd87a68SDimitry Andric# define _VSTD std 80681ad6265SDimitry Andric 8070b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD 8080b57cec5SDimitry Andric 809*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 8100b57cec5SDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ 8110b57cec5SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem { 8120b57cec5SDimitry Andric# else 8130b57cec5SDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ 8140b57cec5SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem { 8150b57cec5SDimitry Andric# endif 8160b57cec5SDimitry Andric 81781ad6265SDimitry Andric# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }} 81881ad6265SDimitry Andric// clang-format on 8190b57cec5SDimitry Andric 82081ad6265SDimitry Andric# define _VSTD_FS std::__fs::filesystem 8210b57cec5SDimitry Andric 8220b57cec5SDimitry Andric# if __has_attribute(__enable_if__) 8230b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 8240b57cec5SDimitry Andric# endif 8250b57cec5SDimitry Andric 826*06c3fb27SDimitry Andric# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) 8270b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_INT128 8280b57cec5SDimitry Andric# endif 8290b57cec5SDimitry Andric 830bdd1243dSDimitry Andric# if __has_attribute(__malloc__) 8310b57cec5SDimitry Andric# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 8320b57cec5SDimitry Andric# else 8330b57cec5SDimitry Andric# define _LIBCPP_NOALIAS 8340b57cec5SDimitry Andric# endif 8350b57cec5SDimitry Andric 836bdd1243dSDimitry Andric# if __has_attribute(__using_if_exists__) 837bdd1243dSDimitry Andric# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 8380b57cec5SDimitry Andric# else 839fe6060f1SDimitry Andric# define _LIBCPP_USING_IF_EXISTS 8400b57cec5SDimitry Andric# endif 8410b57cec5SDimitry Andric 84281ad6265SDimitry Andric# ifdef _LIBCPP_CXX03_LANG 84381ad6265SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 844*06c3fb27SDimitry Andric struct _LIBCPP_EXPORTED_FROM_ABI x { \ 84581ad6265SDimitry Andric enum __lx 84681ad6265SDimitry Andric// clang-format off 8470b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 8480b57cec5SDimitry Andric __lx __v_; \ 8490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \ 8500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 8510b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; } \ 8520b57cec5SDimitry Andric }; 85381ad6265SDimitry Andric// clang-format on 85481ad6265SDimitry Andric 85581ad6265SDimitry Andric# else // _LIBCPP_CXX03_LANG 8560b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x 8570b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 85881ad6265SDimitry Andric# endif // _LIBCPP_CXX03_LANG 8590b57cec5SDimitry Andric 860*06c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) 8610b57cec5SDimitry Andric# define _LIBCPP_LOCALE__L_EXTENSIONS 1 8620b57cec5SDimitry Andric# endif 8630b57cec5SDimitry Andric 8640b57cec5SDimitry Andric# ifdef __FreeBSD__ 8650b57cec5SDimitry Andric# define _DECLARE_C99_LDBL_MATH 1 8660b57cec5SDimitry Andric# endif 8670b57cec5SDimitry Andric 8680b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads 8690b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 8700b57cec5SDimitry Andric# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 8710b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 8720b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 8730b57cec5SDimitry Andric// We're deferring to Microsoft's STL to provide aligned new et al. We don't 8740b57cec5SDimitry Andric// have it unless the language feature test macro is defined. 8750b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 876e8d8bef9SDimitry Andric# elif defined(__MVS__) 877e8d8bef9SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 8780b57cec5SDimitry Andric# endif 8790b57cec5SDimitry Andric 88081ad6265SDimitry Andric# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 8810b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 8820b57cec5SDimitry Andric# endif 8830b57cec5SDimitry Andric 884bdd1243dSDimitry Andric// It is not yet possible to use aligned_alloc() on all Apple platforms since 885bdd1243dSDimitry Andric// 10.15 was the first version to ship an implementation of aligned_alloc(). 886bdd1243dSDimitry Andric# if defined(__APPLE__) 887bdd1243dSDimitry Andric# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 888bdd1243dSDimitry Andric __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) 889bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 890bdd1243dSDimitry Andric# endif 891bdd1243dSDimitry Andric# elif defined(__ANDROID__) && __ANDROID_API__ < 28 892bdd1243dSDimitry Andric// Android only provides aligned_alloc when targeting API 28 or higher. 893bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 894bdd1243dSDimitry Andric# endif 895bdd1243dSDimitry Andric 8960b57cec5SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 8970b57cec5SDimitry Andric# define _LIBCPP_HAS_DEFAULTRUNELOCALE 8980b57cec5SDimitry Andric# endif 8990b57cec5SDimitry Andric 900*06c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 9010b57cec5SDimitry Andric# define _LIBCPP_WCTYPE_IS_MASK 9020b57cec5SDimitry Andric# endif 9030b57cec5SDimitry Andric 9040b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 905fe6060f1SDimitry Andric# define _LIBCPP_HAS_NO_CHAR8_T 9060b57cec5SDimitry Andric# endif 9070b57cec5SDimitry Andric 9080b57cec5SDimitry Andric// Deprecation macros. 9090b57cec5SDimitry Andric// 9100b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out 9110b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 9120b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 913*06c3fb27SDimitry Andric# if __has_attribute(__deprecated__) 914*06c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) 915*06c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) 916*06c3fb27SDimitry Andric# elif _LIBCPP_STD_VER >= 14 9170b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED [[deprecated]] 91881ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 9190b57cec5SDimitry Andric# else 9200b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 92181ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9220b57cec5SDimitry Andric# endif 9230b57cec5SDimitry Andric# else 9240b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 92581ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9260b57cec5SDimitry Andric# endif 9270b57cec5SDimitry Andric 9280b57cec5SDimitry Andric# if !defined(_LIBCPP_CXX03_LANG) 9290b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 9300b57cec5SDimitry Andric# else 9310b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 9320b57cec5SDimitry Andric# endif 9330b57cec5SDimitry Andric 934*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 9350b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 9360b57cec5SDimitry Andric# else 9370b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 9380b57cec5SDimitry Andric# endif 9390b57cec5SDimitry Andric 940*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 9410b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 9420b57cec5SDimitry Andric# else 9430b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 9440b57cec5SDimitry Andric# endif 9450b57cec5SDimitry Andric 946*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 947e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 948e8d8bef9SDimitry Andric# else 949e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 950e8d8bef9SDimitry Andric# endif 951e8d8bef9SDimitry Andric 952bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 23 953bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 954bdd1243dSDimitry Andric# else 955bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 956bdd1243dSDimitry Andric# endif 957bdd1243dSDimitry Andric 958fe6060f1SDimitry Andric# if !defined(_LIBCPP_HAS_NO_CHAR8_T) 959e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 960e8d8bef9SDimitry Andric# else 961e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 962e8d8bef9SDimitry Andric# endif 963e8d8bef9SDimitry Andric 964e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed. 965fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 966e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 96781ad6265SDimitry Andric _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 968fe6060f1SDimitry Andric _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 96981ad6265SDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 970fe6060f1SDimitry Andric# else 971e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 972e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP 973e40139ffSDimitry Andric# endif 974e40139ffSDimitry Andric 9750b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 11 976*06c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 9770b57cec5SDimitry Andric# else 978*06c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit 9790b57cec5SDimitry Andric# endif 9800b57cec5SDimitry Andric 981*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 982*06c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit 983*06c3fb27SDimitry Andric# else 984*06c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 985*06c3fb27SDimitry Andric# endif 986*06c3fb27SDimitry Andric 987*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 988bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 9890b57cec5SDimitry Andric# else 990bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 9910b57cec5SDimitry Andric# endif 9920b57cec5SDimitry Andric 993*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 994bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 9950b57cec5SDimitry Andric# else 996bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 9970b57cec5SDimitry Andric# endif 9980b57cec5SDimitry Andric 999*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 1000bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 10010b57cec5SDimitry Andric# else 1002bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 10030b57cec5SDimitry Andric# endif 10040b57cec5SDimitry Andric 1005*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 1006bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 1007bdd1243dSDimitry Andric# else 1008bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 1009bdd1243dSDimitry Andric# endif 1010bdd1243dSDimitry Andric 1011bdd1243dSDimitry Andric# if __has_cpp_attribute(nodiscard) 1012*06c3fb27SDimitry Andric# define _LIBCPP_NODISCARD [[__nodiscard__]] 10130b57cec5SDimitry Andric# else 10140b57cec5SDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and 10150b57cec5SDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via 10160b57cec5SDimitry Andric// (void) cast. 1017349cc55cSDimitry Andric# define _LIBCPP_NODISCARD 10180b57cec5SDimitry Andric# endif 10190b57cec5SDimitry Andric 10200b57cec5SDimitry Andric// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not 10210b57cec5SDimitry Andric// specified as such as an extension. 1022bdd1243dSDimitry Andric# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 1023349cc55cSDimitry Andric# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD 10240b57cec5SDimitry Andric# else 10250b57cec5SDimitry Andric# define _LIBCPP_NODISCARD_EXT 10260b57cec5SDimitry Andric# endif 10270b57cec5SDimitry Andric 1028*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 1029349cc55cSDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD 10300b57cec5SDimitry Andric# else 10310b57cec5SDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 10320b57cec5SDimitry Andric# endif 10330b57cec5SDimitry Andric 1034bdd1243dSDimitry Andric# if __has_attribute(__no_destroy__) 10350b57cec5SDimitry Andric# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 10360b57cec5SDimitry Andric# else 10370b57cec5SDimitry Andric# define _LIBCPP_NO_DESTROY 10380b57cec5SDimitry Andric# endif 10390b57cec5SDimitry Andric 10400b57cec5SDimitry Andric# ifndef _LIBCPP_HAS_NO_ASAN 1041*06c3fb27SDimitry Andric extern "C" _LIBCPP_EXPORTED_FROM_ABI void 104281ad6265SDimitry Andric __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); 1043*06c3fb27SDimitry Andric# if _LIBCPP_CLANG_VER >= 1600 1044*06c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container( 1045*06c3fb27SDimitry Andric const void*, const void*, const void*, const void*, const void*, const void*); 1046*06c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI int 1047*06c3fb27SDimitry Andric__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*); 1048*06c3fb27SDimitry Andric# endif 10490b57cec5SDimitry Andric# endif 10500b57cec5SDimitry Andric 10510b57cec5SDimitry Andric// Try to find out if RTTI is disabled. 105281ad6265SDimitry Andric# if !defined(__cpp_rtti) || __cpp_rtti < 199711L 10531ac55f4cSDimitry Andric# define _LIBCPP_HAS_NO_RTTI 10540b57cec5SDimitry Andric# endif 10550b57cec5SDimitry Andric 10560b57cec5SDimitry Andric# ifndef _LIBCPP_WEAK 10570b57cec5SDimitry Andric# define _LIBCPP_WEAK __attribute__((__weak__)) 10580b57cec5SDimitry Andric# endif 10590b57cec5SDimitry Andric 10600b57cec5SDimitry Andric// Thread API 106181ad6265SDimitry Andric// clang-format off 10620b57cec5SDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && \ 10630b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 10640b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 10650b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 106681ad6265SDimitry Andric 10670b57cec5SDimitry Andric# if defined(__FreeBSD__) || \ 10680b57cec5SDimitry Andric defined(__wasi__) || \ 10690b57cec5SDimitry Andric defined(__NetBSD__) || \ 1070e8d8bef9SDimitry Andric defined(__OpenBSD__) || \ 1071e8d8bef9SDimitry Andric defined(__NuttX__) || \ 10720b57cec5SDimitry Andric defined(__linux__) || \ 10730b57cec5SDimitry Andric defined(__GNU__) || \ 10740b57cec5SDimitry Andric defined(__APPLE__) || \ 1075e8d8bef9SDimitry Andric defined(__MVS__) || \ 107681ad6265SDimitry Andric defined(_AIX) || \ 107781ad6265SDimitry Andric defined(__EMSCRIPTEN__) 107881ad6265SDimitry Andric// clang-format on 10790b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 1080480093f4SDimitry Andric# elif defined(__Fuchsia__) 10815ffd83dbSDimitry Andric// TODO(44575): Switch to C11 thread API when possible. 10825ffd83dbSDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 10830b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 10840b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_WIN32 10850b57cec5SDimitry Andric# else 10860b57cec5SDimitry Andric# error "No thread API" 10870b57cec5SDimitry Andric# endif // _LIBCPP_HAS_THREAD_API 10880b57cec5SDimitry Andric# endif // _LIBCPP_HAS_NO_THREADS 10890b57cec5SDimitry Andric 1090e40139ffSDimitry Andric# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1091e40139ffSDimitry Andric# if defined(__ANDROID__) && __ANDROID_API__ >= 30 1092e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1093e40139ffSDimitry Andric# elif defined(_LIBCPP_GLIBC_PREREQ) 1094e40139ffSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 30) 1095e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1096e40139ffSDimitry Andric# endif 1097e40139ffSDimitry Andric# endif 1098e40139ffSDimitry Andric# endif 1099e40139ffSDimitry Andric 11000b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 11010b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 11020b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is not defined. 11030b57cec5SDimitry Andric# endif 11040b57cec5SDimitry Andric 11050b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 11060b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 11070b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 11080b57cec5SDimitry Andric# endif 11090b57cec5SDimitry Andric 11100b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 11110b57cec5SDimitry Andric# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 11120b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 11130b57cec5SDimitry Andric# endif 11140b57cec5SDimitry Andric 1115e40139ffSDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 1116e40139ffSDimitry Andric# define __STDCPP_THREADS__ 1 1117e40139ffSDimitry Andric# endif 1118e40139ffSDimitry Andric 1119e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements 11200b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 11210b57cec5SDimitry Andric// mutexes have no destroy mechanism. 1122e40139ffSDimitry Andric// 1123e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1124e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources. 1125e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1126e40139ffSDimitry Andric// 1127e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their 1128e40139ffSDimitry Andric// respective stakeholders. 112981ad6265SDimitry Andric// clang-format off 113081ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ 113181ad6265SDimitry Andric (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 113281ad6265SDimitry Andric defined(_LIBCPP_HAS_THREAD_API_WIN32) 113381ad6265SDimitry Andric// clang-format on 11340b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 11350b57cec5SDimitry Andric# endif 11360b57cec5SDimitry Andric 11370b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows. 1138e40139ffSDimitry Andric// 1139e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1140e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources. 1141e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1142e40139ffSDimitry Andric// 11430b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations 11440b57cec5SDimitry Andric// as well. 114581ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) 11460b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 11470b57cec5SDimitry Andric# endif 11480b57cec5SDimitry Andric 11490b57cec5SDimitry Andric// Some systems do not provide gets() in their C library, for security reasons. 115081ad6265SDimitry Andric# if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__) 11510b57cec5SDimitry Andric# define _LIBCPP_C_HAS_NO_GETS 11520b57cec5SDimitry Andric# endif 11530b57cec5SDimitry Andric 115481ad6265SDimitry Andric# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 115504eeddc0SDimitry Andric defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 11560b57cec5SDimitry Andric# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 11570b57cec5SDimitry Andric# endif 11580b57cec5SDimitry Andric 11590b57cec5SDimitry Andric# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 11600b57cec5SDimitry Andric# define _LIBCPP_HAS_C_ATOMIC_IMP 11610b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 11620b57cec5SDimitry Andric# define _LIBCPP_HAS_GCC_ATOMIC_IMP 11630b57cec5SDimitry Andric# endif 11640b57cec5SDimitry Andric 116581ad6265SDimitry Andric# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1166349cc55cSDimitry Andric !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 11670b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ATOMIC_HEADER 11680b57cec5SDimitry Andric# else 11690b57cec5SDimitry Andric# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 11700b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_FLAG_TYPE bool 11710b57cec5SDimitry Andric# endif 11720b57cec5SDimitry Andric# ifdef _LIBCPP_FREESTANDING 11730b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS 11740b57cec5SDimitry Andric# endif 11750b57cec5SDimitry Andric# endif 11760b57cec5SDimitry Andric 11770b57cec5SDimitry Andric# ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 11780b57cec5SDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 11790b57cec5SDimitry Andric# endif 11800b57cec5SDimitry Andric 1181*06c3fb27SDimitry Andric# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) 1182*06c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) 1183*06c3fb27SDimitry Andric# else 1184*06c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 1185*06c3fb27SDimitry Andric# endif 1186*06c3fb27SDimitry Andric 11870b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 11880b57cec5SDimitry Andric# if defined(__clang__) && __has_attribute(acquire_capability) 11890b57cec5SDimitry Andric// Work around the attribute handling in clang. When both __declspec and 11900b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition 11911fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 11921fd87a68SDimitry Andric// combining the two does work. 11931fd87a68SDimitry Andric# if !defined(_MSC_VER) 11940b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 11950b57cec5SDimitry Andric# endif 11960b57cec5SDimitry Andric# endif 11970b57cec5SDimitry Andric# endif 11980b57cec5SDimitry Andric 1199480093f4SDimitry Andric# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1200480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1201480093f4SDimitry Andric# else 1202480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1203480093f4SDimitry Andric# endif 1204480093f4SDimitry Andric 1205*06c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 120681ad6265SDimitry Andric# define _LIBCPP_CONSTINIT constinit 1207bdd1243dSDimitry Andric# elif __has_attribute(__require_constant_initialization__) 120881ad6265SDimitry Andric# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 12090b57cec5SDimitry Andric# else 121081ad6265SDimitry Andric# define _LIBCPP_CONSTINIT 12110b57cec5SDimitry Andric# endif 12120b57cec5SDimitry Andric 1213bdd1243dSDimitry Andric# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) 1214bdd1243dSDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 12150b57cec5SDimitry Andric# else 12160b57cec5SDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) 12170b57cec5SDimitry Andric# endif 12180b57cec5SDimitry Andric 12190b57cec5SDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon 122081ad6265SDimitry Andric# if __has_cpp_attribute(fallthrough) 12210b57cec5SDimitry Andric# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 1222349cc55cSDimitry Andric# elif __has_attribute(__fallthrough__) 12230b57cec5SDimitry Andric# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 12240b57cec5SDimitry Andric# else 12250b57cec5SDimitry Andric# define _LIBCPP_FALLTHROUGH() ((void)0) 12260b57cec5SDimitry Andric# endif 12270b57cec5SDimitry Andric 1228bdd1243dSDimitry Andric# if __has_cpp_attribute(_Clang::__lifetimebound__) 1229bdd1243dSDimitry Andric# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 1230bdd1243dSDimitry Andric# else 1231bdd1243dSDimitry Andric# define _LIBCPP_LIFETIMEBOUND 1232bdd1243dSDimitry Andric# endif 1233bdd1243dSDimitry Andric 12340b57cec5SDimitry Andric# if __has_attribute(__nodebug__) 12350b57cec5SDimitry Andric# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 12360b57cec5SDimitry Andric# else 12370b57cec5SDimitry Andric# define _LIBCPP_NODEBUG 12380b57cec5SDimitry Andric# endif 12390b57cec5SDimitry Andric 1240fe6060f1SDimitry Andric# if __has_attribute(__standalone_debug__) 1241fe6060f1SDimitry Andric# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1242fe6060f1SDimitry Andric# else 1243fe6060f1SDimitry Andric# define _LIBCPP_STANDALONE_DEBUG 1244fe6060f1SDimitry Andric# endif 12450b57cec5SDimitry Andric 1246e8d8bef9SDimitry Andric# if __has_attribute(__preferred_name__) 1247e8d8bef9SDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1248e8d8bef9SDimitry Andric# else 1249e8d8bef9SDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) 1250e8d8bef9SDimitry Andric# endif 1251e8d8bef9SDimitry Andric 1252*06c3fb27SDimitry Andric# if __has_attribute(__no_sanitize__) 1253*06c3fb27SDimitry Andric# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) 1254*06c3fb27SDimitry Andric# else 1255*06c3fb27SDimitry Andric# define _LIBCPP_NO_SANITIZE(...) 1256*06c3fb27SDimitry Andric# endif 1257*06c3fb27SDimitry Andric 1258349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library. 1259349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of 1260349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger 1261349cc55cSDimitry Andric// impact on readability. 1262349cc55cSDimitry Andric# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1263349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1264349cc55cSDimitry Andric# else 1265349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1266349cc55cSDimitry Andric# endif 1267349cc55cSDimitry Andric 1268bdd1243dSDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 12690b57cec5SDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 12700b57cec5SDimitry Andric# else 12710b57cec5SDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES 12720b57cec5SDimitry Andric# endif 12730b57cec5SDimitry Andric 12740b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) 12750b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR 12760b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS 1277fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE 1278fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 127981ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION 12800b57cec5SDimitry Andric# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 12810b57cec5SDimitry Andric 1282fe6060f1SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) 1283fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS 128481ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION 1285fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS 1286fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS 1287fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR 1288fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS 1289fe6060f1SDimitry Andric# endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES 1290fe6060f1SDimitry Andric 1291*06c3fb27SDimitry Andric// clang-format off 1292*06c3fb27SDimitry 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()\")") 1293*06c3fb27SDimitry 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()\")") 1294*06c3fb27SDimitry Andric// clang-format on 12950b57cec5SDimitry Andric 12960b57cec5SDimitry Andric# ifndef _LIBCPP_NO_AUTO_LINK 12970b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1298fe6060f1SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 12990b57cec5SDimitry Andric# pragma comment(lib, "c++.lib") 13000b57cec5SDimitry Andric# else 13010b57cec5SDimitry Andric# pragma comment(lib, "libc++.lib") 13020b57cec5SDimitry Andric# endif 13030b57cec5SDimitry Andric# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 13040b57cec5SDimitry Andric# endif // _LIBCPP_NO_AUTO_LINK 13050b57cec5SDimitry Andric 1306e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will 1307e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen. 1308e40139ffSDimitry Andric// 1309e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1310e40139ffSDimitry Andric// do. 1311e40139ffSDimitry Andric# if defined(__BIONIC__) 1312e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1313e40139ffSDimitry Andric# else 1314e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE 1315e40139ffSDimitry Andric# endif 1316e40139ffSDimitry Andric 13175ffd83dbSDimitry Andric// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set 13185ffd83dbSDimitry Andric// of functions used in cstdio may not be available for low API levels when 13195ffd83dbSDimitry Andric// using 64-bit file offsets on LP32. 13205ffd83dbSDimitry Andric# if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24 13215ffd83dbSDimitry Andric# define _LIBCPP_HAS_NO_FGETPOS_FSETPOS 13225ffd83dbSDimitry Andric# endif 13235ffd83dbSDimitry Andric 1324bdd1243dSDimitry Andric# if __has_attribute(__init_priority__) 1325bdd1243dSDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 1326349cc55cSDimitry Andric# else 1327e8d8bef9SDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX 1328e8d8bef9SDimitry Andric# endif 1329e8d8bef9SDimitry Andric 1330bdd1243dSDimitry Andric# if __has_attribute(__format__) 13314824e7fdSDimitry Andric// The attribute uses 1-based indices for ordinary and static member functions. 13324824e7fdSDimitry Andric// The attribute uses 2-based indices for non-static member functions. 13334824e7fdSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 13344824e7fdSDimitry Andric __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1335fe6060f1SDimitry Andric# else 13364824e7fdSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1337fe6060f1SDimitry Andric# endif 1338fe6060f1SDimitry Andric 133981ad6265SDimitry Andric# if __has_cpp_attribute(msvc::no_unique_address) 134081ad6265SDimitry Andric// MSVC implements [[no_unique_address]] as a silent no-op currently. 134181ad6265SDimitry Andric// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 134281ad6265SDimitry Andric// However, MSVC implements [[msvc::no_unique_address]] which does what 134381ad6265SDimitry Andric// [[no_unique_address]] is supposed to do, in general. 134481ad6265SDimitry Andric 134581ad6265SDimitry Andric// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 134681ad6265SDimitry Andric// [[msvc::no_unique_address]] though. If/when it does implement 134781ad6265SDimitry Andric// [[msvc::no_unique_address]], this should be preferred though. 134881ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 134981ad6265SDimitry Andric# elif __has_cpp_attribute(no_unique_address) 1350*06c3fb27SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] 135181ad6265SDimitry Andric# else 135281ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 135381ad6265SDimitry Andric// Note that this can be replaced by #error as soon as clang-cl 135481ad6265SDimitry Andric// implements msvc::no_unique_address, since there should be no C++20 135581ad6265SDimitry Andric// compiler that doesn't support one of the two attributes at that point. 135681ad6265SDimitry Andric// We generally don't want to use this macro outside of C++20-only code, 135781ad6265SDimitry Andric// because using it conditionally in one language version only would make 135881ad6265SDimitry Andric// the ABI inconsistent. 135981ad6265SDimitry Andric# endif 136081ad6265SDimitry Andric 136181ad6265SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 136281ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 136381ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 136481ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 136581ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 136681ad6265SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 136781ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 136881ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 136981ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 137081ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 137181ad6265SDimitry Andric# else 137281ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH 137381ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP 137481ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 137581ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 137681ad6265SDimitry Andric# endif 137781ad6265SDimitry Andric 137881ad6265SDimitry Andric# if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC) 137981ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)") 138081ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)") 138181ad6265SDimitry Andric# else 138281ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */ 138381ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */ 138481ad6265SDimitry Andric# endif 138581ad6265SDimitry Andric 138681ad6265SDimitry Andric# if __has_attribute(__packed__) 138781ad6265SDimitry Andric# define _LIBCPP_PACKED __attribute__((__packed__)) 138881ad6265SDimitry Andric# else 138981ad6265SDimitry Andric# define _LIBCPP_PACKED 139081ad6265SDimitry Andric# endif 139181ad6265SDimitry Andric 1392bdd1243dSDimitry Andric// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1393bdd1243dSDimitry Andric// functions is gradually being added to existing C libraries. The conditions 1394bdd1243dSDimitry Andric// below check for known C library versions and conditions under which these 1395bdd1243dSDimitry Andric// functions are declared by the C library. 1396bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1397bdd1243dSDimitry Andric// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 13981ac55f4cSDimitry Andric// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 13991ac55f4cSDimitry Andric// the latter depends on internal GNU libc details that are not appropriate 14001ac55f4cSDimitry Andric// to depend on here, so any declarations present when __cpp_char8_t is not 14011ac55f4cSDimitry Andric// defined are ignored. 14021ac55f4cSDimitry Andric# if defined(_LIBCPP_GLIBC_PREREQ) 14031ac55f4cSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1404bdd1243dSDimitry Andric# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1405bdd1243dSDimitry Andric# endif 1406bdd1243dSDimitry Andric# endif 1407bdd1243dSDimitry Andric 1408bdd1243dSDimitry Andric// There are a handful of public standard library types that are intended to 1409bdd1243dSDimitry Andric// support CTAD but don't need any explicit deduction guides to do so. This 1410bdd1243dSDimitry Andric// macro is used to mark them as such, which suppresses the 1411bdd1243dSDimitry Andric// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1412bdd1243dSDimitry Andric// with these classes. 1413bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 17 1414*06c3fb27SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 1415bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1416bdd1243dSDimitry Andric template <class... _Tag> \ 1417*06c3fb27SDimitry Andric [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> 1418*06c3fb27SDimitry Andric# else 1419*06c3fb27SDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ 1420*06c3fb27SDimitry Andric template <class... _Tag> \ 1421*06c3fb27SDimitry Andric ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> 1422*06c3fb27SDimitry Andric# endif 1423bdd1243dSDimitry Andric# else 1424bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1425bdd1243dSDimitry Andric# endif 1426bdd1243dSDimitry Andric 14271ac55f4cSDimitry Andric// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 14281ac55f4cSDimitry Andric// compiler intrinsics in the Objective-C++ mode. 14291ac55f4cSDimitry Andric# ifdef __OBJC__ 14301ac55f4cSDimitry Andric# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 14311ac55f4cSDimitry Andric# endif 14321ac55f4cSDimitry Andric 1433*06c3fb27SDimitry Andric# define _PSTL_PRAGMA(x) _Pragma(#x) 1434*06c3fb27SDimitry Andric 1435*06c3fb27SDimitry Andric// Enable SIMD for compilers that support OpenMP 4.0 1436*06c3fb27SDimitry Andric# if (defined(_OPENMP) && _OPENMP >= 201307) 1437*06c3fb27SDimitry Andric 1438*06c3fb27SDimitry Andric# define _PSTL_UDR_PRESENT 1439*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) 1440*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) 1441*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) 1442*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) 1443*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) 1444*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) 1445*06c3fb27SDimitry Andric 1446*06c3fb27SDimitry Andric// Declaration of reduction functor, where 1447*06c3fb27SDimitry Andric// NAME - the name of the functor 1448*06c3fb27SDimitry Andric// OP - type of the callable object with the reduction operation 1449*06c3fb27SDimitry Andric// omp_in - refers to the local partial result 1450*06c3fb27SDimitry Andric// omp_out - refers to the final value of the combiner operator 1451*06c3fb27SDimitry Andric// omp_priv - refers to the private copy of the initial value 1452*06c3fb27SDimitry Andric// omp_orig - refers to the original variable to be reduced 1453*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ 1454*06c3fb27SDimitry Andric _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) 1455*06c3fb27SDimitry Andric 1456*06c3fb27SDimitry Andric# else // (defined(_OPENMP) && _OPENMP >= 201307) 1457*06c3fb27SDimitry Andric 1458*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD 1459*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD 1460*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) 1461*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) 1462*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 1463*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 1464*06c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 1465*06c3fb27SDimitry Andric 1466*06c3fb27SDimitry Andric# endif // (defined(_OPENMP) && _OPENMP >= 201307) 1467*06c3fb27SDimitry Andric 1468*06c3fb27SDimitry Andric# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED 1469*06c3fb27SDimitry Andric 14700b57cec5SDimitry Andric#endif // __cplusplus 14710b57cec5SDimitry Andric 147281ad6265SDimitry Andric#endif // _LIBCPP___CONFIG 1473