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 210000 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_EXPERIMENTAL_LIBRARY 1 203# else 204# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 0 205# endif 206 207# define _LIBCPP_HAS_EXPERIMENTAL_PSTL _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 208# define _LIBCPP_HAS_EXPERIMENTAL_TZDB _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 209# define _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 210 211# if defined(__MVS__) 212# include <features.h> // for __NATIVE_ASCII_F 213# endif 214 215# if defined(_WIN32) 216# define _LIBCPP_WIN32API 217# define _LIBCPP_SHORT_WCHAR 1 218// Both MinGW and native MSVC provide a "MSVC"-like environment 219# define _LIBCPP_MSVCRT_LIKE 220// If mingw not explicitly detected, assume using MS C runtime only if 221// a MS compatibility version is specified. 222# if defined(_MSC_VER) && !defined(__MINGW32__) 223# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 224# endif 225# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 226# define _LIBCPP_HAS_BITSCAN64 1 227# else 228# define _LIBCPP_HAS_BITSCAN64 0 229# endif 230# define _LIBCPP_HAS_OPEN_WITH_WCHAR 1 231# else 232# define _LIBCPP_HAS_OPEN_WITH_WCHAR 0 233# define _LIBCPP_HAS_BITSCAN64 0 234# endif // defined(_WIN32) 235 236# if defined(_AIX) && !defined(__64BIT__) 237// The size of wchar is 2 byte on 32-bit mode on AIX. 238# define _LIBCPP_SHORT_WCHAR 1 239# endif 240 241// Libc++ supports various implementations of std::random_device. 242// 243// _LIBCPP_USING_DEV_RANDOM 244// Read entropy from the given file, by default `/dev/urandom`. 245// If a token is provided, it is assumed to be the path to a file 246// to read entropy from. This is the default behavior if nothing 247// else is specified. This implementation requires storing state 248// inside `std::random_device`. 249// 250// _LIBCPP_USING_ARC4_RANDOM 251// Use arc4random(). This allows obtaining random data even when 252// using sandboxing mechanisms. On some platforms like Apple, this 253// is the recommended source of entropy for user-space programs. 254// When this option is used, the token passed to `std::random_device`'s 255// constructor *must* be "/dev/urandom" -- anything else is an error. 256// 257// _LIBCPP_USING_GETENTROPY 258// Use getentropy(). 259// When this option is used, the token passed to `std::random_device`'s 260// constructor *must* be "/dev/urandom" -- anything else is an error. 261// 262// _LIBCPP_USING_FUCHSIA_CPRNG 263// Use Fuchsia's zx_cprng_draw() system call, which is specified to 264// deliver high-quality entropy and cannot fail. 265// When this option is used, the token passed to `std::random_device`'s 266// constructor *must* be "/dev/urandom" -- anything else is an error. 267// 268// _LIBCPP_USING_NACL_RANDOM 269// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 270// including accesses to the special files under `/dev`. This implementation 271// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 272// When this option is used, the token passed to `std::random_device`'s 273// constructor *must* be "/dev/urandom" -- anything else is an error. 274// 275// _LIBCPP_USING_WIN32_RANDOM 276// Use rand_s(), for use on Windows. 277// When this option is used, the token passed to `std::random_device`'s 278// constructor *must* be "/dev/urandom" -- anything else is an error. 279# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 280 defined(__DragonFly__) 281# define _LIBCPP_USING_ARC4_RANDOM 282# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 283# define _LIBCPP_USING_GETENTROPY 284# elif defined(__Fuchsia__) 285# define _LIBCPP_USING_FUCHSIA_CPRNG 286# elif defined(__native_client__) 287# define _LIBCPP_USING_NACL_RANDOM 288# elif defined(_LIBCPP_WIN32API) 289# define _LIBCPP_USING_WIN32_RANDOM 290# else 291# define _LIBCPP_USING_DEV_RANDOM 292# endif 293 294# ifndef _LIBCPP_CXX03_LANG 295 296# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 297# define _ALIGNAS_TYPE(x) alignas(x) 298# define _ALIGNAS(x) alignas(x) 299# define _NOEXCEPT noexcept 300# define _NOEXCEPT_(...) noexcept(__VA_ARGS__) 301# define _LIBCPP_CONSTEXPR constexpr 302 303# else 304 305# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 306# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 307# define _ALIGNAS(x) __attribute__((__aligned__(x))) 308# define nullptr __nullptr 309# define _NOEXCEPT throw() 310# define _NOEXCEPT_(...) 311# define static_assert(...) _Static_assert(__VA_ARGS__) 312# define decltype(...) __decltype(__VA_ARGS__) 313# define _LIBCPP_CONSTEXPR 314 315typedef __char16_t char16_t; 316typedef __char32_t char32_t; 317 318# endif 319 320# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 321 322// Objective-C++ features (opt-in) 323# if __has_feature(objc_arc) 324# define _LIBCPP_HAS_OBJC_ARC 1 325# else 326# define _LIBCPP_HAS_OBJC_ARC 0 327# endif 328 329# if __has_feature(objc_arc_weak) 330# define _LIBCPP_HAS_OBJC_ARC_WEAK 1 331# else 332# define _LIBCPP_HAS_OBJC_ARC_WEAK 0 333# endif 334 335# if __has_extension(blocks) 336# define _LIBCPP_HAS_EXTENSION_BLOCKS 1 337# else 338# define _LIBCPP_HAS_EXTENSION_BLOCKS 0 339# endif 340 341# if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__) 342# define _LIBCPP_HAS_BLOCKS_RUNTIME 1 343# else 344# define _LIBCPP_HAS_BLOCKS_RUNTIME 0 345# endif 346 347# if __has_feature(address_sanitizer) 348# define _LIBCPP_HAS_ASAN 1 349# else 350# define _LIBCPP_HAS_ASAN 0 351# endif 352 353# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 354 355# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 356 357# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 358 359# ifdef _DLL 360# define _LIBCPP_CRT_FUNC __declspec(dllimport) 361# else 362# define _LIBCPP_CRT_FUNC 363# endif 364 365# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 366# define _LIBCPP_DLL_VIS 367# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 368# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 369# define _LIBCPP_OVERRIDABLE_FUNC_VIS 370# define _LIBCPP_EXPORTED_FROM_ABI 371# elif defined(_LIBCPP_BUILDING_LIBRARY) 372# define _LIBCPP_DLL_VIS __declspec(dllexport) 373# if defined(__MINGW32__) 374# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 375# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 376# else 377# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 378# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 379# endif 380# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 381# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 382# else 383# define _LIBCPP_DLL_VIS __declspec(dllimport) 384# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 385# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 386# define _LIBCPP_OVERRIDABLE_FUNC_VIS 387# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 388# endif 389 390# define _LIBCPP_HIDDEN 391# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 392# define _LIBCPP_TEMPLATE_VIS 393# define _LIBCPP_TEMPLATE_DATA_VIS 394# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 395 396# else 397 398# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 399# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 400# else 401# define _LIBCPP_VISIBILITY(vis) 402# endif 403 404# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 405# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 406# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 407# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 408# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 409 410// TODO: Make this a proper customization point or remove the option to override it. 411# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 412# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 413# endif 414 415# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 416// The inline should be removed once PR32114 is resolved 417# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 418# else 419# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 420# endif 421 422// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates 423# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__) 424# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 425# else 426# define _LIBCPP_TEMPLATE_VIS 427# endif 428 429# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) 430# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default"))) 431# else 432# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 433# endif 434 435# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 436 437# if __has_attribute(exclude_from_explicit_instantiation) 438# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 439# else 440// Try to approximate the effect of exclude_from_explicit_instantiation 441// (which is that entities are not assumed to be provided by explicit 442// template instantiations in the dylib) by always inlining those entities. 443# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 444# endif 445 446# ifdef _LIBCPP_COMPILER_CLANG_BASED 447# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 448# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 449# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 450# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 451# elif defined(_LIBCPP_COMPILER_GCC) 452# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 453# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 454# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 455# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 456# else 457# define _LIBCPP_DIAGNOSTIC_PUSH 458# define _LIBCPP_DIAGNOSTIC_POP 459# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 460# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 461# endif 462 463# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 464# define _LIBCPP_HARDENING_SIG f 465# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 466# define _LIBCPP_HARDENING_SIG s 467# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 468# define _LIBCPP_HARDENING_SIG d 469# else 470# define _LIBCPP_HARDENING_SIG n // "none" 471# endif 472 473# if !_LIBCPP_HAS_EXCEPTIONS 474# define _LIBCPP_EXCEPTIONS_SIG n 475# else 476# define _LIBCPP_EXCEPTIONS_SIG e 477# endif 478 479# define _LIBCPP_ODR_SIGNATURE \ 480 _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) 481 482// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 483// on two levels: 484// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 485// symbols from their dynamic library by means of using the libc++ headers. This ensures 486// that those symbols stay private to the dynamic library in which it is defined. 487// 488// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. 489// This ensures that no ODR violation can arise from mixing two TUs compiled with different 490// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the 491// program contains two definitions of a function, the ODR requires them to be token-by-token 492// equivalent, and the linker is allowed to pick either definition and discard the other one. 493// 494// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled 495// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs 496// compiled with different settings), the two definitions are both visible by the linker and they 497// have the same name, but they have a meaningfully different implementation (one throws an exception 498// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in 499// practice what will happen is that the linker will pick one of the definitions at random and will 500// discard the other one. This can quite clearly lead to incorrect program behavior. 501// 502// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any 503// property that causes the code of a function to differ from the code in another configuration 504// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI 505// tag, but we encode the ones that we think are most important: library version, exceptions, and 506// hardening mode. 507// 508// Note that historically, solving this problem has been achieved in various ways, including 509// force-inlining all functions or giving internal linkage to all functions. Both these previous 510// solutions suffer from drawbacks that lead notably to code bloat. 511// 512// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 513// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 514// 515// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 516// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 517// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 518// the virtual function pointer in the vtable based on the mangled name of the function. Since 519// we use an ABI tag that changes with each released version, the mangled name of the virtual 520// function would change, which is incorrect. Note that it doesn't make much sense to change 521// the implementation of a virtual function in an ABI-incompatible way in the first place, 522// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 523// 524// The macro can be applied to record and enum types. When the tagged type is nested in 525// a record this "parent" record needs to have the macro too. Another use case for applying 526// this macro to records and unions is to apply an ABI tag to inline constexpr variables. 527// This can be useful for inline variables that are implementation details which are expected 528// to change in the future. 529// 530// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 531// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 532// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 533# ifndef _LIBCPP_NO_ABI_TAG 534# define _LIBCPP_HIDE_FROM_ABI \ 535 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 536 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) 537# else 538# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 539# endif 540# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 541 542# ifdef _LIBCPP_BUILDING_LIBRARY 543# if _LIBCPP_ABI_VERSION > 1 544# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 545# else 546# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 547# endif 548# else 549# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 550# endif 551 552// TODO: Remove this workaround once we drop support for Clang 16 553# if __has_warning("-Wc++23-extensions") 554# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") 555# else 556# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions") 557# endif 558 559// Clang modules take a significant compile time hit when pushing and popping diagnostics. 560// Since all the headers are marked as system headers in the modulemap, we can simply disable this 561// pushing and popping when building with clang modules. 562# if !__has_feature(modules) 563# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ 564 _LIBCPP_DIAGNOSTIC_PUSH \ 565 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \ 566 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ 567 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ 568 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ 569 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \ 570 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ 571 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ 572 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ 573 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") 574# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP 575# else 576# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS 577# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS 578# endif 579 580// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 581// clang-format off 582# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ 583 namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \ 584 inline namespace _LIBCPP_ABI_NAMESPACE { 585# define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS 586 587#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental { 588#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL }} 589 590#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 { 591#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL 592 593#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 { 594#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL 595 596#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE 597# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem { 598# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD 599#else 600# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ 601 inline namespace __fs { namespace filesystem { 602 603# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD 604#endif 605 606// clang-format on 607 608# if __has_attribute(__enable_if__) 609# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 610# endif 611 612# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) 613# define _LIBCPP_HAS_INT128 0 614# else 615# define _LIBCPP_HAS_INT128 1 616# endif 617 618# ifdef _LIBCPP_CXX03_LANG 619# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 620 struct _LIBCPP_EXPORTED_FROM_ABI x { \ 621 enum __lx 622// clang-format off 623# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 624 __lx __v_; \ 625 _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ 626 _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 627 _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ 628 }; 629// clang-format on 630 631# else // _LIBCPP_CXX03_LANG 632# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x 633# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 634# endif // _LIBCPP_CXX03_LANG 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# define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]] 1174 1175# if __has_cpp_attribute(_Clang::__no_specializations__) 1176# define _LIBCPP_NO_SPECIALIZATIONS \ 1177 [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]] 1178# else 1179# define _LIBCPP_NO_SPECIALIZATIONS 1180# endif 1181 1182# if __has_attribute(__standalone_debug__) 1183# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1184# else 1185# define _LIBCPP_STANDALONE_DEBUG 1186# endif 1187 1188# if __has_attribute(__preferred_name__) 1189# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1190# else 1191# define _LIBCPP_PREFERRED_NAME(x) 1192# endif 1193 1194# if __has_attribute(__no_sanitize__) 1195# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) 1196# else 1197# define _LIBCPP_NO_SANITIZE(...) 1198# endif 1199 1200# if __has_attribute(__init_priority__) 1201# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 1202# else 1203# define _LIBCPP_INIT_PRIORITY_MAX 1204# endif 1205 1206# if __has_attribute(__format__) 1207// The attribute uses 1-based indices for ordinary and static member functions. 1208// The attribute uses 2-based indices for non-static member functions. 1209# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 1210 __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1211# else 1212# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1213# endif 1214 1215# if __has_attribute(__packed__) 1216# define _LIBCPP_PACKED __attribute__((__packed__)) 1217# else 1218# define _LIBCPP_PACKED 1219# endif 1220 1221# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 1222# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 1223# else 1224# define _LIBCPP_DECLSPEC_EMPTY_BASES 1225# endif 1226 1227// Allow for build-time disabling of unsigned integer sanitization 1228# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) 1229# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 1230# else 1231# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1232# endif 1233 1234// Clang-18 has support for deducing this, but it does not set the FTM. 1235# if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800) 1236# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1 1237# else 1238# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0 1239# endif 1240 1241#endif // __cplusplus 1242 1243#endif // _LIBCPP___CONFIG 1244