Skip to content

Commit bec96f6

Browse files
committed
[libc++] Systematically define a macro to check whether a feature is unavailable
Previously, we inconsistently defined whether a feature was unavailable on a given deployment target. We would have availability attributes for all features, but only some features had the equivalent of a _HAS_NO_FOO macro in the form of the DISABLE_FTM___foo macros. Instead, systematically define a _HAS_NO_FOO macro, which makes it easier to understand how to add availability markup for a new platform. Differential Revision: https://reviews.llvm.org/D147226
1 parent b060ca7 commit bec96f6

13 files changed

+216
-144
lines changed

libcxx/include/__availability

Lines changed: 108 additions & 40 deletions
Large diffs are not rendered by default.

libcxx/include/__verbose_abort

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121

2222
// This function should never be called directly from the code -- it should only be called through
2323
// the _LIBCPP_VERBOSE_ABORT macro.
24-
_LIBCPP_NORETURN _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2)
24+
_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2)
2525
void __libcpp_verbose_abort(const char *__format, ...);
2626

2727
// _LIBCPP_VERBOSE_ABORT(format, args...)
@@ -40,17 +40,19 @@ void __libcpp_verbose_abort(const char *__format, ...);
4040

4141
// Support _LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED until LLVM 18, but tell people
4242
// to move to customizing _LIBCPP_VERBOSE_ABORT instead.
43-
# if defined(_LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY) && defined(_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED)
44-
# undef _LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY
43+
# if defined(_LIBCPP_AVAILABILITY_HAS_NO_VERBOSE_ABORT) && defined(_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED)
44+
# undef _LIBCPP_AVAILABILITY_HAS_NO_VERBOSE_ABORT
4545
# warning _LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED is deprecated, please customize _LIBCPP_VERBOSE_ABORT instead
4646
# endif
4747

48-
# if defined(_LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY)
48+
# if defined(_LIBCPP_AVAILABILITY_HAS_NO_VERBOSE_ABORT)
4949
// The decltype is there to suppress -Wunused warnings in this configuration.
50-
# define _LIBCPP_VERBOSE_ABORT(...) (decltype(std::__libcpp_verbose_abort(__VA_ARGS__))(), __builtin_abort())
50+
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR void __use(const char*, ...) { }
51+
# define _LIBCPP_VERBOSE_ABORT(...) (decltype(::std::__use(__VA_ARGS__))(), __builtin_abort())
5152
# else
5253
# define _LIBCPP_VERBOSE_ABORT(...) ::std::__libcpp_verbose_abort(__VA_ARGS__)
5354
# endif
55+
5456
#endif // !defined(_LIBCPP_VERBOSE_ABORT)
5557

5658
_LIBCPP_END_NAMESPACE_STD

libcxx/include/version

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ __cpp_lib_void_t 201411L <type_traits>
225225
# define __cpp_lib_quoted_string_io 201304L
226226
# define __cpp_lib_result_of_sfinae 201210L
227227
# define __cpp_lib_robust_nonmodifying_seq_ops 201304L
228-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex)
228+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SHARED_MUTEX)
229229
# define __cpp_lib_shared_timed_mutex 201402L
230230
# endif
231231
# define __cpp_lib_string_udls 201304L
@@ -250,7 +250,7 @@ __cpp_lib_void_t 201411L <type_traits>
250250
# define __cpp_lib_clamp 201603L
251251
# define __cpp_lib_enable_shared_from_this 201603L
252252
// # define __cpp_lib_execution 201603L
253-
# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem)
253+
# if !defined(_LIBCPP_AVAILABILITY_HAS_NO_FILESYSTEM)
254254
# define __cpp_lib_filesystem 201703L
255255
# endif
256256
# define __cpp_lib_gcd_lcm 201606L
@@ -278,7 +278,7 @@ __cpp_lib_void_t 201411L <type_traits>
278278
# define __cpp_lib_raw_memory_algorithms 201606L
279279
# define __cpp_lib_sample 201603L
280280
# define __cpp_lib_scoped_lock 201703L
281-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex)
281+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SHARED_MUTEX)
282282
# define __cpp_lib_shared_mutex 201505L
283283
# endif
284284
# define __cpp_lib_shared_ptr_arrays 201611L
@@ -304,10 +304,10 @@ __cpp_lib_void_t 201411L <type_traits>
304304
// # define __cpp_lib_atomic_ref 201806L
305305
// # define __cpp_lib_atomic_shared_ptr 201711L
306306
# define __cpp_lib_atomic_value_initialization 201911L
307-
# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)
307+
# if !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
308308
# define __cpp_lib_atomic_wait 201907L
309309
# endif
310-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier)
310+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
311311
# define __cpp_lib_barrier 201907L
312312
# endif
313313
# define __cpp_lib_bind_front 201907L
@@ -338,7 +338,7 @@ __cpp_lib_void_t 201411L <type_traits>
338338
# define __cpp_lib_erase_if 202002L
339339
# undef __cpp_lib_execution
340340
// # define __cpp_lib_execution 201902L
341-
# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
341+
# if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
342342
// # define __cpp_lib_format 202106L
343343
# endif
344344
# define __cpp_lib_generic_unordered_lookup 201811L
@@ -352,7 +352,7 @@ __cpp_lib_void_t 201411L <type_traits>
352352
# if !defined(_LIBCPP_HAS_NO_THREADS)
353353
// # define __cpp_lib_jthread 201911L
354354
# endif
355-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_latch)
355+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
356356
# define __cpp_lib_latch 201907L
357357
# endif
358358
# define __cpp_lib_list_remove_return_type 201806L
@@ -361,7 +361,7 @@ __cpp_lib_void_t 201411L <type_traits>
361361
# define __cpp_lib_polymorphic_allocator 201902L
362362
# define __cpp_lib_ranges 202106L
363363
# define __cpp_lib_remove_cvref 201711L
364-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore)
364+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
365365
# define __cpp_lib_semaphore 201907L
366366
# endif
367367
# undef __cpp_lib_shared_ptr_arrays

libcxx/test/libcxx/assertions/deprecated-link-time-custom-handler.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// XFAIL: availability-verbose_abort-missing
10+
911
// Make sure that we still support _LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED for folks
1012
// who customize the verbose termination function at link-time in back-deployment environments.
1113

libcxx/test/libcxx/assertions/headers_declare_verbose_abort.sh.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// The system-provided <uchar.h> seems to be broken on AIX, which trips up this test.
1414
// XFAIL: LIBCXX-AIX-FIXME
1515

16+
// XFAIL: availability-verbose_abort-missing
17+
1618
/*
1719
BEGIN-SCRIPT
1820

libcxx/test/std/language.support/support.limits/support.limits.general/atomic.version.compile.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
# error "__cpp_lib_atomic_value_initialization should have the value 201911L in c++20"
217217
# endif
218218

219-
# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)
219+
# if !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
220220
# ifndef __cpp_lib_atomic_wait
221221
# error "__cpp_lib_atomic_wait should be defined in c++20"
222222
# endif
@@ -225,7 +225,7 @@
225225
# endif
226226
# else
227227
# ifdef __cpp_lib_atomic_wait
228-
# error "__cpp_lib_atomic_wait should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)' is not met!"
228+
# error "__cpp_lib_atomic_wait should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)' is not met!"
229229
# endif
230230
# endif
231231

@@ -311,7 +311,7 @@
311311
# error "__cpp_lib_atomic_value_initialization should have the value 201911L in c++2b"
312312
# endif
313313

314-
# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)
314+
# if !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
315315
# ifndef __cpp_lib_atomic_wait
316316
# error "__cpp_lib_atomic_wait should be defined in c++2b"
317317
# endif
@@ -320,7 +320,7 @@
320320
# endif
321321
# else
322322
# ifdef __cpp_lib_atomic_wait
323-
# error "__cpp_lib_atomic_wait should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)' is not met!"
323+
# error "__cpp_lib_atomic_wait should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)' is not met!"
324324
# endif
325325
# endif
326326

libcxx/test/std/language.support/support.limits/support.limits.general/barrier.version.compile.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
#elif TEST_STD_VER == 20
4646

47-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier)
47+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
4848
# ifndef __cpp_lib_barrier
4949
# error "__cpp_lib_barrier should be defined in c++20"
5050
# endif
@@ -53,13 +53,13 @@
5353
# endif
5454
# else
5555
# ifdef __cpp_lib_barrier
56-
# error "__cpp_lib_barrier should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier)' is not met!"
56+
# error "__cpp_lib_barrier should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)' is not met!"
5757
# endif
5858
# endif
5959

6060
#elif TEST_STD_VER > 20
6161

62-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier)
62+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
6363
# ifndef __cpp_lib_barrier
6464
# error "__cpp_lib_barrier should be defined in c++2b"
6565
# endif
@@ -68,7 +68,7 @@
6868
# endif
6969
# else
7070
# ifdef __cpp_lib_barrier
71-
# error "__cpp_lib_barrier should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier)' is not met!"
71+
# error "__cpp_lib_barrier should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)' is not met!"
7272
# endif
7373
# endif
7474

libcxx/test/std/language.support/support.limits/support.limits.general/filesystem.version.compile.pass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# error "__cpp_lib_char8_t should not be defined before c++20"
5252
# endif
5353

54-
# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem)
54+
# if !defined(_LIBCPP_AVAILABILITY_HAS_NO_FILESYSTEM)
5555
# ifndef __cpp_lib_filesystem
5656
# error "__cpp_lib_filesystem should be defined in c++17"
5757
# endif
@@ -60,7 +60,7 @@
6060
# endif
6161
# else
6262
# ifdef __cpp_lib_filesystem
63-
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem)' is not met!"
63+
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_HAS_NO_FILESYSTEM)' is not met!"
6464
# endif
6565
# endif
6666

@@ -79,7 +79,7 @@
7979
# endif
8080
# endif
8181

82-
# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem)
82+
# if !defined(_LIBCPP_AVAILABILITY_HAS_NO_FILESYSTEM)
8383
# ifndef __cpp_lib_filesystem
8484
# error "__cpp_lib_filesystem should be defined in c++20"
8585
# endif
@@ -88,7 +88,7 @@
8888
# endif
8989
# else
9090
# ifdef __cpp_lib_filesystem
91-
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem)' is not met!"
91+
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_HAS_NO_FILESYSTEM)' is not met!"
9292
# endif
9393
# endif
9494

@@ -107,7 +107,7 @@
107107
# endif
108108
# endif
109109

110-
# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem)
110+
# if !defined(_LIBCPP_AVAILABILITY_HAS_NO_FILESYSTEM)
111111
# ifndef __cpp_lib_filesystem
112112
# error "__cpp_lib_filesystem should be defined in c++2b"
113113
# endif
@@ -116,7 +116,7 @@
116116
# endif
117117
# else
118118
# ifdef __cpp_lib_filesystem
119-
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem)' is not met!"
119+
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_AVAILABILITY_HAS_NO_FILESYSTEM)' is not met!"
120120
# endif
121121
# endif
122122

libcxx/test/std/language.support/support.limits/support.limits.general/latch.version.compile.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
#elif TEST_STD_VER == 20
4646

47-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_latch)
47+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
4848
# ifndef __cpp_lib_latch
4949
# error "__cpp_lib_latch should be defined in c++20"
5050
# endif
@@ -53,13 +53,13 @@
5353
# endif
5454
# else
5555
# ifdef __cpp_lib_latch
56-
# error "__cpp_lib_latch should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_latch)' is not met!"
56+
# error "__cpp_lib_latch should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)' is not met!"
5757
# endif
5858
# endif
5959

6060
#elif TEST_STD_VER > 20
6161

62-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_latch)
62+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
6363
# ifndef __cpp_lib_latch
6464
# error "__cpp_lib_latch should be defined in c++2b"
6565
# endif
@@ -68,7 +68,7 @@
6868
# endif
6969
# else
7070
# ifdef __cpp_lib_latch
71-
# error "__cpp_lib_latch should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_latch)' is not met!"
71+
# error "__cpp_lib_latch should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)' is not met!"
7272
# endif
7373
# endif
7474

libcxx/test/std/language.support/support.limits/support.limits.general/semaphore.version.compile.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
#elif TEST_STD_VER == 20
4646

47-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore)
47+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
4848
# ifndef __cpp_lib_semaphore
4949
# error "__cpp_lib_semaphore should be defined in c++20"
5050
# endif
@@ -53,13 +53,13 @@
5353
# endif
5454
# else
5555
# ifdef __cpp_lib_semaphore
56-
# error "__cpp_lib_semaphore should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore)' is not met!"
56+
# error "__cpp_lib_semaphore should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)' is not met!"
5757
# endif
5858
# endif
5959

6060
#elif TEST_STD_VER > 20
6161

62-
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore)
62+
# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)
6363
# ifndef __cpp_lib_semaphore
6464
# error "__cpp_lib_semaphore should be defined in c++2b"
6565
# endif
@@ -68,7 +68,7 @@
6868
# endif
6969
# else
7070
# ifdef __cpp_lib_semaphore
71-
# error "__cpp_lib_semaphore should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore)' is not met!"
71+
# error "__cpp_lib_semaphore should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_HAS_NO_SYNC)' is not met!"
7272
# endif
7373
# endif
7474

0 commit comments

Comments
 (0)