1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5// See https://llvm.org/LICENSE.txt for license information. 6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef _LIBCPP___CONFIG 11#define _LIBCPP___CONFIG 12 13#include <__config_site> 14 15#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 16# pragma GCC system_header 17#endif 18 19#if defined(__apple_build_version__) 20// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) 21# define _LIBCPP_COMPILER_CLANG_BASED 22# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) 23#elif defined(__clang__) 24# define _LIBCPP_COMPILER_CLANG_BASED 25# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) 26#elif defined(__GNUC__) 27# define _LIBCPP_COMPILER_GCC 28# define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__) 29#endif 30 31#ifdef __cplusplus 32 33// Warn if a compiler version is used that is not supported anymore 34// LLVM RELEASE Update the minimum compiler versions 35#if defined(_LIBCPP_ENABLE_COMPILER_VERSION_CHECKS) // FreeBSD customization 36# if defined(_LIBCPP_CLANG_VER) 37# if _LIBCPP_CLANG_VER < 1600 38# warning "Libc++ only supports Clang 16 and later" 39# endif 40# elif defined(_LIBCPP_APPLE_CLANG_VER) 41# if _LIBCPP_APPLE_CLANG_VER < 1500 42# warning "Libc++ only supports AppleClang 15 and later" 43# endif 44# elif defined(_LIBCPP_GCC_VER) 45# if _LIBCPP_GCC_VER < 1300 46# warning "Libc++ only supports GCC 13 and later" 47# endif 48# endif 49#endif // _LIBCPP_ENABLE_COMPILER_VERSION_CHECKS 50 51// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html 52 53// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 54// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is 55// defined to XXYYZZ. 56# define _LIBCPP_VERSION 180000 57 58# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 59# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 60 61# if __STDC_HOSTED__ == 0 62# define _LIBCPP_FREESTANDING 63# endif 64 65// NOLINTBEGIN(libcpp-cpp-version-check) 66# ifndef _LIBCPP_STD_VER 67# if __cplusplus <= 201103L 68# define _LIBCPP_STD_VER 11 69# elif __cplusplus <= 201402L 70# define _LIBCPP_STD_VER 14 71# elif __cplusplus <= 201703L 72# define _LIBCPP_STD_VER 17 73# elif __cplusplus <= 202002L 74# define _LIBCPP_STD_VER 20 75# elif __cplusplus <= 202302L 76# define _LIBCPP_STD_VER 23 77# else 78// Expected release year of the next C++ standard 79# define _LIBCPP_STD_VER 26 80# endif 81# endif // _LIBCPP_STD_VER 82// NOLINTEND(libcpp-cpp-version-check) 83 84# if defined(__ELF__) 85# define _LIBCPP_OBJECT_FORMAT_ELF 1 86# elif defined(__MACH__) 87# define _LIBCPP_OBJECT_FORMAT_MACHO 1 88# elif defined(_WIN32) 89# define _LIBCPP_OBJECT_FORMAT_COFF 1 90# elif defined(__wasm__) 91# define _LIBCPP_OBJECT_FORMAT_WASM 1 92# elif defined(_AIX) 93# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 94# else 95// ... add new file formats here ... 96# endif 97 98// ABI { 99 100# if _LIBCPP_ABI_VERSION >= 2 101// Change short string representation so that string data starts at offset 0, 102// improving its alignment in some cases. 103# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 104// Fix deque iterator type in order to support incomplete types. 105# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 106// Fix undefined behavior in how std::list stores its linked nodes. 107# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB 108// Fix undefined behavior in how __tree stores its end and parent nodes. 109# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB 110// Fix undefined behavior in how __hash_table stores its pointer types. 111# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB 112# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB 113# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 114// Define a key function for `bad_function_call` in the library, to centralize 115// its vtable and typeinfo to libc++ rather than having all other libraries 116// using that class define their own copies. 117# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 118// Override the default return value of exception::what() for 119// bad_function_call::what() with a string that is specific to 120// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break 121// because it changes the vtable layout of bad_function_call. 122# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE 123// Enable optimized version of __do_get_(un)signed which avoids redundant copies. 124# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET 125// Give reverse_iterator<T> one data member of type T, not two. 126// Also, in C++17 and later, don't derive iterator types from std::iterator. 127# define _LIBCPP_ABI_NO_ITERATOR_BASES 128// Use the smallest possible integer type to represent the index of the variant. 129// Previously libc++ used "unsigned int" exclusively. 130# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION 131// Unstable attempt to provide a more optimized std::function 132# define _LIBCPP_ABI_OPTIMIZED_FUNCTION 133// All the regex constants must be distinct and nonzero. 134# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO 135// Re-worked external template instantiations for std::string with a focus on 136// performance and fast-path inlining. 137# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 138// Enable clang::trivial_abi on std::unique_ptr. 139# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI 140// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr 141# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI 142// std::random_device holds some state when it uses an implementation that gets 143// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this 144// implementation to another one on a platform that has already shipped 145// std::random_device, one needs to retain the same object layout to remain ABI 146// compatible. This switch removes these workarounds for platforms that don't care 147// about ABI compatibility. 148# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT 149// Don't export the legacy __basic_string_common class and its methods from the built library. 150# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON 151// Don't export the legacy __vector_base_common class and its methods from the built library. 152# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON 153// According to the Standard, `bitset::operator[] const` returns bool 154# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 155// Fix the implementation of CityHash used for std::hash<fundamental-type>. 156// This is an ABI break because `std::hash` will return a different result, 157// which means that hashing the same object in translation units built against 158// different versions of libc++ can return inconsistent results. This is especially 159// tricky since std::hash is used in the implementation of unordered containers. 160// 161// The incorrect implementation of CityHash has the problem that it drops some 162// bits on the floor. 163# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION 164// Remove the base 10 implementation of std::to_chars from the dylib. 165// The implementation moved to the header, but we still export the symbols from 166// the dylib for backwards compatibility. 167# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 168// Save memory by providing the allocator more freedom to allocate the most 169// efficient size class by dropping the alignment requirements for std::string's 170// pointer from 16 to 8. This changes the output of std::string::max_size, 171// which makes it ABI breaking 172# define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT 173# elif _LIBCPP_ABI_VERSION == 1 174# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) 175// Enable compiling copies of now inline methods into the dylib to support 176// applications compiled against older libraries. This is unnecessary with 177// COFF dllexport semantics, since dllexport forces a non-inline definition 178// of inline functions to be emitted anyway. Our own non-inline copy would 179// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, 180// the linker will take issue with the symbols in the shared object if the 181// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), 182// so disable it. 183# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS 184# endif 185// Feature macros for disabling pre ABI v1 features. All of these options 186// are deprecated. 187# if defined(__FreeBSD__) && __FreeBSD__ < 14 188# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 189# endif 190// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol 191// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def 192// in the library, so we need to always rely on the library version. 193# if defined(_AIX) 194# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 195# endif 196# endif 197 198# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 199// Define a key function for `bad_function_call` in the library, to centralize 200// its vtable and typeinfo to libc++ rather than having all other libraries 201// using that class define their own copies. 202# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 203# endif 204 205// We had some bugs where we use [[no_unique_address]] together with construct_at, 206// which causes UB as the call on construct_at could write to overlapping subobjects 207// 208// https://github.com/llvm/llvm-project/issues/70506 209// https://github.com/llvm/llvm-project/issues/70494 210// 211// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions. 212// The below macro is used for all classes whose ABI have changed as part of fixing these bugs. 213# define _LIBCPP_ABI_2023_OVERLAPPING_SUBOBJECT_FIX_TAG __attribute__((__abi_tag__("subobj_fix_2023"))) 214 215// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's 216// within the bounds of the original container and asserts it on every dereference. 217// 218// ABI impact: changes the iterator type of the relevant containers. 219// 220// Supported containers: 221// - `span`; 222// - `string_view`; 223// - `array`. 224// #define _LIBCPP_ABI_BOUNDED_ITERATORS 225 226// } ABI 227 228// HARDENING { 229 230// TODO(hardening): deprecate this in LLVM 19. 231// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) 232// equivalent to setting the extensive mode. 233# ifdef _LIBCPP_ENABLE_ASSERTIONS 234# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 235# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" 236# endif 237# if _LIBCPP_ENABLE_ASSERTIONS 238# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE 239# endif 240# endif 241 242// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: 243// 244// - `_LIBCPP_HARDENING_MODE_NONE`; 245// - `_LIBCPP_HARDENING_MODE_FAST`; 246// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; 247// - `_LIBCPP_HARDENING_MODE_DEBUG`. 248// 249// These values have the following effects: 250// 251// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; 252// 253// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks 254// that can be done with relatively little runtime overhead in constant time; 255// 256// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of 257// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors 258// but are not necessarily security-critical; 259// 260// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive 261// mode and enables all checks available in the library, including internal assertions. Checks that are part of the 262// debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. 263 264// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These 265// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. 266// 267// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and 268// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: 269// - the sentinel is reachable from the begin iterator; 270// - TODO(hardening): both iterators refer to the same container. 271// 272// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through 273// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access 274// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like 275// `optional` and `function` are considered one-element containers for the purposes of this check. 276// 277// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero 278// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the 279// memory security of a program (however, it is still undefined behavior that can result in strange errors due to 280// compiler optimizations). 281// 282// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the 283// given ranges do not overlap. 284// 285// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure 286// the containers have compatible allocators. 287// 288// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to 289// be benign in our implementation. 290// 291// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on 292// user input. 293// 294// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. 295 296// clang-format off 297# define _LIBCPP_HARDENING_MODE_NONE (1 << 1) 298# define _LIBCPP_HARDENING_MODE_FAST (1 << 2) 299# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. 300# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) 301// clang-format on 302 303# ifndef _LIBCPP_HARDENING_MODE 304# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT 305# endif 306 307# if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \ 308 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ 309 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ 310 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG 311# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ 312_LIBCPP_HARDENING_MODE_NONE, \ 313_LIBCPP_HARDENING_MODE_FAST, \ 314_LIBCPP_HARDENING_MODE_EXTENSIVE, \ 315_LIBCPP_HARDENING_MODE_DEBUG 316# endif 317 318// clang-format off 319// Fast hardening mode checks. 320 321# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 322 323// Enabled checks. 324# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 325# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 326// Disabled checks. 327// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access. 328# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) 329// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security 330// vulnerability. 331# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 332# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 333# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression) 334# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 335# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 336 337// Extensive hardening mode checks. 338 339# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 340 341// Enabled checks. 342# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 343# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 344# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) 345# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 346# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 347# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 348# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message) 349// Disabled checks. 350# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 351 352// Debug hardening mode checks. 353 354# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 355 356// All checks enabled. 357# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 358# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 359# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) 360# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 361# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 362# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message) 363# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) 364# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 365 366// Disable all checks if hardening is not enabled. 367 368# else 369 370// All checks disabled. 371# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression) 372# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression) 373# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) 374# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 375# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 376# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression) 377# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 378# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 379 380# endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 381// clang-format on 382 383// } HARDENING 384 385# define _LIBCPP_TOSTRING2(x) #x 386# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 387 388// NOLINTNEXTLINE(libcpp-cpp-version-check) 389# if __cplusplus < 201103L 390# define _LIBCPP_CXX03_LANG 391# endif 392 393# ifndef __has_attribute 394# define __has_attribute(__x) 0 395# endif 396 397# ifndef __has_builtin 398# define __has_builtin(__x) 0 399# endif 400 401# ifndef __has_extension 402# define __has_extension(__x) 0 403# endif 404 405# ifndef __has_feature 406# define __has_feature(__x) 0 407# endif 408 409# ifndef __has_cpp_attribute 410# define __has_cpp_attribute(__x) 0 411# endif 412 413# ifndef __has_constexpr_builtin 414# define __has_constexpr_builtin(x) 0 415# endif 416 417// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 418// the compiler and '1' otherwise. 419# ifndef __is_identifier 420# define __is_identifier(__x) 1 421# endif 422 423# ifndef __has_declspec_attribute 424# define __has_declspec_attribute(__x) 0 425# endif 426 427# define __has_keyword(__x) !(__is_identifier(__x)) 428 429# ifndef __has_include 430# define __has_include(...) 0 431# endif 432 433# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 434# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 435# endif 436 437// FIXME: ABI detection should be done via compiler builtin macros. This 438// is just a placeholder until Clang implements such macros. For now assume 439// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, 440// and allow the user to explicitly specify the ABI to handle cases where this 441// heuristic falls short. 442# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) 443# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" 444# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) 445# define _LIBCPP_ABI_ITANIUM 446# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) 447# define _LIBCPP_ABI_MICROSOFT 448# else 449# if defined(_WIN32) && defined(_MSC_VER) 450# define _LIBCPP_ABI_MICROSOFT 451# else 452# define _LIBCPP_ABI_ITANIUM 453# endif 454# endif 455 456# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 457# define _LIBCPP_ABI_VCRUNTIME 458# endif 459 460# if __has_feature(experimental_library) 461# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 462# define _LIBCPP_ENABLE_EXPERIMENTAL 463# endif 464# endif 465 466// Incomplete features get their own specific disabling flags. This makes it 467// easier to grep for target specific flags once the feature is complete. 468# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 469# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL 470# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN 471# define _LIBCPP_HAS_NO_INCOMPLETE_TZDB 472# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM 473# endif 474 475// Need to detect which libc we're using if we're on Linux. 476# if defined(__linux__) 477# include <features.h> 478# if defined(__GLIBC_PREREQ) 479# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) 480# else 481# define _LIBCPP_GLIBC_PREREQ(a, b) 0 482# endif // defined(__GLIBC_PREREQ) 483# endif // defined(__linux__) 484 485# if defined(__MVS__) 486# include <features.h> // for __NATIVE_ASCII_F 487# endif 488 489# ifndef __BYTE_ORDER__ 490# error \ 491 "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform" 492# endif 493 494# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 495# define _LIBCPP_LITTLE_ENDIAN 496# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 497# define _LIBCPP_BIG_ENDIAN 498# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 499 500# if defined(_WIN32) 501# define _LIBCPP_WIN32API 502# define _LIBCPP_SHORT_WCHAR 1 503// Both MinGW and native MSVC provide a "MSVC"-like environment 504# define _LIBCPP_MSVCRT_LIKE 505// If mingw not explicitly detected, assume using MS C runtime only if 506// a MS compatibility version is specified. 507# if defined(_MSC_VER) && !defined(__MINGW32__) 508# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 509# endif 510# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 511# define _LIBCPP_HAS_BITSCAN64 512# endif 513# define _LIBCPP_HAS_OPEN_WITH_WCHAR 514# endif // defined(_WIN32) 515 516# if defined(_AIX) && !defined(__64BIT__) 517// The size of wchar is 2 byte on 32-bit mode on AIX. 518# define _LIBCPP_SHORT_WCHAR 1 519# endif 520 521// Libc++ supports various implementations of std::random_device. 522// 523// _LIBCPP_USING_DEV_RANDOM 524// Read entropy from the given file, by default `/dev/urandom`. 525// If a token is provided, it is assumed to be the path to a file 526// to read entropy from. This is the default behavior if nothing 527// else is specified. This implementation requires storing state 528// inside `std::random_device`. 529// 530// _LIBCPP_USING_ARC4_RANDOM 531// Use arc4random(). This allows obtaining random data even when 532// using sandboxing mechanisms. On some platforms like Apple, this 533// is the recommended source of entropy for user-space programs. 534// When this option is used, the token passed to `std::random_device`'s 535// constructor *must* be "/dev/urandom" -- anything else is an error. 536// 537// _LIBCPP_USING_GETENTROPY 538// Use getentropy(). 539// When this option is used, the token passed to `std::random_device`'s 540// constructor *must* be "/dev/urandom" -- anything else is an error. 541// 542// _LIBCPP_USING_FUCHSIA_CPRNG 543// Use Fuchsia's zx_cprng_draw() system call, which is specified to 544// deliver high-quality entropy and cannot fail. 545// When this option is used, the token passed to `std::random_device`'s 546// constructor *must* be "/dev/urandom" -- anything else is an error. 547// 548// _LIBCPP_USING_NACL_RANDOM 549// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 550// including accesses to the special files under `/dev`. This implementation 551// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 552// When this option is used, the token passed to `std::random_device`'s 553// constructor *must* be "/dev/urandom" -- anything else is an error. 554// 555// _LIBCPP_USING_WIN32_RANDOM 556// Use rand_s(), for use on Windows. 557// When this option is used, the token passed to `std::random_device`'s 558// constructor *must* be "/dev/urandom" -- anything else is an error. 559# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 560 defined(__DragonFly__) 561# define _LIBCPP_USING_ARC4_RANDOM 562# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 563# define _LIBCPP_USING_GETENTROPY 564# elif defined(__Fuchsia__) 565# define _LIBCPP_USING_FUCHSIA_CPRNG 566# elif defined(__native_client__) 567# define _LIBCPP_USING_NACL_RANDOM 568# elif defined(_LIBCPP_WIN32API) 569# define _LIBCPP_USING_WIN32_RANDOM 570# else 571# define _LIBCPP_USING_DEV_RANDOM 572# endif 573 574# ifndef _LIBCPP_CXX03_LANG 575 576# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 577# define _ALIGNAS_TYPE(x) alignas(x) 578# define _ALIGNAS(x) alignas(x) 579# define _LIBCPP_NORETURN [[noreturn]] 580# define _NOEXCEPT noexcept 581# define _NOEXCEPT_(x) noexcept(x) 582# define _LIBCPP_CONSTEXPR constexpr 583 584# else 585 586# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 587# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 588# define _ALIGNAS(x) __attribute__((__aligned__(x))) 589# define _LIBCPP_NORETURN __attribute__((__noreturn__)) 590# define _LIBCPP_HAS_NO_NOEXCEPT 591# define nullptr __nullptr 592# define _NOEXCEPT throw() 593# define _NOEXCEPT_(x) 594# define static_assert(...) _Static_assert(__VA_ARGS__) 595# define decltype(...) __decltype(__VA_ARGS__) 596# define _LIBCPP_CONSTEXPR 597 598typedef __char16_t char16_t; 599typedef __char32_t char32_t; 600 601# endif 602 603# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L 604# define _LIBCPP_HAS_NO_EXCEPTIONS 605# endif 606 607# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 608 609# if defined(_LIBCPP_COMPILER_CLANG_BASED) 610 611# if defined(__APPLE__) 612# if defined(__i386__) || defined(__x86_64__) 613// use old string layout on x86_64 and i386 614# elif defined(__arm__) 615// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs 616# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 617# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 618# endif 619# else 620# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 621# endif 622# endif 623 624// Objective-C++ features (opt-in) 625# if __has_feature(objc_arc) 626# define _LIBCPP_HAS_OBJC_ARC 627# endif 628 629# if __has_feature(objc_arc_weak) 630# define _LIBCPP_HAS_OBJC_ARC_WEAK 631# endif 632 633# if __has_extension(blocks) 634# define _LIBCPP_HAS_EXTENSION_BLOCKS 635# endif 636 637# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) 638# define _LIBCPP_HAS_BLOCKS_RUNTIME 639# endif 640 641# if !__has_feature(address_sanitizer) 642# define _LIBCPP_HAS_NO_ASAN 643# endif 644 645# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 646 647# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 648 649# elif defined(_LIBCPP_COMPILER_GCC) 650 651# if !defined(__SANITIZE_ADDRESS__) 652# define _LIBCPP_HAS_NO_ASAN 653# endif 654 655# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 656 657# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 658 659# endif // _LIBCPP_COMPILER_[CLANG|GCC] 660 661# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 662 663# ifdef _DLL 664# define _LIBCPP_CRT_FUNC __declspec(dllimport) 665# else 666# define _LIBCPP_CRT_FUNC 667# endif 668 669# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 670# define _LIBCPP_DLL_VIS 671# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 672# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 673# define _LIBCPP_OVERRIDABLE_FUNC_VIS 674# define _LIBCPP_EXPORTED_FROM_ABI 675# elif defined(_LIBCPP_BUILDING_LIBRARY) 676# define _LIBCPP_DLL_VIS __declspec(dllexport) 677# if defined(__MINGW32__) 678# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 679# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 680# else 681# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 682# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 683# endif 684# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 685# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 686# else 687# define _LIBCPP_DLL_VIS __declspec(dllimport) 688# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 689# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 690# define _LIBCPP_OVERRIDABLE_FUNC_VIS 691# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 692# endif 693 694# define _LIBCPP_HIDDEN 695# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 696# define _LIBCPP_TEMPLATE_VIS 697# define _LIBCPP_TEMPLATE_DATA_VIS 698# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 699 700# else 701 702# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 703# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 704# else 705# define _LIBCPP_VISIBILITY(vis) 706# endif 707 708# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 709# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 710# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 711# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 712# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 713 714// TODO: Make this a proper customization point or remove the option to override it. 715# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 716# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 717# endif 718 719# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 720// The inline should be removed once PR32114 is resolved 721# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 722# else 723# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 724# endif 725 726// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates 727# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__) 728# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 729# else 730# define _LIBCPP_TEMPLATE_VIS 731# endif 732 733# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) && \ 734 _LIBCPP_CLANG_VER >= 1500 // FreeBSD customization 735# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default"))) 736# else 737# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 738# endif 739 740# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 741 742# if __has_attribute(exclude_from_explicit_instantiation) 743# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 744# else 745// Try to approximate the effect of exclude_from_explicit_instantiation 746// (which is that entities are not assumed to be provided by explicit 747// template instantiations in the dylib) by always inlining those entities. 748# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 749# endif 750 751# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 752# define _LIBCPP_HARDENING_SIG f 753# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 754# define _LIBCPP_HARDENING_SIG s 755# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 756# define _LIBCPP_HARDENING_SIG d 757# else 758# define _LIBCPP_HARDENING_SIG n // "none" 759# endif 760 761# ifdef _LIBCPP_HAS_NO_EXCEPTIONS 762# define _LIBCPP_EXCEPTIONS_SIG n 763# else 764# define _LIBCPP_EXCEPTIONS_SIG e 765# endif 766 767# define _LIBCPP_ODR_SIGNATURE \ 768 _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) 769 770// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 771// on two levels: 772// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 773// symbols from their dynamic library by means of using the libc++ headers. This ensures 774// that those symbols stay private to the dynamic library in which it is defined. 775// 776// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. 777// This ensures that no ODR violation can arise from mixing two TUs compiled with different 778// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the 779// program contains two definitions of a function, the ODR requires them to be token-by-token 780// equivalent, and the linker is allowed to pick either definition and discard the other one. 781// 782// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled 783// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs 784// compiled with different settings), the two definitions are both visible by the linker and they 785// have the same name, but they have a meaningfully different implementation (one throws an exception 786// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in 787// practice what will happen is that the linker will pick one of the definitions at random and will 788// discard the other one. This can quite clearly lead to incorrect program behavior. 789// 790// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any 791// property that causes the code of a function to differ from the code in another configuration 792// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI 793// tag, but we encode the ones that we think are most important: library version, exceptions, and 794// hardening mode. 795// 796// Note that historically, solving this problem has been achieved in various ways, including 797// force-inlining all functions or giving internal linkage to all functions. Both these previous 798// solutions suffer from drawbacks that lead notably to code bloat. 799// 800// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 801// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 802// 803// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 804// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 805// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 806// the virtual function pointer in the vtable based on the mangled name of the function. Since 807// we use an ABI tag that changes with each released version, the mangled name of the virtual 808// function would change, which is incorrect. Note that it doesn't make much sense to change 809// the implementation of a virtual function in an ABI-incompatible way in the first place, 810// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 811// 812// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 813// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 814// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 815# ifndef _LIBCPP_NO_ABI_TAG 816# define _LIBCPP_HIDE_FROM_ABI \ 817 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 818 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) 819# else 820# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 821# endif 822# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 823 824// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern 825// "C" function, as those lack mangling. 826# define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 827 828# ifdef _LIBCPP_BUILDING_LIBRARY 829# if _LIBCPP_ABI_VERSION > 1 830# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 831# else 832# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 833# endif 834# else 835# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 836# endif 837 838// TODO(LLVM-19): Remove _LIBCPP_INLINE_VISIBILITY and _VSTD, which we're keeping around 839// only to ease the renaming for downstreams. 840# define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI 841# define _VSTD std 842 843// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 844// clang-format off 845# define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \ 846 inline namespace _LIBCPP_ABI_NAMESPACE { 847# define _LIBCPP_END_NAMESPACE_STD }} 848 849# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ 850 inline namespace __fs { namespace filesystem { 851 852# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }} 853// clang-format on 854 855# if __has_attribute(__enable_if__) 856# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 857# endif 858 859# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) 860# define _LIBCPP_HAS_NO_INT128 861# endif 862 863# ifdef _LIBCPP_CXX03_LANG 864# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 865 struct _LIBCPP_EXPORTED_FROM_ABI x { \ 866 enum __lx 867// clang-format off 868# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 869 __lx __v_; \ 870 _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ 871 _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 872 _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ 873 }; 874// clang-format on 875 876# else // _LIBCPP_CXX03_LANG 877# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x 878# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 879# endif // _LIBCPP_CXX03_LANG 880 881# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) 882# define _LIBCPP_LOCALE__L_EXTENSIONS 1 883# endif 884 885# ifdef __FreeBSD__ 886# define _DECLARE_C99_LDBL_MATH 1 887# endif 888 889// If we are getting operator new from the MSVC CRT, then allocation overloads 890// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 891# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 892# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 893# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 894// We're deferring to Microsoft's STL to provide aligned new et al. We don't 895// have it unless the language feature test macro is defined. 896# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 897# elif defined(__MVS__) 898# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 899# endif 900 901# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 902# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 903# endif 904 905// It is not yet possible to use aligned_alloc() on all Apple platforms since 906// 10.15 was the first version to ship an implementation of aligned_alloc(). 907# if defined(__APPLE__) 908# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 909 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) 910# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 911# endif 912# elif defined(__ANDROID__) && __ANDROID_API__ < 28 913// Android only provides aligned_alloc when targeting API 28 or higher. 914# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 915# endif 916 917# if defined(__APPLE__) || defined(__FreeBSD__) 918# define _LIBCPP_HAS_DEFAULTRUNELOCALE 919# endif 920 921# if defined(__APPLE__) || defined(__FreeBSD__) 922# define _LIBCPP_WCTYPE_IS_MASK 923# endif 924 925# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 926# define _LIBCPP_HAS_NO_CHAR8_T 927# endif 928 929// Deprecation macros. 930// 931// Deprecations warnings are always enabled, except when users explicitly opt-out 932// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 933# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 934# if __has_attribute(__deprecated__) 935# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) 936# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) 937# elif _LIBCPP_STD_VER >= 14 938# define _LIBCPP_DEPRECATED [[deprecated]] 939# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 940# else 941# define _LIBCPP_DEPRECATED 942# define _LIBCPP_DEPRECATED_(m) 943# endif 944# else 945# define _LIBCPP_DEPRECATED 946# define _LIBCPP_DEPRECATED_(m) 947# endif 948 949# if !defined(_LIBCPP_CXX03_LANG) 950# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 951# else 952# define _LIBCPP_DEPRECATED_IN_CXX11 953# endif 954 955# if _LIBCPP_STD_VER >= 14 956# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 957# else 958# define _LIBCPP_DEPRECATED_IN_CXX14 959# endif 960 961# if _LIBCPP_STD_VER >= 17 962# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 963# else 964# define _LIBCPP_DEPRECATED_IN_CXX17 965# endif 966 967# if _LIBCPP_STD_VER >= 20 968# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 969# else 970# define _LIBCPP_DEPRECATED_IN_CXX20 971# endif 972 973# if _LIBCPP_STD_VER >= 23 974# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 975# else 976# define _LIBCPP_DEPRECATED_IN_CXX23 977# endif 978 979# if !defined(_LIBCPP_HAS_NO_CHAR8_T) 980# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 981# else 982# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 983# endif 984 985// Macros to enter and leave a state where deprecation warnings are suppressed. 986# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 987# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 988 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 989 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 990# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 991# else 992# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 993# define _LIBCPP_SUPPRESS_DEPRECATED_POP 994# endif 995 996# if _LIBCPP_STD_VER <= 11 997# define _LIBCPP_EXPLICIT_SINCE_CXX14 998# else 999# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit 1000# endif 1001 1002# if _LIBCPP_STD_VER >= 23 1003# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit 1004# else 1005# define _LIBCPP_EXPLICIT_SINCE_CXX23 1006# endif 1007 1008# if _LIBCPP_STD_VER >= 14 1009# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 1010# else 1011# define _LIBCPP_CONSTEXPR_SINCE_CXX14 1012# endif 1013 1014# if _LIBCPP_STD_VER >= 17 1015# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 1016# else 1017# define _LIBCPP_CONSTEXPR_SINCE_CXX17 1018# endif 1019 1020# if _LIBCPP_STD_VER >= 20 1021# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 1022# else 1023# define _LIBCPP_CONSTEXPR_SINCE_CXX20 1024# endif 1025 1026# if _LIBCPP_STD_VER >= 23 1027# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 1028# else 1029# define _LIBCPP_CONSTEXPR_SINCE_CXX23 1030# endif 1031 1032# ifndef _LIBCPP_HAS_NO_ASAN 1033extern "C" _LIBCPP_EXPORTED_FROM_ABI void 1034__sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); 1035extern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container( 1036 const void*, const void*, const void*, const void*, const void*, const void*); 1037extern "C" _LIBCPP_EXPORTED_FROM_ABI int 1038__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*); 1039# endif 1040 1041// Try to find out if RTTI is disabled. 1042# if !defined(__cpp_rtti) || __cpp_rtti < 199711L 1043# define _LIBCPP_HAS_NO_RTTI 1044# endif 1045 1046# ifndef _LIBCPP_WEAK 1047# define _LIBCPP_WEAK __attribute__((__weak__)) 1048# endif 1049 1050// Thread API 1051// clang-format off 1052# if !defined(_LIBCPP_HAS_NO_THREADS) && \ 1053 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 1054 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 1055 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 1056 1057# if defined(__FreeBSD__) || \ 1058 defined(__wasi__) || \ 1059 defined(__NetBSD__) || \ 1060 defined(__OpenBSD__) || \ 1061 defined(__NuttX__) || \ 1062 defined(__linux__) || \ 1063 defined(__GNU__) || \ 1064 defined(__APPLE__) || \ 1065 defined(__MVS__) || \ 1066 defined(_AIX) || \ 1067 defined(__EMSCRIPTEN__) 1068// clang-format on 1069# define _LIBCPP_HAS_THREAD_API_PTHREAD 1070# elif defined(__Fuchsia__) 1071// TODO(44575): Switch to C11 thread API when possible. 1072# define _LIBCPP_HAS_THREAD_API_PTHREAD 1073# elif defined(_LIBCPP_WIN32API) 1074# define _LIBCPP_HAS_THREAD_API_WIN32 1075# else 1076# error "No thread API" 1077# endif // _LIBCPP_HAS_THREAD_API 1078# endif // _LIBCPP_HAS_NO_THREADS 1079 1080# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1081# if defined(__ANDROID__) && __ANDROID_API__ >= 30 1082# define _LIBCPP_HAS_COND_CLOCKWAIT 1083# elif defined(_LIBCPP_GLIBC_PREREQ) 1084# if _LIBCPP_GLIBC_PREREQ(2, 30) 1085# define _LIBCPP_HAS_COND_CLOCKWAIT 1086# endif 1087# endif 1088# endif 1089 1090# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1091# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 1092 _LIBCPP_HAS_NO_THREADS is not defined. 1093# endif 1094 1095# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 1096# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 1097 _LIBCPP_HAS_NO_THREADS is defined. 1098# endif 1099 1100# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 1101# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 1102 _LIBCPP_HAS_NO_THREADS is defined. 1103# endif 1104 1105# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 1106# define __STDCPP_THREADS__ 1 1107# endif 1108 1109// The glibc and Bionic implementation of pthreads implements 1110// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 1111// mutexes have no destroy mechanism. 1112// 1113// This optimization can't be performed on Apple platforms, where 1114// pthread_mutex_destroy can allow the kernel to release resources. 1115// See https://llvm.org/D64298 for details. 1116// 1117// TODO(EricWF): Enable this optimization on Bionic after speaking to their 1118// respective stakeholders. 1119// clang-format off 1120# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ 1121 (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 1122 defined(_LIBCPP_HAS_THREAD_API_WIN32) 1123// clang-format on 1124# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1125# endif 1126 1127// Destroying a condvar is a nop on Windows. 1128// 1129// This optimization can't be performed on Apple platforms, where 1130// pthread_cond_destroy can allow the kernel to release resources. 1131// See https://llvm.org/D64298 for details. 1132// 1133// TODO(EricWF): This is potentially true for some pthread implementations 1134// as well. 1135# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) 1136# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1137# endif 1138 1139# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 1140 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 1141# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 1142# endif 1143 1144# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 1145# define _LIBCPP_HAS_C_ATOMIC_IMP 1146# elif defined(_LIBCPP_COMPILER_GCC) 1147# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1148# endif 1149 1150# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1151 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 1152# define _LIBCPP_HAS_NO_ATOMIC_HEADER 1153# else 1154# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 1155# define _LIBCPP_ATOMIC_FLAG_TYPE bool 1156# endif 1157# ifdef _LIBCPP_FREESTANDING 1158# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS 1159# endif 1160# endif 1161 1162# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) 1163# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) 1164# else 1165# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 1166# endif 1167 1168# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 1169# if defined(__clang__) && __has_attribute(acquire_capability) 1170// Work around the attribute handling in clang. When both __declspec and 1171// __attribute__ are present, the processing goes awry preventing the definition 1172// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 1173// combining the two does work. 1174# if !defined(_MSC_VER) 1175# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1176# endif 1177# endif 1178# endif 1179 1180# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1181# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1182# else 1183# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1184# endif 1185 1186# if _LIBCPP_STD_VER >= 20 1187# define _LIBCPP_CONSTINIT constinit 1188# elif __has_attribute(__require_constant_initialization__) 1189# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 1190# else 1191# define _LIBCPP_CONSTINIT 1192# endif 1193 1194# if __has_attribute(__noinline__) 1195# define _LIBCPP_NOINLINE __attribute__((__noinline__)) 1196# else 1197# define _LIBCPP_NOINLINE 1198# endif 1199 1200// We often repeat things just for handling wide characters in the library. 1201// When wide characters are disabled, it can be useful to have a quick way of 1202// disabling it without having to resort to #if-#endif, which has a larger 1203// impact on readability. 1204# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1205# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1206# else 1207# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1208# endif 1209 1210# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) 1211# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR 1212# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS 1213# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE 1214# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 1215# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION 1216# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 1217 1218# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) 1219# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS 1220# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION 1221# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS 1222# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS 1223# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR 1224# define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS 1225# endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES 1226 1227// clang-format off 1228# 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()\")") 1229# 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()\")") 1230// clang-format on 1231 1232# ifndef _LIBCPP_NO_AUTO_LINK 1233# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1234# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 1235# pragma comment(lib, "c++.lib") 1236# else 1237# pragma comment(lib, "libc++.lib") 1238# endif 1239# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1240# endif // _LIBCPP_NO_AUTO_LINK 1241 1242// Configures the fopen close-on-exec mode character, if any. This string will 1243// be appended to any mode string used by fstream for fopen/fdopen. 1244// 1245// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1246// do. 1247# if defined(__BIONIC__) 1248# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1249# else 1250# define _LIBCPP_FOPEN_CLOEXEC_MODE 1251# endif 1252 1253# if __has_cpp_attribute(msvc::no_unique_address) 1254// MSVC implements [[no_unique_address]] as a silent no-op currently. 1255// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 1256// However, MSVC implements [[msvc::no_unique_address]] which does what 1257// [[no_unique_address]] is supposed to do, in general. 1258 1259// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 1260// [[msvc::no_unique_address]] though. If/when it does implement 1261// [[msvc::no_unique_address]], this should be preferred though. 1262# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 1263# elif __has_cpp_attribute(no_unique_address) 1264# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] 1265# else 1266# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 1267// Note that this can be replaced by #error as soon as clang-cl 1268// implements msvc::no_unique_address, since there should be no C++20 1269// compiler that doesn't support one of the two attributes at that point. 1270// We generally don't want to use this macro outside of C++20-only code, 1271// because using it conditionally in one language version only would make 1272// the ABI inconsistent. 1273# endif 1274 1275# ifdef _LIBCPP_COMPILER_CLANG_BASED 1276# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 1277# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 1278# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 1279# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 1280# elif defined(_LIBCPP_COMPILER_GCC) 1281# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 1282# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 1283# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 1284# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 1285# else 1286# define _LIBCPP_DIAGNOSTIC_PUSH 1287# define _LIBCPP_DIAGNOSTIC_POP 1288# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 1289# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 1290# endif 1291 1292// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1293// functions is gradually being added to existing C libraries. The conditions 1294// below check for known C library versions and conditions under which these 1295// functions are declared by the C library. 1296# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1297// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 1298// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 1299// the latter depends on internal GNU libc details that are not appropriate 1300// to depend on here, so any declarations present when __cpp_char8_t is not 1301// defined are ignored. 1302# if defined(_LIBCPP_GLIBC_PREREQ) 1303# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1304# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1305# endif 1306# endif 1307 1308// There are a handful of public standard library types that are intended to 1309// support CTAD but don't need any explicit deduction guides to do so. This 1310// macro is used to mark them as such, which suppresses the 1311// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1312// with these classes. 1313# if _LIBCPP_STD_VER >= 17 1314# ifdef _LIBCPP_COMPILER_CLANG_BASED 1315# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1316 template <class... _Tag> \ 1317 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> 1318# else 1319# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ 1320 template <class... _Tag> \ 1321 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> 1322# endif 1323# else 1324# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1325# endif 1326 1327// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 1328// compiler intrinsics in the Objective-C++ mode. 1329# ifdef __OBJC__ 1330# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 1331# endif 1332 1333# define _PSTL_PRAGMA(x) _Pragma(#x) 1334 1335// Enable SIMD for compilers that support OpenMP 4.0 1336# if (defined(_OPENMP) && _OPENMP >= 201307) 1337 1338# define _PSTL_UDR_PRESENT 1339# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) 1340# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) 1341# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) 1342# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) 1343# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) 1344# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) 1345 1346// Declaration of reduction functor, where 1347// NAME - the name of the functor 1348// OP - type of the callable object with the reduction operation 1349// omp_in - refers to the local partial result 1350// omp_out - refers to the final value of the combiner operator 1351// omp_priv - refers to the private copy of the initial value 1352// omp_orig - refers to the original variable to be reduced 1353# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ 1354 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) 1355 1356# elif defined(_LIBCPP_COMPILER_CLANG_BASED) 1357 1358# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") 1359# define _PSTL_PRAGMA_DECLARE_SIMD 1360# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 1361# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 1362# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 1363# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 1364# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 1365 1366# else // (defined(_OPENMP) && _OPENMP >= 201307) 1367 1368# define _PSTL_PRAGMA_SIMD 1369# define _PSTL_PRAGMA_DECLARE_SIMD 1370# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) 1371# define _PSTL_PRAGMA_SIMD_SCAN(PRM) 1372# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 1373# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 1374# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 1375 1376# endif // (defined(_OPENMP) && _OPENMP >= 201307) 1377 1378# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED 1379 1380// Optional attributes - these are useful for a better QoI, but not required to be available 1381 1382# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 1383# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 1384# else 1385# define _LIBCPP_NO_CFI 1386# endif 1387 1388# if __has_attribute(__malloc__) 1389# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 1390# else 1391# define _LIBCPP_NOALIAS 1392# endif 1393 1394# if __has_attribute(__using_if_exists__) 1395# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 1396# else 1397# define _LIBCPP_USING_IF_EXISTS 1398# endif 1399 1400# if __has_cpp_attribute(nodiscard) 1401# define _LIBCPP_NODISCARD [[__nodiscard__]] 1402# else 1403// We can't use GCC's [[gnu::warn_unused_result]] and 1404// __attribute__((warn_unused_result)), because GCC does not silence them via 1405// (void) cast. 1406# define _LIBCPP_NODISCARD 1407# endif 1408 1409// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not 1410// specified as such as an extension. 1411# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 1412# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD 1413# else 1414# define _LIBCPP_NODISCARD_EXT 1415# endif 1416 1417# if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 1418# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD 1419# else 1420# define _LIBCPP_NODISCARD_AFTER_CXX17 1421# endif 1422 1423# if __has_attribute(__no_destroy__) 1424# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 1425# else 1426# define _LIBCPP_NO_DESTROY 1427# endif 1428 1429# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) 1430# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 1431# else 1432# define _LIBCPP_DIAGNOSE_WARNING(...) 1433# endif 1434 1435// Use a function like macro to imply that it must be followed by a semicolon 1436# if __has_cpp_attribute(fallthrough) 1437# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 1438# elif __has_attribute(__fallthrough__) 1439# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 1440# else 1441# define _LIBCPP_FALLTHROUGH() ((void)0) 1442# endif 1443 1444# if __has_cpp_attribute(_Clang::__lifetimebound__) 1445# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 1446# else 1447# define _LIBCPP_LIFETIMEBOUND 1448# endif 1449 1450# if __has_attribute(__nodebug__) 1451# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 1452# else 1453# define _LIBCPP_NODEBUG 1454# endif 1455 1456# if __has_attribute(__standalone_debug__) 1457# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1458# else 1459# define _LIBCPP_STANDALONE_DEBUG 1460# endif 1461 1462# if __has_attribute(__preferred_name__) 1463# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1464# else 1465# define _LIBCPP_PREFERRED_NAME(x) 1466# endif 1467 1468# if __has_attribute(__no_sanitize__) 1469# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) 1470# else 1471# define _LIBCPP_NO_SANITIZE(...) 1472# endif 1473 1474# if __has_attribute(__init_priority__) 1475# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 1476# else 1477# define _LIBCPP_INIT_PRIORITY_MAX 1478# endif 1479 1480# if __has_attribute(__format__) 1481// The attribute uses 1-based indices for ordinary and static member functions. 1482// The attribute uses 2-based indices for non-static member functions. 1483# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 1484 __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1485# else 1486# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1487# endif 1488 1489# if __has_attribute(__packed__) 1490# define _LIBCPP_PACKED __attribute__((__packed__)) 1491# else 1492# define _LIBCPP_PACKED 1493# endif 1494 1495# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 1496# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 1497# else 1498# define _LIBCPP_DECLSPEC_EMPTY_BASES 1499# endif 1500 1501// Allow for build-time disabling of unsigned integer sanitization 1502# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) 1503# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 1504# else 1505# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1506# endif 1507 1508#endif // __cplusplus 1509 1510#endif // _LIBCPP___CONFIG 1511