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#include <__configuration/abi.h> 15#include <__configuration/availability.h> 16#include <__configuration/compiler.h> 17#include <__configuration/language.h> 18#include <__configuration/platform.h> 19 20#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 21# pragma GCC system_header 22#endif 23 24#ifdef __cplusplus 25 26// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html 27 28// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 29// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is 30// defined to XXYYZZ. 31# define _LIBCPP_VERSION 200000 32 33# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 34# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 35# define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z)) 36 37# if __STDC_HOSTED__ == 0 38# define _LIBCPP_FREESTANDING 39# endif 40 41// HARDENING { 42 43// TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated. 44# ifdef _LIBCPP_ENABLE_ASSERTIONS 45# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead" 46# endif 47 48// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: 49// 50// - `_LIBCPP_HARDENING_MODE_NONE`; 51// - `_LIBCPP_HARDENING_MODE_FAST`; 52// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; 53// - `_LIBCPP_HARDENING_MODE_DEBUG`. 54// 55// These values have the following effects: 56// 57// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; 58// 59// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks 60// that can be done with relatively little runtime overhead in constant time; 61// 62// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of 63// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors 64// but are not necessarily security-critical; 65// 66// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive 67// mode and enables all checks available in the library, including internal assertions. Checks that are part of the 68// debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. 69 70// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These 71// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. 72// 73// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and 74// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: 75// - the sentinel is reachable from the begin iterator; 76// - TODO(hardening): both iterators refer to the same container. 77// 78// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through 79// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access 80// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like 81// `optional` and `function` are considered one-element containers for the purposes of this check. 82// 83// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero 84// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the 85// memory security of a program (however, it is still undefined behavior that can result in strange errors due to 86// compiler optimizations). 87// 88// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the 89// given ranges do not overlap. 90// 91// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object 92// was allocated by the given allocator). Violating this category typically results in a memory leak. 93// 94// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in 95// an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like 96// attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category 97// (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or 98// otherwise create an immediate security issue. 99// 100// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure 101// the containers have compatible allocators. 102// 103// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments 104// for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the 105// original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g. 106// a string view where only a subset of elements is possible to access). This category is for assertions violating 107// which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the 108// user code. 109// 110// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to 111// be benign in our implementation. 112// 113// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed 114// by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied; 115// thus, this would often be a heuristic check and it might be quite expensive. 116// 117// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on 118// user input. 119// 120// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. 121 122// clang-format off 123# define _LIBCPP_HARDENING_MODE_NONE (1 << 1) 124# define _LIBCPP_HARDENING_MODE_FAST (1 << 2) 125# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. 126# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) 127// clang-format on 128 129# ifndef _LIBCPP_HARDENING_MODE 130 131# ifndef _LIBCPP_HARDENING_MODE_DEFAULT 132# error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \ 133`__config_site` header, please make sure your installation of libc++ is not broken. 134# endif 135 136# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT 137# endif 138 139# if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \ 140 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ 141 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ 142 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG 143# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ 144_LIBCPP_HARDENING_MODE_NONE, \ 145_LIBCPP_HARDENING_MODE_FAST, \ 146_LIBCPP_HARDENING_MODE_EXTENSIVE, \ 147_LIBCPP_HARDENING_MODE_DEBUG 148# endif 149 150// } HARDENING 151 152# define _LIBCPP_TOSTRING2(x) #x 153# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 154 155// NOLINTNEXTLINE(libcpp-cpp-version-check) 156# if __cplusplus < 201103L 157# define _LIBCPP_CXX03_LANG 158# endif 159 160# ifndef __has_constexpr_builtin 161# define __has_constexpr_builtin(x) 0 162# endif 163 164// This checks wheter a Clang module is built 165# ifndef __building_module 166# define __building_module(...) 0 167# endif 168 169// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 170// the compiler and '1' otherwise. 171# ifndef __is_identifier 172# define __is_identifier(__x) 1 173# endif 174 175# ifndef __has_declspec_attribute 176# define __has_declspec_attribute(__x) 0 177# endif 178 179# define __has_keyword(__x) !(__is_identifier(__x)) 180 181# ifndef __has_warning 182# define __has_warning(...) 0 183# endif 184 185# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 186# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 187# endif 188 189# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 190# define _LIBCPP_ABI_VCRUNTIME 191# endif 192 193# if __has_feature(experimental_library) 194# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 195# define _LIBCPP_ENABLE_EXPERIMENTAL 196# endif 197# endif 198 199// Incomplete features get their own specific disabling flags. This makes it 200// easier to grep for target specific flags once the feature is complete. 201# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 202# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL 203# define _LIBCPP_HAS_NO_EXPERIMENTAL_TZDB 204# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM 205# endif 206 207# if defined(__MVS__) 208# include <features.h> // for __NATIVE_ASCII_F 209# endif 210 211# if defined(_WIN32) 212# define _LIBCPP_WIN32API 213# define _LIBCPP_SHORT_WCHAR 1 214// Both MinGW and native MSVC provide a "MSVC"-like environment 215# define _LIBCPP_MSVCRT_LIKE 216// If mingw not explicitly detected, assume using MS C runtime only if 217// a MS compatibility version is specified. 218# if defined(_MSC_VER) && !defined(__MINGW32__) 219# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 220# endif 221# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 222# define _LIBCPP_HAS_BITSCAN64 1 223# else 224# define _LIBCPP_HAS_BITSCAN64 0 225# endif 226# define _LIBCPP_HAS_OPEN_WITH_WCHAR 1 227# else 228# define _LIBCPP_HAS_OPEN_WITH_WCHAR 0 229# define _LIBCPP_HAS_BITSCAN64 0 230# endif // defined(_WIN32) 231 232# if defined(_AIX) && !defined(__64BIT__) 233// The size of wchar is 2 byte on 32-bit mode on AIX. 234# define _LIBCPP_SHORT_WCHAR 1 235# endif 236 237// Libc++ supports various implementations of std::random_device. 238// 239// _LIBCPP_USING_DEV_RANDOM 240// Read entropy from the given file, by default `/dev/urandom`. 241// If a token is provided, it is assumed to be the path to a file 242// to read entropy from. This is the default behavior if nothing 243// else is specified. This implementation requires storing state 244// inside `std::random_device`. 245// 246// _LIBCPP_USING_ARC4_RANDOM 247// Use arc4random(). This allows obtaining random data even when 248// using sandboxing mechanisms. On some platforms like Apple, this 249// is the recommended source of entropy for user-space programs. 250// When this option is used, the token passed to `std::random_device`'s 251// constructor *must* be "/dev/urandom" -- anything else is an error. 252// 253// _LIBCPP_USING_GETENTROPY 254// Use getentropy(). 255// When this option is used, the token passed to `std::random_device`'s 256// constructor *must* be "/dev/urandom" -- anything else is an error. 257// 258// _LIBCPP_USING_FUCHSIA_CPRNG 259// Use Fuchsia's zx_cprng_draw() system call, which is specified to 260// deliver high-quality entropy and cannot fail. 261// When this option is used, the token passed to `std::random_device`'s 262// constructor *must* be "/dev/urandom" -- anything else is an error. 263// 264// _LIBCPP_USING_NACL_RANDOM 265// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 266// including accesses to the special files under `/dev`. This implementation 267// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 268// When this option is used, the token passed to `std::random_device`'s 269// constructor *must* be "/dev/urandom" -- anything else is an error. 270// 271// _LIBCPP_USING_WIN32_RANDOM 272// Use rand_s(), for use on Windows. 273// When this option is used, the token passed to `std::random_device`'s 274// constructor *must* be "/dev/urandom" -- anything else is an error. 275# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 276 defined(__DragonFly__) 277# define _LIBCPP_USING_ARC4_RANDOM 278# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 279# define _LIBCPP_USING_GETENTROPY 280# elif defined(__Fuchsia__) 281# define _LIBCPP_USING_FUCHSIA_CPRNG 282# elif defined(__native_client__) 283# define _LIBCPP_USING_NACL_RANDOM 284# elif defined(_LIBCPP_WIN32API) 285# define _LIBCPP_USING_WIN32_RANDOM 286# else 287# define _LIBCPP_USING_DEV_RANDOM 288# endif 289 290# ifndef _LIBCPP_CXX03_LANG 291 292# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 293# define _ALIGNAS_TYPE(x) alignas(x) 294# define _ALIGNAS(x) alignas(x) 295# define _NOEXCEPT noexcept 296# define _NOEXCEPT_(...) noexcept(__VA_ARGS__) 297# define _LIBCPP_CONSTEXPR constexpr 298 299# else 300 301# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 302# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 303# define _ALIGNAS(x) __attribute__((__aligned__(x))) 304# define nullptr __nullptr 305# define _NOEXCEPT throw() 306# define _NOEXCEPT_(...) 307# define static_assert(...) _Static_assert(__VA_ARGS__) 308# define decltype(...) __decltype(__VA_ARGS__) 309# define _LIBCPP_CONSTEXPR 310 311typedef __char16_t char16_t; 312typedef __char32_t char32_t; 313 314# endif 315 316# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 317 318// Objective-C++ features (opt-in) 319# if __has_feature(objc_arc) 320# define _LIBCPP_HAS_OBJC_ARC 1 321# else 322# define _LIBCPP_HAS_OBJC_ARC 0 323# endif 324 325# if __has_feature(objc_arc_weak) 326# define _LIBCPP_HAS_OBJC_ARC_WEAK 1 327# else 328# define _LIBCPP_HAS_OBJC_ARC_WEAK 0 329# endif 330 331# if __has_extension(blocks) 332# define _LIBCPP_HAS_EXTENSION_BLOCKS 1 333# else 334# define _LIBCPP_HAS_EXTENSION_BLOCKS 0 335# endif 336 337# if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__) 338# define _LIBCPP_HAS_BLOCKS_RUNTIME 1 339# else 340# define _LIBCPP_HAS_BLOCKS_RUNTIME 0 341# endif 342 343# if __has_feature(address_sanitizer) 344# define _LIBCPP_HAS_ASAN 1 345# else 346# define _LIBCPP_HAS_ASAN 0 347# endif 348 349# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 350 351# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 352 353# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 354 355# ifdef _DLL 356# define _LIBCPP_CRT_FUNC __declspec(dllimport) 357# else 358# define _LIBCPP_CRT_FUNC 359# endif 360 361# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 362# define _LIBCPP_DLL_VIS 363# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 364# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 365# define _LIBCPP_OVERRIDABLE_FUNC_VIS 366# define _LIBCPP_EXPORTED_FROM_ABI 367# elif defined(_LIBCPP_BUILDING_LIBRARY) 368# define _LIBCPP_DLL_VIS __declspec(dllexport) 369# if defined(__MINGW32__) 370# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 371# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 372# else 373# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 374# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 375# endif 376# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 377# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 378# else 379# define _LIBCPP_DLL_VIS __declspec(dllimport) 380# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 381# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 382# define _LIBCPP_OVERRIDABLE_FUNC_VIS 383# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 384# endif 385 386# define _LIBCPP_HIDDEN 387# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 388# define _LIBCPP_TEMPLATE_VIS 389# define _LIBCPP_TEMPLATE_DATA_VIS 390# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 391 392# else 393 394# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 395# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 396# else 397# define _LIBCPP_VISIBILITY(vis) 398# endif 399 400# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 401# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 402# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 403# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 404# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 405 406// TODO: Make this a proper customization point or remove the option to override it. 407# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 408# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 409# endif 410 411# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 412// The inline should be removed once PR32114 is resolved 413# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 414# else 415# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 416# endif 417 418// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates 419# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__) 420# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 421# else 422# define _LIBCPP_TEMPLATE_VIS 423# endif 424 425# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) 426# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default"))) 427# else 428# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 429# endif 430 431# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 432 433# if __has_attribute(exclude_from_explicit_instantiation) 434# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 435# else 436// Try to approximate the effect of exclude_from_explicit_instantiation 437// (which is that entities are not assumed to be provided by explicit 438// template instantiations in the dylib) by always inlining those entities. 439# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 440# endif 441 442# ifdef _LIBCPP_COMPILER_CLANG_BASED 443# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 444# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 445# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 446# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 447# elif defined(_LIBCPP_COMPILER_GCC) 448# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 449# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 450# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 451# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 452# else 453# define _LIBCPP_DIAGNOSTIC_PUSH 454# define _LIBCPP_DIAGNOSTIC_POP 455# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 456# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 457# endif 458 459# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 460# define _LIBCPP_HARDENING_SIG f 461# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 462# define _LIBCPP_HARDENING_SIG s 463# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 464# define _LIBCPP_HARDENING_SIG d 465# else 466# define _LIBCPP_HARDENING_SIG n // "none" 467# endif 468 469# if !_LIBCPP_HAS_EXCEPTIONS 470# define _LIBCPP_EXCEPTIONS_SIG n 471# else 472# define _LIBCPP_EXCEPTIONS_SIG e 473# endif 474 475# define _LIBCPP_ODR_SIGNATURE \ 476 _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) 477 478// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 479// on two levels: 480// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 481// symbols from their dynamic library by means of using the libc++ headers. This ensures 482// that those symbols stay private to the dynamic library in which it is defined. 483// 484// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. 485// This ensures that no ODR violation can arise from mixing two TUs compiled with different 486// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the 487// program contains two definitions of a function, the ODR requires them to be token-by-token 488// equivalent, and the linker is allowed to pick either definition and discard the other one. 489// 490// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled 491// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs 492// compiled with different settings), the two definitions are both visible by the linker and they 493// have the same name, but they have a meaningfully different implementation (one throws an exception 494// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in 495// practice what will happen is that the linker will pick one of the definitions at random and will 496// discard the other one. This can quite clearly lead to incorrect program behavior. 497// 498// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any 499// property that causes the code of a function to differ from the code in another configuration 500// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI 501// tag, but we encode the ones that we think are most important: library version, exceptions, and 502// hardening mode. 503// 504// Note that historically, solving this problem has been achieved in various ways, including 505// force-inlining all functions or giving internal linkage to all functions. Both these previous 506// solutions suffer from drawbacks that lead notably to code bloat. 507// 508// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 509// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 510// 511// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 512// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 513// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 514// the virtual function pointer in the vtable based on the mangled name of the function. Since 515// we use an ABI tag that changes with each released version, the mangled name of the virtual 516// function would change, which is incorrect. Note that it doesn't make much sense to change 517// the implementation of a virtual function in an ABI-incompatible way in the first place, 518// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 519// 520// The macro can be applied to record and enum types. When the tagged type is nested in 521// a record this "parent" record needs to have the macro too. Another use case for applying 522// this macro to records and unions is to apply an ABI tag to inline constexpr variables. 523// This can be useful for inline variables that are implementation details which are expected 524// to change in the future. 525// 526// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 527// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 528// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 529# ifndef _LIBCPP_NO_ABI_TAG 530# define _LIBCPP_HIDE_FROM_ABI \ 531 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 532 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) 533# else 534# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 535# endif 536# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 537 538# ifdef _LIBCPP_BUILDING_LIBRARY 539# if _LIBCPP_ABI_VERSION > 1 540# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 541# else 542# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 543# endif 544# else 545# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 546# endif 547 548// TODO: Remove this workaround once we drop support for Clang 16 549# if __has_warning("-Wc++23-extensions") 550# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") 551# else 552# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions") 553# endif 554 555// Clang modules take a significant compile time hit when pushing and popping diagnostics. 556// Since all the headers are marked as system headers in the modulemap, we can simply disable this 557// pushing and popping when building with clang modules. 558# if !__has_feature(modules) 559# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ 560 _LIBCPP_DIAGNOSTIC_PUSH \ 561 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \ 562 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ 563 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ 564 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ 565 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \ 566 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ 567 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ 568 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ 569 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") 570# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP 571# else 572# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS 573# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS 574# endif 575 576// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 577// clang-format off 578# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ 579 namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \ 580 inline namespace _LIBCPP_ABI_NAMESPACE { 581# define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS 582 583#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental { 584#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL }} 585 586#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 { 587#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL 588 589#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 { 590#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL 591 592#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE 593# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem { 594# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD 595#else 596# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ 597 inline namespace __fs { namespace filesystem { 598 599# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD 600#endif 601 602// clang-format on 603 604# if __has_attribute(__enable_if__) 605# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 606# endif 607 608# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) 609# define _LIBCPP_HAS_INT128 0 610# else 611# define _LIBCPP_HAS_INT128 1 612# endif 613 614# ifdef _LIBCPP_CXX03_LANG 615# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 616 struct _LIBCPP_EXPORTED_FROM_ABI x { \ 617 enum __lx 618// clang-format off 619# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 620 __lx __v_; \ 621 _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ 622 _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 623 _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ 624 }; 625// clang-format on 626 627# else // _LIBCPP_CXX03_LANG 628# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x 629# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 630# endif // _LIBCPP_CXX03_LANG 631 632# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) 633# define _LIBCPP_LOCALE__L_EXTENSIONS 1 634# endif 635 636# ifdef __FreeBSD__ 637# define _DECLARE_C99_LDBL_MATH 1 638# endif 639 640// If we are getting operator new from the MSVC CRT, then allocation overloads 641// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 642# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 643# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 644# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 645// We're deferring to Microsoft's STL to provide aligned new et al. We don't 646// have it unless the language feature test macro is defined. 647# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 648# elif defined(__MVS__) 649# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 650# else 651# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1 652# endif 653 654# if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 655# define _LIBCPP_HAS_ALIGNED_ALLOCATION 0 656# else 657# define _LIBCPP_HAS_ALIGNED_ALLOCATION 1 658# endif 659 660// It is not yet possible to use aligned_alloc() on all Apple platforms since 661// 10.15 was the first version to ship an implementation of aligned_alloc(). 662# if defined(__APPLE__) 663# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 664 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ 665 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ 666 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) 667# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 668# else 669# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 670# endif 671# elif defined(__ANDROID__) && __ANDROID_API__ < 28 672// Android only provides aligned_alloc when targeting API 28 or higher. 673# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 674# else 675# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 676# endif 677 678# if defined(__APPLE__) || defined(__FreeBSD__) 679# define _LIBCPP_HAS_DEFAULTRUNELOCALE 680# endif 681 682# if defined(__APPLE__) || defined(__FreeBSD__) 683# define _LIBCPP_WCTYPE_IS_MASK 684# endif 685 686# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 687# define _LIBCPP_HAS_CHAR8_T 0 688# else 689# define _LIBCPP_HAS_CHAR8_T 1 690# endif 691 692// Deprecation macros. 693// 694// Deprecations warnings are always enabled, except when users explicitly opt-out 695// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 696# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 697# if __has_attribute(__deprecated__) 698# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) 699# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) 700# elif _LIBCPP_STD_VER >= 14 701# define _LIBCPP_DEPRECATED [[deprecated]] 702# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 703# else 704# define _LIBCPP_DEPRECATED 705# define _LIBCPP_DEPRECATED_(m) 706# endif 707# else 708# define _LIBCPP_DEPRECATED 709# define _LIBCPP_DEPRECATED_(m) 710# endif 711 712# if !defined(_LIBCPP_CXX03_LANG) 713# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 714# else 715# define _LIBCPP_DEPRECATED_IN_CXX11 716# endif 717 718# if _LIBCPP_STD_VER >= 14 719# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 720# else 721# define _LIBCPP_DEPRECATED_IN_CXX14 722# endif 723 724# if _LIBCPP_STD_VER >= 17 725# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 726# else 727# define _LIBCPP_DEPRECATED_IN_CXX17 728# endif 729 730# if _LIBCPP_STD_VER >= 20 731# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 732# else 733# define _LIBCPP_DEPRECATED_IN_CXX20 734# endif 735 736# if _LIBCPP_STD_VER >= 23 737# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 738# else 739# define _LIBCPP_DEPRECATED_IN_CXX23 740# endif 741 742# if _LIBCPP_STD_VER >= 26 743# define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED 744# else 745# define _LIBCPP_DEPRECATED_IN_CXX26 746# endif 747 748# if _LIBCPP_HAS_CHAR8_T 749# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 750# else 751# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 752# endif 753 754// Macros to enter and leave a state where deprecation warnings are suppressed. 755# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 756# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 757 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 758 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 759# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 760# else 761# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 762# define _LIBCPP_SUPPRESS_DEPRECATED_POP 763# endif 764 765# if _LIBCPP_STD_VER <= 11 766# define _LIBCPP_EXPLICIT_SINCE_CXX14 767# else 768# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit 769# endif 770 771# if _LIBCPP_STD_VER >= 23 772# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit 773# else 774# define _LIBCPP_EXPLICIT_SINCE_CXX23 775# endif 776 777# if _LIBCPP_STD_VER >= 14 778# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 779# else 780# define _LIBCPP_CONSTEXPR_SINCE_CXX14 781# endif 782 783# if _LIBCPP_STD_VER >= 17 784# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 785# else 786# define _LIBCPP_CONSTEXPR_SINCE_CXX17 787# endif 788 789# if _LIBCPP_STD_VER >= 20 790# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 791# else 792# define _LIBCPP_CONSTEXPR_SINCE_CXX20 793# endif 794 795# if _LIBCPP_STD_VER >= 23 796# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 797# else 798# define _LIBCPP_CONSTEXPR_SINCE_CXX23 799# endif 800 801# if _LIBCPP_STD_VER >= 26 802# define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr 803# else 804# define _LIBCPP_CONSTEXPR_SINCE_CXX26 805# endif 806 807# ifndef _LIBCPP_WEAK 808# define _LIBCPP_WEAK __attribute__((__weak__)) 809# endif 810 811// Thread API 812// clang-format off 813# if _LIBCPP_HAS_THREADS && \ 814 !_LIBCPP_HAS_THREAD_API_PTHREAD && \ 815 !_LIBCPP_HAS_THREAD_API_WIN32 && \ 816 !_LIBCPP_HAS_THREAD_API_EXTERNAL 817 818# if defined(__FreeBSD__) || \ 819 defined(__wasi__) || \ 820 defined(__NetBSD__) || \ 821 defined(__OpenBSD__) || \ 822 defined(__NuttX__) || \ 823 defined(__linux__) || \ 824 defined(__GNU__) || \ 825 defined(__APPLE__) || \ 826 defined(__MVS__) || \ 827 defined(_AIX) || \ 828 defined(__EMSCRIPTEN__) 829// clang-format on 830# undef _LIBCPP_HAS_THREAD_API_PTHREAD 831# define _LIBCPP_HAS_THREAD_API_PTHREAD 1 832# elif defined(__Fuchsia__) 833// TODO(44575): Switch to C11 thread API when possible. 834# undef _LIBCPP_HAS_THREAD_API_PTHREAD 835# define _LIBCPP_HAS_THREAD_API_PTHREAD 1 836# elif defined(_LIBCPP_WIN32API) 837# undef _LIBCPP_HAS_THREAD_API_WIN32 838# define _LIBCPP_HAS_THREAD_API_WIN32 1 839# else 840# error "No thread API" 841# endif // _LIBCPP_HAS_THREAD_API 842# endif // _LIBCPP_HAS_THREADS 843 844# if _LIBCPP_HAS_THREAD_API_PTHREAD 845# if defined(__ANDROID__) && __ANDROID_API__ >= 30 846# define _LIBCPP_HAS_COND_CLOCKWAIT 1 847# elif defined(_LIBCPP_GLIBC_PREREQ) 848# if _LIBCPP_GLIBC_PREREQ(2, 30) 849# define _LIBCPP_HAS_COND_CLOCKWAIT 1 850# else 851# define _LIBCPP_HAS_COND_CLOCKWAIT 0 852# endif 853# else 854# define _LIBCPP_HAS_COND_CLOCKWAIT 0 855# endif 856# else 857# define _LIBCPP_HAS_COND_CLOCKWAIT 0 858# endif 859 860# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD 861# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true. 862# endif 863 864# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL 865# error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true. 866# endif 867 868# if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS 869# error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false. 870# endif 871 872# if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__) 873# define __STDCPP_THREADS__ 1 874# endif 875 876// The glibc and Bionic implementation of pthreads implements 877// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 878// mutexes have no destroy mechanism. 879// 880// This optimization can't be performed on Apple platforms, where 881// pthread_mutex_destroy can allow the kernel to release resources. 882// See https://llvm.org/D64298 for details. 883// 884// TODO(EricWF): Enable this optimization on Bionic after speaking to their 885// respective stakeholders. 886// clang-format off 887# if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \ 888 (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \ 889 _LIBCPP_HAS_THREAD_API_WIN32 890// clang-format on 891# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1 892# else 893# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0 894# endif 895 896// Destroying a condvar is a nop on Windows. 897// 898// This optimization can't be performed on Apple platforms, where 899// pthread_cond_destroy can allow the kernel to release resources. 900// See https://llvm.org/D64298 for details. 901// 902// TODO(EricWF): This is potentially true for some pthread implementations 903// as well. 904# if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32 905# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1 906# else 907# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0 908# endif 909 910# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 911 _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__) 912# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 913# endif 914 915# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 916# define _LIBCPP_HAS_C_ATOMIC_IMP 1 917# define _LIBCPP_HAS_GCC_ATOMIC_IMP 0 918# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 919# elif defined(_LIBCPP_COMPILER_GCC) 920# define _LIBCPP_HAS_C_ATOMIC_IMP 0 921# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1 922# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 923# endif 924 925# if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 926# define _LIBCPP_HAS_ATOMIC_HEADER 0 927# else 928# define _LIBCPP_HAS_ATOMIC_HEADER 1 929# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 930# define _LIBCPP_ATOMIC_FLAG_TYPE bool 931# endif 932# endif 933 934# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) 935# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) 936# else 937# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 938# endif 939 940// Work around the attribute handling in clang. When both __declspec and 941// __attribute__ are present, the processing goes awry preventing the definition 942// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 943// combining the two does work. 944# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) && defined(__clang__) && \ 945 __has_attribute(acquire_capability) && !defined(_MSC_VER) 946# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1 947# else 948# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 0 949# endif 950 951# if _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 952# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 953# else 954# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 955# endif 956 957# if _LIBCPP_STD_VER >= 20 958# define _LIBCPP_CONSTINIT constinit 959# elif __has_attribute(__require_constant_initialization__) 960# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 961# else 962# define _LIBCPP_CONSTINIT 963# endif 964 965# if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) 966// The CUDA SDK contains an unfortunate definition for the __noinline__ macro, 967// which breaks the regular __attribute__((__noinline__)) syntax. Therefore, 968// when compiling for CUDA we use the non-underscored version of the noinline 969// attribute. 970// 971// This is a temporary workaround and we still expect the CUDA SDK team to solve 972// this issue properly in the SDK headers. 973// 974// See https://github.com/llvm/llvm-project/pull/73838 for more details. 975# define _LIBCPP_NOINLINE __attribute__((noinline)) 976# elif __has_attribute(__noinline__) 977# define _LIBCPP_NOINLINE __attribute__((__noinline__)) 978# else 979# define _LIBCPP_NOINLINE 980# endif 981 982// We often repeat things just for handling wide characters in the library. 983// When wide characters are disabled, it can be useful to have a quick way of 984// disabling it without having to resort to #if-#endif, which has a larger 985// impact on readability. 986# if !_LIBCPP_HAS_WIDE_CHARACTERS 987# define _LIBCPP_IF_WIDE_CHARACTERS(...) 988# else 989# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 990# endif 991 992// clang-format off 993# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")") 994# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")") 995// clang-format on 996 997# ifndef _LIBCPP_NO_AUTO_LINK 998# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 999# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 1000# pragma comment(lib, "c++.lib") 1001# else 1002# pragma comment(lib, "libc++.lib") 1003# endif 1004# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1005# endif // _LIBCPP_NO_AUTO_LINK 1006 1007// Configures the fopen close-on-exec mode character, if any. This string will 1008// be appended to any mode string used by fstream for fopen/fdopen. 1009// 1010// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1011// do. 1012# if defined(__BIONIC__) 1013# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1014# else 1015# define _LIBCPP_FOPEN_CLOEXEC_MODE 1016# endif 1017 1018# if __has_cpp_attribute(msvc::no_unique_address) 1019// MSVC implements [[no_unique_address]] as a silent no-op currently. 1020// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 1021// However, MSVC implements [[msvc::no_unique_address]] which does what 1022// [[no_unique_address]] is supposed to do, in general. 1023# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 1024# else 1025# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] 1026# endif 1027 1028// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1029// functions is gradually being added to existing C libraries. The conditions 1030// below check for known C library versions and conditions under which these 1031// functions are declared by the C library. 1032// 1033// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 1034// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 1035// the latter depends on internal GNU libc details that are not appropriate 1036// to depend on here, so any declarations present when __cpp_char8_t is not 1037// defined are ignored. 1038# if defined(_LIBCPP_GLIBC_PREREQ) 1039# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1040# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1 1041# else 1042# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 1043# endif 1044# else 1045# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 1046# endif 1047 1048// There are a handful of public standard library types that are intended to 1049// support CTAD but don't need any explicit deduction guides to do so. This 1050// macro is used to mark them as such, which suppresses the 1051// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1052// with these classes. 1053# if _LIBCPP_STD_VER >= 17 1054# ifdef _LIBCPP_COMPILER_CLANG_BASED 1055# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1056 template <class... _Tag> \ 1057 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> 1058# else 1059# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ 1060 template <class... _Tag> \ 1061 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> 1062# endif 1063# else 1064# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1065# endif 1066 1067// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 1068// compiler intrinsics in the Objective-C++ mode. 1069# ifdef __OBJC__ 1070# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 1071# endif 1072 1073# define _PSTL_PRAGMA(x) _Pragma(#x) 1074 1075// Enable SIMD for compilers that support OpenMP 4.0 1076# if (defined(_OPENMP) && _OPENMP >= 201307) 1077 1078# define _PSTL_UDR_PRESENT 1079# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) 1080# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) 1081# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) 1082# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) 1083# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) 1084# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) 1085 1086// Declaration of reduction functor, where 1087// NAME - the name of the functor 1088// OP - type of the callable object with the reduction operation 1089// omp_in - refers to the local partial result 1090// omp_out - refers to the final value of the combiner operator 1091// omp_priv - refers to the private copy of the initial value 1092// omp_orig - refers to the original variable to be reduced 1093# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ 1094 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) 1095 1096# elif defined(_LIBCPP_COMPILER_CLANG_BASED) 1097 1098# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") 1099# define _PSTL_PRAGMA_DECLARE_SIMD 1100# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 1101# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 1102# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 1103# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 1104# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 1105 1106# else // (defined(_OPENMP) && _OPENMP >= 201307) 1107 1108# define _PSTL_PRAGMA_SIMD 1109# define _PSTL_PRAGMA_DECLARE_SIMD 1110# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) 1111# define _PSTL_PRAGMA_SIMD_SCAN(PRM) 1112# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 1113# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 1114# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 1115 1116# endif // (defined(_OPENMP) && _OPENMP >= 201307) 1117 1118# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED 1119 1120// Optional attributes - these are useful for a better QoI, but not required to be available 1121 1122# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 1123# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 1124# else 1125# define _LIBCPP_NO_CFI 1126# endif 1127 1128# if __has_attribute(__malloc__) 1129# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 1130# else 1131# define _LIBCPP_NOALIAS 1132# endif 1133 1134# if __has_attribute(__using_if_exists__) 1135# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 1136# else 1137# define _LIBCPP_USING_IF_EXISTS 1138# endif 1139 1140# if __has_attribute(__no_destroy__) 1141# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 1142# else 1143# define _LIBCPP_NO_DESTROY 1144# endif 1145 1146# if __has_attribute(__diagnose_if__) 1147# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 1148# else 1149# define _LIBCPP_DIAGNOSE_WARNING(...) 1150# endif 1151 1152// Use a function like macro to imply that it must be followed by a semicolon 1153# if __has_cpp_attribute(fallthrough) 1154# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 1155# elif __has_attribute(__fallthrough__) 1156# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 1157# else 1158# define _LIBCPP_FALLTHROUGH() ((void)0) 1159# endif 1160 1161# if __has_cpp_attribute(_Clang::__lifetimebound__) 1162# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 1163# else 1164# define _LIBCPP_LIFETIMEBOUND 1165# endif 1166 1167# if __has_cpp_attribute(_Clang::__noescape__) 1168# define _LIBCPP_NOESCAPE [[_Clang::__noescape__]] 1169# else 1170# define _LIBCPP_NOESCAPE 1171# endif 1172 1173# if __has_attribute(__nodebug__) 1174# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 1175# else 1176# define _LIBCPP_NODEBUG 1177# endif 1178 1179# if __has_attribute(__standalone_debug__) 1180# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1181# else 1182# define _LIBCPP_STANDALONE_DEBUG 1183# endif 1184 1185# if __has_attribute(__preferred_name__) 1186# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1187# else 1188# define _LIBCPP_PREFERRED_NAME(x) 1189# endif 1190 1191# if __has_attribute(__no_sanitize__) 1192# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) 1193# else 1194# define _LIBCPP_NO_SANITIZE(...) 1195# endif 1196 1197# if __has_attribute(__init_priority__) 1198# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 1199# else 1200# define _LIBCPP_INIT_PRIORITY_MAX 1201# endif 1202 1203# if __has_attribute(__format__) 1204// The attribute uses 1-based indices for ordinary and static member functions. 1205// The attribute uses 2-based indices for non-static member functions. 1206# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 1207 __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1208# else 1209# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1210# endif 1211 1212# if __has_attribute(__packed__) 1213# define _LIBCPP_PACKED __attribute__((__packed__)) 1214# else 1215# define _LIBCPP_PACKED 1216# endif 1217 1218# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 1219# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 1220# else 1221# define _LIBCPP_DECLSPEC_EMPTY_BASES 1222# endif 1223 1224// Allow for build-time disabling of unsigned integer sanitization 1225# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) 1226# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 1227# else 1228# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1229# endif 1230 1231// Clang-18 has support for deducing this, but it does not set the FTM. 1232# if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800) 1233# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1 1234# else 1235# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0 1236# endif 1237 1238#endif // __cplusplus 1239 1240#endif // _LIBCPP___CONFIG 1241