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