codekingpro/portable-devtools
114k
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-exception7// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.8//9//===----------------------------------------------------------------------===//10 11#ifndef _LIBCUDACXX___AVAILABILITY12#define _LIBCUDACXX___AVAILABILITY13 14#ifndef __cuda_std__15#include <__config>16#endif // __cuda_std__17 18#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)19# pragma GCC system_header20#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)21# pragma clang system_header22#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)23# pragma system_header24#endif // no system header25 26// Libc++ is shipped by various vendors. In particular, it is used as a system27// library on macOS, iOS and other Apple platforms. In order for users to be28// able to compile a binary that is intended to be deployed to an older version29// of a platform, Clang provides availability attributes [1]. These attributes30// can be placed on declarations and are used to describe the life cycle of a31// symbol in the library.32//33// The main goal is to ensure a compile-time error if a symbol that hasn't been34// introduced in a previously released library is used in a program that targets35// that previously released library. Normally, this would be a load-time error36// when one tries to launch the program against the older library.37//38// For example, the filesystem library was introduced in the dylib in macOS 10.15.39// If a user compiles on a macOS 10.15 host but targets macOS 10.13 with their40// program, the compiler would normally not complain (because the required41// declarations are in the headers), but the dynamic loader would fail to find42// the symbols when actually trying to launch the program on macOS 10.13. To43// turn this into a compile-time issue instead, declarations are annotated with44// when they were introduced, and the compiler can produce a diagnostic if the45// program references something that isn't available on the deployment target.46//47// This mechanism is general in nature, and any vendor can add their markup to48// the library (see below). Whenever a new feature is added that requires support49// in the shared library, a macro should be added below to mark this feature50// as unavailable. When vendors decide to ship the feature as part of their51// shared library, they can update the markup appropriately.52//53// Furthermore, many features in the standard library have corresponding54// feature-test macros. When a feature is made unavailable on some deployment55// target, a macro should be defined to signal that it is unavailable. That56// macro can then be picked up when feature-test macros are generated (see57// generate_feature_test_macro_components.py) to make sure that feature-test58// macros don't announce a feature as being implemented if it has been marked59// as unavailable.60//61// Note that this mechanism is disabled by default in the "upstream" libc++.62// Availability annotations are only meaningful when shipping libc++ inside63// a platform (i.e. as a system library), and so vendors that want them should64// turn those annotations on at CMake configuration time.65//66// [1]: https://clang.llvm.org/docs/AttributeReference.html#availability67 68 69// For backwards compatibility, allow users to define _LIBCUDACXX_DISABLE_AVAILABILITY70// for a while.71#if defined(_LIBCUDACXX_DISABLE_AVAILABILITY)72# if !defined(_LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)73# define _LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS74# endif75#endif76 77// Availability markup is disabled when building the library, or when the compiler78// doesn't support the proper attributes.79#if defined(_LIBCUDACXX_BUILDING_LIBRARY) || \80 defined(_LIBCXXABI_BUILDING_LIBRARY) || \81 !__has_feature(attribute_availability_with_strict) || \82 !__has_feature(attribute_availability_in_templates) || \83 !__has_extension(pragma_clang_attribute_external_declaration)84# if !defined(_LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)85# define _LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS86# endif87#endif88 89#if defined(_LIBCUDACXX_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)90 91 // This controls the availability of std::shared_mutex and std::shared_timed_mutex,92 // which were added to the dylib later.93# define _LIBCUDACXX_AVAILABILITY_SHARED_MUTEX94// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex95// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex96 97 // These macros control the availability of std::bad_optional_access and98 // other exception types. These were put in the shared library to prevent99 // code bloat from every user program defining the vtable for these exception100 // types.101 //102 // Note that when exceptions are disabled, the methods that normally throw103 // these exceptions can be used even on older deployment targets, but those104 // methods will abort instead of throwing.105# define _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS106# define _LIBCUDACXX_AVAILABILITY_BAD_VARIANT_ACCESS107# define _LIBCUDACXX_AVAILABILITY_BAD_ANY_CAST108 109 // This controls the availability of std::uncaught_exceptions().110# define _LIBCUDACXX_AVAILABILITY_UNCAUGHT_EXCEPTIONS111 112 // This controls the availability of the sized version of ::operator delete,113 // ::operator delete[], and their align_val_t variants, which were all added114 // in C++17, and hence not present in early dylibs.115# define _LIBCUDACXX_AVAILABILITY_SIZED_NEW_DELETE116 117 // This controls the availability of the std::future_error exception.118 //119 // Note that when exceptions are disabled, the methods that normally throw120 // std::future_error can be used even on older deployment targets, but those121 // methods will abort instead of throwing.122# define _LIBCUDACXX_AVAILABILITY_FUTURE_ERROR123 124 // This controls the availability of std::type_info's vtable.125 // I can't imagine how using std::type_info can work at all if126 // this isn't supported.127# define _LIBCUDACXX_AVAILABILITY_TYPEINFO_VTABLE128 129 // This controls the availability of std::locale::category members130 // (e.g. std::locale::collate), which are defined in the dylib.131# define _LIBCUDACXX_AVAILABILITY_LOCALE_CATEGORY132 133 // This controls the availability of atomic operations on std::shared_ptr134 // (e.g. `std::atomic_store(std::shared_ptr)`), which require a shared135 // lock table located in the dylib.136# define _LIBCUDACXX_AVAILABILITY_ATOMIC_SHARED_PTR137 138 // These macros control the availability of all parts of <filesystem> that139 // depend on something in the dylib.140# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM141# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_PUSH142# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_POP143// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem144 145 // This controls the availability of floating-point std::to_chars functions.146 // These overloads were added later than the integer overloads.147# define _LIBCUDACXX_AVAILABILITY_TO_CHARS_FLOATING_POINT148 149 // This controls the availability of the C++20 synchronization library,150 // which requires shared library support for various operations151 // (see libcxx/src/atomic.cpp). This includes <barier>, <latch>,152 // <semaphore>, and notification functions on std::atomic.153# define _LIBCUDACXX_AVAILABILITY_SYNC154// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait155// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier156// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_latch157// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore158 159 // This controls the availability of the C++20 format library.160 // The library is in development and not ABI stable yet. P2216 is161 // retroactively accepted in C++20. This paper contains ABI breaking162 // changes.163# define _LIBCUDACXX_AVAILABILITY_FORMAT164// # define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_format165 166 // This controls whether the default verbose termination function is167 // provided by the library.168 //169 // Note that when users provide their own custom function, it doesn't170 // matter whether the dylib provides a default function, and the171 // availability markup can actually give a false positive diagnostic172 // (it will think that no function is provided, when in reality the173 // user has provided their own).174 //175 // Users can pass -D_LIBCUDACXX_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED176 // to the compiler to tell the library not to define its own verbose abort.177 // Note that defining this macro but failing to define a custom function178 // will lead to a load-time error on back-deployment targets, so it should179 // be avoided.180// # define _LIBCUDACXX_HAS_NO_VERBOSE_ABORT_IN_LIBRARY181 182#elif defined(__APPLE__)183 184# define _LIBCUDACXX_AVAILABILITY_SHARED_MUTEX \185 __attribute__((availability(macos,strict,introduced=10.12))) \186 __attribute__((availability(ios,strict,introduced=10.0))) \187 __attribute__((availability(tvos,strict,introduced=10.0))) \188 __attribute__((availability(watchos,strict,introduced=3.0)))189# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) || \190 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 100000) || \191 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 100000) || \192 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 30000)193# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex194# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex195# endif196 197 // Note: bad_optional_access & friends were not introduced in the matching198 // macOS and iOS versions, so the version mismatch between macOS and others199 // is intended.200# define _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS \201 __attribute__((availability(macos,strict,introduced=10.13))) \202 __attribute__((availability(ios,strict,introduced=12.0))) \203 __attribute__((availability(tvos,strict,introduced=12.0))) \204 __attribute__((availability(watchos,strict,introduced=5.0)))205# define _LIBCUDACXX_AVAILABILITY_BAD_VARIANT_ACCESS \206 _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS207# define _LIBCUDACXX_AVAILABILITY_BAD_ANY_CAST \208 _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS209 210# define _LIBCUDACXX_AVAILABILITY_UNCAUGHT_EXCEPTIONS \211 __attribute__((availability(macos,strict,introduced=10.12))) \212 __attribute__((availability(ios,strict,introduced=10.0))) \213 __attribute__((availability(tvos,strict,introduced=10.0))) \214 __attribute__((availability(watchos,strict,introduced=3.0)))215 216# define _LIBCUDACXX_AVAILABILITY_SIZED_NEW_DELETE \217 __attribute__((availability(macos,strict,introduced=10.12))) \218 __attribute__((availability(ios,strict,introduced=10.0))) \219 __attribute__((availability(tvos,strict,introduced=10.0))) \220 __attribute__((availability(watchos,strict,introduced=3.0)))221 222# define _LIBCUDACXX_AVAILABILITY_FUTURE_ERROR \223 __attribute__((availability(ios,strict,introduced=6.0)))224 225# define _LIBCUDACXX_AVAILABILITY_TYPEINFO_VTABLE \226 __attribute__((availability(macos,strict,introduced=10.9))) \227 __attribute__((availability(ios,strict,introduced=7.0)))228 229# define _LIBCUDACXX_AVAILABILITY_LOCALE_CATEGORY \230 __attribute__((availability(macos,strict,introduced=10.9))) \231 __attribute__((availability(ios,strict,introduced=7.0)))232 233# define _LIBCUDACXX_AVAILABILITY_ATOMIC_SHARED_PTR \234 __attribute__((availability(macos,strict,introduced=10.9))) \235 __attribute__((availability(ios,strict,introduced=7.0)))236 237# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM \238 __attribute__((availability(macos,strict,introduced=10.15))) \239 __attribute__((availability(ios,strict,introduced=13.0))) \240 __attribute__((availability(tvos,strict,introduced=13.0))) \241 __attribute__((availability(watchos,strict,introduced=6.0)))242# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_PUSH \243 _Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \244 _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \245 _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \246 _Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))")247# define _LIBCUDACXX_AVAILABILITY_FILESYSTEM_POP \248 _Pragma("clang attribute pop") \249 _Pragma("clang attribute pop") \250 _Pragma("clang attribute pop") \251 _Pragma("clang attribute pop")252# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \253 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \254 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) || \255 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000)256# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem257# endif258 259# define _LIBCUDACXX_AVAILABILITY_TO_CHARS_FLOATING_POINT \260 __attribute__((unavailable))261 262# define _LIBCUDACXX_AVAILABILITY_SYNC \263 __attribute__((availability(macos,strict,introduced=11.0))) \264 __attribute__((availability(ios,strict,introduced=14.0))) \265 __attribute__((availability(tvos,strict,introduced=14.0))) \266 __attribute__((availability(watchos,strict,introduced=7.0)))267# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \268 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \269 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 140000) || \270 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000)271# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait272# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier273# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_latch274# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore275# endif276 277# define _LIBCUDACXX_AVAILABILITY_FORMAT \278 __attribute__((unavailable))279# define _LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_format280 281# define _LIBCUDACXX_HAS_NO_VERBOSE_ABORT_IN_LIBRARY282 283#else284 285// ...New vendors can add availability markup here...286 287# error "It looks like you're trying to enable vendor availability markup, but you haven't defined the corresponding macros yet!"288 289#endif290 291// Define availability attributes that depend on _LIBCUDACXX_NO_EXCEPTIONS.292// Those are defined in terms of the availability attributes above, and293// should not be vendor-specific.294#if defined(_LIBCUDACXX_NO_EXCEPTIONS)295# define _LIBCUDACXX_AVAILABILITY_FUTURE296# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_ANY_CAST297# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS298# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_VARIANT_ACCESS299#else300# define _LIBCUDACXX_AVAILABILITY_FUTURE _LIBCUDACXX_AVAILABILITY_FUTURE_ERROR301# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_ANY_CAST _LIBCUDACXX_AVAILABILITY_BAD_ANY_CAST302# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS _LIBCUDACXX_AVAILABILITY_BAD_OPTIONAL_ACCESS303# define _LIBCUDACXX_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCUDACXX_AVAILABILITY_BAD_VARIANT_ACCESS304#endif305 306#endif // _LIBCUDACXX___AVAILABILITY307 