llvm-project/libcxx/include
Louis Dionne b0fd9497af [libc++] Add a lightweight overridable assertion handler
This patch adds a lightweight assertion handler mechanism that can be
overriden at link-time in a fashion similar to `operator new`.

This is a third take on https://llvm.org/D121123 (which allowed customizing
the assertion handler at compile-time), and https://llvm.org/D119969
(which allowed customizing the assertion handler at runtime only).

This approach is, I think, the best of all three explored approaches.
Indeed, replacing the assertion handler in user code is ergonomic,
yet we retain the ability to provide a custom assertion handler when
deploying to older platforms that don't have a default handler in
the dylib.

As-is, this patch provides a pretty good amount of backwards compatibility
with the previous debug mode:

- Code that used to set _LIBCPP_DEBUG=0 in order to get basic assertions
  in their code will still get basic assertions out of the box, but
  those assertions will be using the new assertion handler support.
- Code that was previously compiled with references to __libcpp_debug_function
  and friends will work out-of-the-box, no changes required. This is
  because we provide the same symbols in the dylib as we used to.
- Code that used to set a custom __libcpp_debug_function will stop
  compiling, because we don't provide that declaration anymore. Users
  will have to migrate to the new way of setting a custom assertion
  handler, which is extremely easy. I suspect that pool of users is
  very limited, so breaking them at compile-time is probably acceptable.

The main downside of this approach is that code being compiled with
assertions enabled but deploying to an older platform where the assertion
handler didn't exist yet will fail to compile. However users can easily
fix the problem by providing a custom assertion handler and defining
the _LIBCPP_AVAILABILITY_CUSTOM_ASSERTION_HANDLER_PROVIDED macro to
let the library know about the custom handler. In a way, this is
actually a feature because it avoids a load-time error that one would
otherwise get when trying to run the code on the older target.

Differential Revision: https://reviews.llvm.org/D121478
2022-03-23 15:35:46 -04:00
..
__algorithm [libc++][ranges] Implement ranges::min 2022-03-18 12:52:21 +01:00
__bit [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
__charconv [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__chrono [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__compare [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
__concepts [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
__coroutine [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__filesystem [libc++] Make __dir_stream visibility declaration consistent 2022-03-15 19:30:35 +01:00
__format [libc++] Add missing <cstddef> include 2022-03-17 17:07:37 -04:00
__functional [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
__ios [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__iterator [libc++][ranges] Implement changes to reverse_iterator from One Ranges Proposal. 2022-03-17 19:58:03 -07:00
__memory [libc++] Make shared_ptr move unique_ptr's deleter 2022-03-18 11:50:31 -06:00
__numeric [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__random [libc++] Define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER whenever we enable warnings in the test suite 2022-03-15 17:17:54 -04:00
__ranges [libc++][NFC] Use struct instead of class for ranges::end 2022-03-22 15:36:47 -04:00
__support [libc++] Remove the ability to use the std::nullptr_t emulation in C++03 mode 2022-02-07 17:51:05 -05:00
__thread [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__utility [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
__variant [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
experimental [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
ext [libc++] Use -I instead of -isystem to include headers in the test suite 2022-03-03 13:19:47 +01:00
CMakeLists.txt [libc++][ranges] Implement ranges::min 2022-03-18 12:52:21 +01:00
__assert [libc++] Add a lightweight overridable assertion handler 2022-03-23 15:35:46 -04:00
__availability [libc++] Add a lightweight overridable assertion handler 2022-03-23 15:35:46 -04:00
__bit_reference [libc++] Add `explicit` to a bunch of internal detail ctors. 2022-03-01 14:37:06 -05:00
__bits [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__bsd_locale_defaults.h [libc++][NFC] Fix include guards and add a missing license header 2022-03-23 13:14:19 -04:00
__bsd_locale_fallbacks.h [libc++][NFC] Fix include guards and add a missing license header 2022-03-23 13:14:19 -04:00
__config [libc++][NFC] Fix include guards and add a missing license header 2022-03-23 13:14:19 -04:00
__config_site.in [libc++] Add a lightweight overridable assertion handler 2022-03-23 15:35:46 -04:00
__debug [libc++][NFC] Fix include guards and add a missing license header 2022-03-23 13:14:19 -04:00
__errc [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
__hash_table [libc++][NFC] Fix include guards and add a missing license header 2022-03-23 13:14:19 -04:00
__libcpp_version Bump the trunk major version to 15 2022-02-01 23:54:52 -08:00
__locale [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
__mbstate_t.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
__mutex_base [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__node_handle [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__split_buffer [libc++][NFC] Fix include guards and add a missing license header 2022-03-23 13:14:19 -04:00
__std_stream [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__string [libc++] Remove raw call to debug handler from __char_traits_length_checked 2022-03-11 09:05:29 -05:00
__threading_support [libc++][NFC] Fix include guards and add a missing license header 2022-03-23 13:14:19 -04:00
__tree [libc++] Granularize <utility> includes 2022-03-05 19:31:46 +01:00
__tuple [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
__undef_macros [runtimes][NFC] Remove filenames at the top of the license notice 2021-11-17 16:30:52 -05:00
algorithm [libc++][ranges] Implement ranges::min 2022-03-18 12:52:21 +01:00
any [libc++] Define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER whenever we enable warnings in the test suite 2022-03-15 17:17:54 -04:00
array [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
atomic [libc++] Granularize chrono includes 2022-02-23 23:06:26 +01:00
barrier [libc++] Define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER whenever we enable warnings in the test suite 2022-03-15 17:17:54 -04:00
bit [libc++] [LWG3656] Update the return type of std::bit_width. 2022-03-04 17:31:09 -05:00
bitset [libc++] Define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER whenever we enable warnings in the test suite 2022-03-15 17:17:54 -04:00
cassert [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
ccomplex [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cctype [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cerrno [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cfenv [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cfloat [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
charconv [libc++] Define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER whenever we enable warnings in the test suite 2022-03-15 17:17:54 -04:00
chrono [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cinttypes [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
ciso646 [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
climits [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
clocale [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cmath [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
codecvt [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
compare [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
complex [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
complex.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
concepts [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
condition_variable [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
coroutine [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
csetjmp [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
csignal [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cstdarg [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cstdbool [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cstddef [libc++] Remove the ability to use the std::nullptr_t emulation in C++03 mode 2022-02-07 17:51:05 -05:00
cstdint [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cstdio [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cstdlib [libc++] Remove workaround for missing declarations on Windows store apps 2022-03-11 09:08:30 -05:00
cstring [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
ctgmath [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
ctime [libc++] Remove workaround for C11 features on compilers that don't support using_if_exists 2022-03-11 09:06:43 -05:00
ctype.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cuchar [libc++] Add missing header <cuchar> 2022-03-07 08:48:50 -05:00
cwchar [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
cwctype [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
deque [libc++] Granularize <utility> includes 2022-03-05 19:31:46 +01:00
errno.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
exception [libc++] Guard warning pragmas 2022-02-15 00:41:11 +01:00
execution [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
fenv.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
filesystem [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
float.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
format [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
forward_list [libc++] Granularize algorithm includes 2022-02-16 04:12:22 +01:00
fstream [libc++] Granularize <utility> includes 2022-03-05 19:31:46 +01:00
functional [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
future [libc++] Granularize <utility> includes 2022-03-05 19:31:46 +01:00
initializer_list [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
inttypes.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
iomanip [libc++] Overhaul std::quoted; fix its relationship to character traits. 2022-03-07 13:28:58 -05:00
ios [libc++] Granularize <utility> includes 2022-03-05 19:31:46 +01:00
iosfwd [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
iostream [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
istream [libc++] Define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER whenever we enable warnings in the test suite 2022-03-15 17:17:54 -04:00
iterator [libc++][ranges] Implement changes to reverse_iterator from One Ranges Proposal. 2022-03-17 19:58:03 -07:00
latch [libc++] Define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER whenever we enable warnings in the test suite 2022-03-15 17:17:54 -04:00
limits Set std::numeric_limits<>::tinyness_before to true for floating point types on ARM platforms. 2022-02-22 15:49:21 -08:00
limits.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
list [libc++] Granularize <utility> includes 2022-03-05 19:31:46 +01:00
locale [libc++] Enable modernize-loop-convert 2022-03-18 20:34:19 +01:00
locale.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
map [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
math.h [libc++][AIX] Use C++ overloads from libc++'s math.h 2022-03-01 15:53:41 -05:00
memory [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
module.modulemap [libc++][ranges] Implement ranges::min 2022-03-18 12:52:21 +01:00
mutex [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
new [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
numbers [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
numeric [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
optional [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
ostream [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
queue [libc++] Granularize algorithm includes 2022-02-16 04:12:22 +01:00
random [libc++] Explicitly reject `uniform_int_distribution<bool>` and `<char>`. 2022-02-28 14:57:53 -05:00
ranges [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
ratio [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
regex [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
scoped_allocator [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
semaphore [libc++] Granularize chrono includes 2022-02-23 23:06:26 +01:00
set [libc++] Move everything related solely to _LIBCPP_ASSERT to its own file 2022-02-16 12:49:50 -05:00
setjmp.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
shared_mutex [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
span [libc++] Re-enable workaround for pre-ranges CTAD in std::span 2022-03-21 21:56:42 -04:00
sstream [libc++] Granularize <utility> includes 2022-03-05 19:31:46 +01:00
stack [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
stdbool.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
stddef.h [libc++] Remove the ability to use the std::nullptr_t emulation in C++03 mode 2022-02-07 17:51:05 -05:00
stdexcept [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
stdint.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
stdio.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
stdlib.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
streambuf [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
string [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
string.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
string_view [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
strstream [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
system_error [libc++] Remove _LIBCPP_HAS_NO_STRONG_ENUMS. 2022-03-01 20:27:20 +01:00
tgmath.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
thread [libc++] Granularize chrono includes 2022-02-23 23:06:26 +01:00
tuple [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
type_traits [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
typeindex [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
typeinfo [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
uchar.h [libc++] Add missing header <cuchar> 2022-03-07 08:48:50 -05:00
unordered_map [libc++] Move everything related solely to _LIBCPP_ASSERT to its own file 2022-02-16 12:49:50 -05:00
unordered_set [libc++] Move everything related solely to _LIBCPP_ASSERT to its own file 2022-02-16 12:49:50 -05:00
utility [libc++] Implement P0627R6 (Function to mark unreachable code) 2022-02-14 20:52:51 +01:00
valarray [libc++] Make sure calls to std::move are always qualified 2022-02-24 19:58:08 -05:00
variant [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
vector [libc++] Remove <utility> includes 2022-03-17 00:12:33 +01:00
version [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
wchar.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00
wctype.h [libc++] Normalize all our '#pragma GCC system_header', and regression-test. 2022-02-04 12:27:19 -05:00