Skip to content

Commit 182f5e9

Browse files
authoredApr 25, 2024
[libc++] Reformulate availability in terms of LLVM releases (#87563)
To make it easier to maintain the availability macros for both upstream developers and vendors, this patch reformulates availability macros as a function of the upstream LLVM release that a feature was introduced in. This way, upstream developers can easily use the appropriate LLVM version, and vendors can simply fill in the platform version(s) in which a LLVM version landed.
1 parent 584a9bf commit 182f5e9

File tree

1 file changed

+226
-189
lines changed

1 file changed

+226
-189
lines changed
 

‎libcxx/include/__availability

Lines changed: 226 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,32 @@
2828
// that previously released library. Normally, this would be a load-time error
2929
// when one tries to launch the program against the older library.
3030
//
31-
// For example, the filesystem library was introduced in the dylib in macOS 10.15.
32-
// If a user compiles on a macOS 10.15 host but targets macOS 10.13 with their
33-
// program, the compiler would normally not complain (because the required
34-
// declarations are in the headers), but the dynamic loader would fail to find
35-
// the symbols when actually trying to launch the program on macOS 10.13. To
36-
// turn this into a compile-time issue instead, declarations are annotated with
37-
// when they were introduced, and the compiler can produce a diagnostic if the
38-
// program references something that isn't available on the deployment target.
31+
// For example, the filesystem library was introduced in the dylib in LLVM 9.
32+
// On Apple platforms, this corresponds to macOS 10.15. If a user compiles on
33+
// a macOS 10.15 host but targets macOS 10.13 with their program, the compiler
34+
// would normally not complain (because the required declarations are in the
35+
// headers), but the dynamic loader would fail to find the symbols when actually
36+
// trying to launch the program on macOS 10.13. To turn this into a compile-time
37+
// issue instead, declarations are annotated with when they were introduced, and
38+
// the compiler can produce a diagnostic if the program references something that
39+
// isn't available on the deployment target.
3940
//
4041
// This mechanism is general in nature, and any vendor can add their markup to
4142
// the library (see below). Whenever a new feature is added that requires support
4243
// in the shared library, two macros are added below to allow marking the feature
4344
// as unavailable:
44-
// 1. A macro named `_LIBCPP_AVAILABILITY_HAS_NO_<feature>` which must be defined
45-
// exactly when compiling for a target that doesn't support the feature.
46-
// 2. A macro named `_LIBCPP_AVAILABILITY_<feature>`, which must always be defined
47-
// and must expand to the proper availability attribute for the platform.
45+
// 1. A macro named `_LIBCPP_AVAILABILITY_HAS_<feature>` which must be defined
46+
// to `_LIBCPP_INTRODUCED_IN_<version>` for the appropriate LLVM version.
47+
// 2. A macro named `_LIBCPP_AVAILABILITY_<feature>`, which must be defined to
48+
// `_LIBCPP_INTRODUCED_IN_<version>_MARKUP` for the appropriate LLVM version.
4849
//
4950
// When vendors decide to ship the feature as part of their shared library, they
50-
// can update these macros appropriately for their platform, and the library will
51-
// use those to provide an optimal user experience.
51+
// can update the `_LIBCPP_INTRODUCED_IN_<version>` macro (and the markup counterpart)
52+
// based on the platform version they shipped that version of LLVM in. The library
53+
// will then use this markup to provide an optimal user experience on these platforms.
5254
//
5355
// Furthermore, many features in the standard library have corresponding
54-
// feature-test macros. The `_LIBCPP_AVAILABILITY_HAS_NO_<feature>` macros
56+
// feature-test macros. The `_LIBCPP_AVAILABILITY_HAS_<feature>` macros
5557
// are checked by the corresponding feature-test macros generated by
5658
// generate_feature_test_macro_components.py to ensure that the library
5759
// doesn't announce a feature as being implemented if it is unavailable on
@@ -74,237 +76,181 @@
7476

7577
// Availability markup is disabled when building the library, or when a non-Clang
7678
// compiler is used because only Clang supports the necessary attributes.
77-
// doesn't support the proper attributes.
7879
#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || !defined(_LIBCPP_COMPILER_CLANG_BASED)
7980
# if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
8081
# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
8182
# endif
8283
#endif
8384

85+
// When availability annotations are disabled, we take for granted that features introduced
86+
// in all versions of the library are available.
8487
#if defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
8588

86-
// These macros control the availability of std::bad_optional_access and
87-
// other exception types. These were put in the shared library to prevent
88-
// code bloat from every user program defining the vtable for these exception
89-
// types.
90-
//
91-
// Note that when exceptions are disabled, the methods that normally throw
92-
// these exceptions can be used even on older deployment targets, but those
93-
// methods will abort instead of throwing.
94-
# define _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS 1
95-
# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
96-
97-
# define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS 1
98-
# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
89+
# define _LIBCPP_INTRODUCED_IN_LLVM_4 1
90+
# define _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP /* nothing */
9991

100-
# define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST 1
101-
# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST
92+
# define _LIBCPP_INTRODUCED_IN_LLVM_9 1
93+
# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP /* nothing */
94+
# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_PUSH /* nothing */
95+
# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_POP /* nothing */
10296

103-
// These macros control the availability of all parts of <filesystem> that
104-
// depend on something in the dylib.
105-
# define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 1
106-
# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
107-
# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
108-
# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
97+
# define _LIBCPP_INTRODUCED_IN_LLVM_10 1
98+
# define _LIBCPP_INTRODUCED_IN_LLVM_10_MARKUP /* nothing */
10999

110-
// This controls the availability of the C++20 synchronization library,
111-
// which requires shared library support for various operations
112-
// (see libcxx/src/atomic.cpp). This includes <barier>, <latch>,
113-
// <semaphore>, and notification functions on std::atomic.
114-
# define _LIBCPP_AVAILABILITY_HAS_SYNC 1
115-
# define _LIBCPP_AVAILABILITY_SYNC
100+
# define _LIBCPP_INTRODUCED_IN_LLVM_12 1
101+
# define _LIBCPP_INTRODUCED_IN_LLVM_12_MARKUP /* nothing */
116102

117-
// Enable additional explicit instantiations of iostreams components. This
118-
// reduces the number of weak definitions generated in programs that use
119-
// iostreams by providing a single strong definition in the shared library.
120-
//
121-
// TODO: Enable additional explicit instantiations on GCC once it supports exclude_from_explicit_instantiation,
122-
// or once libc++ doesn't use the attribute anymore.
123-
// TODO: Enable them on Windows once https://llvm.org/PR41018 has been fixed.
124-
# if !defined(_LIBCPP_COMPILER_GCC) && !defined(_WIN32)
125-
# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 1
126-
# else
127-
# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0
128-
# endif
103+
# define _LIBCPP_INTRODUCED_IN_LLVM_14 1
104+
# define _LIBCPP_INTRODUCED_IN_LLVM_14_MARKUP /* nothing */
129105

130-
// This controls the availability of floating-point std::to_chars functions.
131-
// These overloads were added later than the integer overloads.
132-
# define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT 1
133-
# define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
106+
# define _LIBCPP_INTRODUCED_IN_LLVM_15 1
107+
# define _LIBCPP_INTRODUCED_IN_LLVM_15_MARKUP /* nothing */
134108

135-
// This controls whether the library claims to provide a default verbose
136-
// termination function, and consequently whether the headers will try
137-
// to use it when the mechanism isn't overriden at compile-time.
138-
# define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT 1
139-
# define _LIBCPP_AVAILABILITY_VERBOSE_ABORT
109+
# define _LIBCPP_INTRODUCED_IN_LLVM_16 1
110+
# define _LIBCPP_INTRODUCED_IN_LLVM_16_MARKUP /* nothing */
140111

141-
// This controls the availability of the C++17 std::pmr library,
142-
// which is implemented in large part in the built library.
143-
# define _LIBCPP_AVAILABILITY_HAS_PMR 1
144-
# define _LIBCPP_AVAILABILITY_PMR
112+
# define _LIBCPP_INTRODUCED_IN_LLVM_18 1
113+
# define _LIBCPP_INTRODUCED_IN_LLVM_18_MARKUP /* nothing */
145114

146-
// These macros controls the availability of __cxa_init_primary_exception
147-
// in the built library, which std::make_exception_ptr might use
148-
// (see libcxx/include/__exception/exception_ptr.h).
149-
# define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION 1
150-
# define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION
151-
152-
// This controls the availability of C++23 <print>, which
153-
// has a dependency on the built library (it needs access to
154-
// the underlying buffer types of std::cout, std::cerr, and std::clog.
155-
# define _LIBCPP_AVAILABILITY_HAS_PRINT 1
156-
# define _LIBCPP_AVAILABILITY_PRINT
157-
158-
// This controls the availability of the C++20 time zone database.
159-
// The parser code is built in the library.
160-
# define _LIBCPP_AVAILABILITY_HAS_TZDB 1
161-
# define _LIBCPP_AVAILABILITY_TZDB
162-
163-
// These macros determine whether we assume that std::bad_function_call and
164-
// std::bad_expected_access provide a key function in the dylib. This allows
165-
// centralizing their vtable and typeinfo instead of having all TUs provide
166-
// a weak definition that then gets deduplicated.
167-
# define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_KEY_FUNCTION 1
168-
# define _LIBCPP_AVAILABILITY_BAD_FUNCTION_CALL_KEY_FUNCTION
169-
# define _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION 1
170-
# define _LIBCPP_AVAILABILITY_BAD_EXPECTED_ACCESS_KEY_FUNCTION
115+
# define _LIBCPP_INTRODUCED_IN_LLVM_19 1
116+
# define _LIBCPP_INTRODUCED_IN_LLVM_19_MARKUP /* nothing */
171117

172118
#elif defined(__APPLE__)
173119

174-
# define _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS \
175-
(!defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) || __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 50000)
176-
177-
# define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS
178-
# define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS
179-
180-
# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS __attribute__((availability(watchos, strict, introduced = 5.0)))
181-
# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
182-
# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
183-
184-
// TODO: Update once this is released
185-
# define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION 0
186-
# define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION __attribute__((unavailable))
120+
// LLVM 4
121+
# if defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000
122+
# define _LIBCPP_INTRODUCED_IN_LLVM_4 0
123+
# define _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP __attribute__((availability(watchos, strict, introduced = 5.0)))
124+
# else
125+
# define _LIBCPP_INTRODUCED_IN_LLVM_4 1
126+
# define _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP /* nothing */
127+
# endif
187128

188-
// <filesystem>
129+
// LLVM 9
189130
// clang-format off
190131
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
191132
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \
192133
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) || \
193134
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000)
194135
// clang-format on
195-
# define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 0
136+
# define _LIBCPP_INTRODUCED_IN_LLVM_9 0
137+
# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP \
138+
__attribute__((availability(macos, strict, introduced = 10.15))) \
139+
__attribute__((availability(ios, strict, introduced = 13.0))) \
140+
__attribute__((availability(tvos, strict, introduced = 13.0))) \
141+
__attribute__((availability(watchos, strict, introduced = 6.0)))
142+
// clang-format off
143+
# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_PUSH \
144+
_Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \
145+
_Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \
146+
_Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \
147+
_Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))")
148+
# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_POP \
149+
_Pragma("clang attribute pop") \
150+
_Pragma("clang attribute pop") \
151+
_Pragma("clang attribute pop") \
152+
_Pragma("clang attribute pop")
153+
// clang-format on
196154
# else
197-
# define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 1
155+
# define _LIBCPP_INTRODUCED_IN_LLVM_9 1
156+
# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP /* nothing */
157+
# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_PUSH /* nothing */
158+
# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_POP /* nothing */
198159
# endif
199-
# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY \
200-
__attribute__((availability(macos, strict, introduced = 10.15))) \
201-
__attribute__((availability(ios, strict, introduced = 13.0))) \
202-
__attribute__((availability(tvos, strict, introduced = 13.0))) \
203-
__attribute__((availability(watchos, strict, introduced = 6.0)))
160+
161+
// LLVM 10
204162
// clang-format off
205-
# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH \
206-
_Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \
207-
_Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \
208-
_Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \
209-
_Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))")
210-
# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP \
211-
_Pragma("clang attribute pop") \
212-
_Pragma("clang attribute pop") \
213-
_Pragma("clang attribute pop") \
214-
_Pragma("clang attribute pop")
163+
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \
164+
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \
165+
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 140000) || \
166+
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000)
215167
// clang-format on
168+
# define _LIBCPP_INTRODUCED_IN_LLVM_10 0
169+
# define _LIBCPP_INTRODUCED_IN_LLVM_10_MARKUP \
170+
__attribute__((availability(macos, strict, introduced = 11.0))) \
171+
__attribute__((availability(ios, strict, introduced = 14.0))) \
172+
__attribute__((availability(tvos, strict, introduced = 14.0))) \
173+
__attribute__((availability(watchos, strict, introduced = 7.0)))
174+
# else
175+
# define _LIBCPP_INTRODUCED_IN_LLVM_10 1
176+
# define _LIBCPP_INTRODUCED_IN_LLVM_10_MARKUP /* nothing */
177+
# endif
216178

217-
// std::to_chars(floating-point)
179+
// LLVM 12
218180
// clang-format off
219-
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130300) || \
220-
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160300) || \
221-
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160300) || \
222-
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90300)
181+
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120000) || \
182+
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150000) || \
183+
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150000) || \
184+
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80000)
223185
// clang-format on
224-
# define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT 0
186+
# define _LIBCPP_INTRODUCED_IN_LLVM_12 0
187+
# define _LIBCPP_INTRODUCED_IN_LLVM_12_MARKUP \
188+
__attribute__((availability(macos, strict, introduced = 12.0))) \
189+
__attribute__((availability(ios, strict, introduced = 15.0))) \
190+
__attribute__((availability(tvos, strict, introduced = 15.0))) \
191+
__attribute__((availability(watchos, strict, introduced = 8.0)))
225192
# else
226-
# define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT 1
193+
# define _LIBCPP_INTRODUCED_IN_LLVM_12 1
194+
# define _LIBCPP_INTRODUCED_IN_LLVM_12_MARKUP /* nothing */
227195
# endif
228-
# define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT \
229-
__attribute__((availability(macos, strict, introduced = 13.3))) \
230-
__attribute__((availability(ios, strict, introduced = 16.3))) \
231-
__attribute__((availability(tvos, strict, introduced = 16.3))) \
232-
__attribute__((availability(watchos, strict, introduced = 9.3)))
233196

234-
// c++20 synchronization library
197+
// LLVM 14
235198
// clang-format off
236-
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \
237-
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \
238-
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 140000) || \
239-
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000)
199+
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130400) || \
200+
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160500) || \
201+
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160500) || \
202+
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90500)
240203
// clang-format on
241-
# define _LIBCPP_AVAILABILITY_HAS_SYNC 0
204+
# define _LIBCPP_INTRODUCED_IN_LLVM_14 0
205+
# define _LIBCPP_INTRODUCED_IN_LLVM_14_MARKUP \
206+
__attribute__((availability(macos, strict, introduced = 13.4))) \
207+
__attribute__((availability(ios, strict, introduced = 16.5))) \
208+
__attribute__((availability(tvos, strict, introduced = 16.5))) \
209+
__attribute__((availability(watchos, strict, introduced = 9.5)))
242210
# else
243-
# define _LIBCPP_AVAILABILITY_HAS_SYNC 1
211+
# define _LIBCPP_INTRODUCED_IN_LLVM_14 1
212+
# define _LIBCPP_INTRODUCED_IN_LLVM_14_MARKUP /* nothing */
244213
# endif
245-
# define _LIBCPP_AVAILABILITY_SYNC \
246-
__attribute__((availability(macos, strict, introduced = 11.0))) \
247-
__attribute__((availability(ios, strict, introduced = 14.0))) \
248-
__attribute__((availability(tvos, strict, introduced = 14.0))) \
249-
__attribute__((availability(watchos, strict, introduced = 7.0)))
250-
251-
// __libcpp_verbose_abort
252-
// TODO: Update once this is released
253-
# define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT 0
254214

255-
# define _LIBCPP_AVAILABILITY_VERBOSE_ABORT __attribute__((unavailable))
256-
257-
// std::pmr
215+
// LLVM 15-16
216+
# define _LIBCPP_INTRODUCED_IN_LLVM_15 _LIBCPP_INTRODUCED_IN_LLVM_16
217+
# define _LIBCPP_INTRODUCED_IN_LLVM_15_MARKUP _LIBCPP_INTRODUCED_IN_LLVM_16_MARKUP
258218
// clang-format off
259219
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140000) || \
260220
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170000) || \
261221
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170000) || \
262222
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100000)
263223
// clang-format on
264-
# define _LIBCPP_AVAILABILITY_HAS_PMR 0
265-
# else
266-
# define _LIBCPP_AVAILABILITY_HAS_PMR 1
267-
# endif
268-
// TODO: Enable std::pmr markup once https://github.com/llvm/llvm-project/issues/40340 has been fixed
269-
// Until then, it is possible for folks to try to use `std::pmr` when back-deploying to targets that don't support
270-
// it and it'll be a load-time error, but we don't have a good alternative because the library won't compile if we
271-
// use availability annotations until that bug has been fixed.
272-
# if 0
273-
# define _LIBCPP_AVAILABILITY_PMR \
224+
# define _LIBCPP_INTRODUCED_IN_LLVM_16 0
225+
# define _LIBCPP_INTRODUCED_IN_LLVM_16_MARKUP \
274226
__attribute__((availability(macos, strict, introduced = 14.0))) \
275227
__attribute__((availability(ios, strict, introduced = 17.0))) \
276228
__attribute__((availability(tvos, strict, introduced = 17.0))) \
277229
__attribute__((availability(watchos, strict, introduced = 10.0)))
278230
# else
279-
# define _LIBCPP_AVAILABILITY_PMR
231+
# define _LIBCPP_INTRODUCED_IN_LLVM_16 1
232+
# define _LIBCPP_INTRODUCED_IN_LLVM_16_MARKUP /* nothing */
280233
# endif
281234

282-
# define _LIBCPP_AVAILABILITY_HAS_TZDB 0
283-
# define _LIBCPP_AVAILABILITY_TZDB __attribute__((unavailable))
284-
285-
// Warning: This availability macro works differently than the other macros.
286-
// The dylib part of print is not needed on Apple platforms. Therefore when
287-
// the macro is not available the code calling the dylib is commented out.
288-
// The macro _LIBCPP_AVAILABILITY_PRINT is not used.
289-
# define _LIBCPP_AVAILABILITY_HAS_PRINT 0
290-
# define _LIBCPP_AVAILABILITY_PRINT __attribute__((unavailable))
291-
292-
// clang-format off
293-
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120000) || \
294-
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150000) || \
295-
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150000) || \
296-
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80000)
297-
// clang-format on
298-
# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0
235+
// LLVM 18
236+
// TODO: Fill this in
237+
# if 1
238+
# define _LIBCPP_INTRODUCED_IN_LLVM_18 0
239+
# define _LIBCPP_INTRODUCED_IN_LLVM_18_MARKUP __attribute__((unavailable))
299240
# else
300-
# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 1
241+
# define _LIBCPP_INTRODUCED_IN_LLVM_18 1
242+
# define _LIBCPP_INTRODUCED_IN_LLVM_18_MARKUP /* nothing */
301243
# endif
302244

303-
# define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_KEY_FUNCTION 0
304-
# define _LIBCPP_AVAILABILITY_BAD_FUNCTION_CALL_KEY_FUNCTION __attribute__((unavailable))
305-
306-
# define _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION 0
307-
# define _LIBCPP_AVAILABILITY_BAD_EXPECTED_ACCESS_KEY_FUNCTION __attribute__((unavailable))
245+
// LLVM 19
246+
// TODO: Fill this in
247+
# if 1
248+
# define _LIBCPP_INTRODUCED_IN_LLVM_19 0
249+
# define _LIBCPP_INTRODUCED_IN_LLVM_19_MARKUP __attribute__((unavailable))
250+
# else
251+
# define _LIBCPP_INTRODUCED_IN_LLVM_19 1
252+
# define _LIBCPP_INTRODUCED_IN_LLVM_19_MARKUP /* nothing */
253+
# endif
308254

309255
#else
310256

@@ -315,6 +261,97 @@
315261

316262
#endif
317263

264+
// These macros control the availability of std::bad_optional_access and
265+
// other exception types. These were put in the shared library to prevent
266+
// code bloat from every user program defining the vtable for these exception
267+
// types.
268+
//
269+
// Note that when exceptions are disabled, the methods that normally throw
270+
// these exceptions can be used even on older deployment targets, but those
271+
// methods will abort instead of throwing.
272+
#define _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4
273+
#define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP
274+
275+
#define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4
276+
#define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP
277+
278+
#define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST _LIBCPP_INTRODUCED_IN_LLVM_4
279+
#define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP
280+
281+
// These macros control the availability of all parts of <filesystem> that
282+
// depend on something in the dylib.
283+
#define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY _LIBCPP_INTRODUCED_IN_LLVM_9
284+
#define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP
285+
#define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_PUSH
286+
#define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_POP
287+
288+
// This controls the availability of the C++20 synchronization library,
289+
// which requires shared library support for various operations
290+
// (see libcxx/src/atomic.cpp). This includes <barier>, <latch>,
291+
// <semaphore>, and notification functions on std::atomic.
292+
#define _LIBCPP_AVAILABILITY_HAS_SYNC _LIBCPP_INTRODUCED_IN_LLVM_10
293+
#define _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INTRODUCED_IN_LLVM_10_MARKUP
294+
295+
// Enable additional explicit instantiations of iostreams components. This
296+
// reduces the number of weak definitions generated in programs that use
297+
// iostreams by providing a single strong definition in the shared library.
298+
//
299+
// TODO: Enable additional explicit instantiations on GCC once it supports exclude_from_explicit_instantiation,
300+
// or once libc++ doesn't use the attribute anymore.
301+
// TODO: Enable them on Windows once https://llvm.org/PR41018 has been fixed.
302+
#if !defined(_LIBCPP_COMPILER_GCC) && !defined(_WIN32)
303+
# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 _LIBCPP_INTRODUCED_IN_LLVM_12
304+
#else
305+
# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0
306+
#endif
307+
308+
// This controls the availability of floating-point std::to_chars functions.
309+
// These overloads were added later than the integer overloads.
310+
#define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14
311+
#define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14_MARKUP
312+
313+
// This controls whether the library claims to provide a default verbose
314+
// termination function, and consequently whether the headers will try
315+
// to use it when the mechanism isn't overriden at compile-time.
316+
#define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15
317+
#define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15_MARKUP
318+
319+
// This controls the availability of the C++17 std::pmr library,
320+
// which is implemented in large part in the built library.
321+
//
322+
// TODO: Enable std::pmr markup once https://github.com/llvm/llvm-project/issues/40340 has been fixed
323+
// Until then, it is possible for folks to try to use `std::pmr` when back-deploying to targets that don't support
324+
// it and it'll be a load-time error, but we don't have a good alternative because the library won't compile if we
325+
// use availability annotations until that bug has been fixed.
326+
#define _LIBCPP_AVAILABILITY_HAS_PMR _LIBCPP_INTRODUCED_IN_LLVM_16
327+
#define _LIBCPP_AVAILABILITY_PMR
328+
329+
// These macros controls the availability of __cxa_init_primary_exception
330+
// in the built library, which std::make_exception_ptr might use
331+
// (see libcxx/include/__exception/exception_ptr.h).
332+
#define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18
333+
#define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18_MARKUP
334+
335+
// This controls the availability of C++23 <print>, which
336+
// has a dependency on the built library (it needs access to
337+
// the underlying buffer types of std::cout, std::cerr, and std::clog.
338+
#define _LIBCPP_AVAILABILITY_HAS_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18
339+
#define _LIBCPP_AVAILABILITY_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18_MARKUP
340+
341+
// This controls the availability of the C++20 time zone database.
342+
// The parser code is built in the library.
343+
#define _LIBCPP_AVAILABILITY_HAS_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19
344+
#define _LIBCPP_AVAILABILITY_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19_MARKUP
345+
346+
// These macros determine whether we assume that std::bad_function_call and
347+
// std::bad_expected_access provide a key function in the dylib. This allows
348+
// centralizing their vtable and typeinfo instead of having all TUs provide
349+
// a weak definition that then gets deduplicated.
350+
# define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19
351+
# define _LIBCPP_AVAILABILITY_BAD_FUNCTION_CALL_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_MARKUP
352+
# define _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19
353+
# define _LIBCPP_AVAILABILITY_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_MARKUP
354+
318355
// Define availability attributes that depend on _LIBCPP_HAS_NO_EXCEPTIONS.
319356
// Those are defined in terms of the availability attributes above, and
320357
// should not be vendor-specific.

0 commit comments

Comments
 (0)
Please sign in to comment.