Skip to content

Commit 7ab01c9

Browse files
committed
libcxxabi: Update to Clang 20.
1 parent a89b343 commit 7ab01c9

18 files changed

+344
-124
lines changed

lib/libcxxabi/include/__cxxabi_config.h

+6
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,10 @@
103103
#define _LIBCXXABI_DTOR_FUNC
104104
#endif
105105

106+
#if __cplusplus < 201103L
107+
# define _LIBCXXABI_NOEXCEPT throw()
108+
#else
109+
# define _LIBCXXABI_NOEXCEPT noexcept
110+
#endif
111+
106112
#endif // ____CXXABI_CONFIG_H

lib/libcxxabi/include/cxxabi.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ extern "C" {
4343

4444
// 2.4.2 Allocating the Exception Object
4545
extern _LIBCXXABI_FUNC_VIS void *
46-
__cxa_allocate_exception(size_t thrown_size) throw();
46+
__cxa_allocate_exception(size_t thrown_size) _LIBCXXABI_NOEXCEPT;
4747
extern _LIBCXXABI_FUNC_VIS void
48-
__cxa_free_exception(void *thrown_exception) throw();
48+
__cxa_free_exception(void *thrown_exception) _LIBCXXABI_NOEXCEPT;
4949
// This function is an LLVM extension, which mirrors the same extension in libsupc++ and libcxxrt
5050
extern _LIBCXXABI_FUNC_VIS __cxa_exception*
5151
#ifdef __wasm__
5252
// In Wasm, a destructor returns its argument
53-
__cxa_init_primary_exception(void* object, std::type_info* tinfo, void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
53+
__cxa_init_primary_exception(void* object, std::type_info* tinfo, void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) _LIBCXXABI_NOEXCEPT;
5454
#else
55-
__cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
55+
__cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) _LIBCXXABI_NOEXCEPT;
5656
#endif
5757

5858
// 2.4.3 Throwing the Exception Object
@@ -66,21 +66,21 @@ __cxa_throw(void *thrown_exception, std::type_info *tinfo,
6666

6767
// 2.5.3 Exception Handlers
6868
extern _LIBCXXABI_FUNC_VIS void *
69-
__cxa_get_exception_ptr(void *exceptionObject) throw();
69+
__cxa_get_exception_ptr(void *exceptionObject) _LIBCXXABI_NOEXCEPT;
7070
extern _LIBCXXABI_FUNC_VIS void *
71-
__cxa_begin_catch(void *exceptionObject) throw();
71+
__cxa_begin_catch(void *exceptionObject) _LIBCXXABI_NOEXCEPT;
7272
extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
7373
#if defined(_LIBCXXABI_ARM_EHABI)
7474
extern _LIBCXXABI_FUNC_VIS bool
75-
__cxa_begin_cleanup(void *exceptionObject) throw();
75+
__cxa_begin_cleanup(void *exceptionObject) _LIBCXXABI_NOEXCEPT;
7676
extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
7777
#endif
7878
extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();
7979

8080
// GNU extension
8181
// Calls `terminate` with the current exception being caught. This function is used by GCC when a `noexcept` function
8282
// throws an exception inside a try/catch block and doesn't catch it.
83-
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_call_terminate(void*) throw();
83+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_call_terminate(void*) _LIBCXXABI_NOEXCEPT;
8484

8585
// 2.5.4 Rethrowing Exceptions
8686
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow();
@@ -168,23 +168,23 @@ extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,
168168

169169
// Apple additions to support C++ 0x exception_ptr class
170170
// These are primitives to wrap a smart pointer around an exception object
171-
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw();
171+
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() _LIBCXXABI_NOEXCEPT;
172172
extern _LIBCXXABI_FUNC_VIS void
173173
__cxa_rethrow_primary_exception(void *primary_exception);
174174
extern _LIBCXXABI_FUNC_VIS void
175-
__cxa_increment_exception_refcount(void *primary_exception) throw();
175+
__cxa_increment_exception_refcount(void *primary_exception) _LIBCXXABI_NOEXCEPT;
176176
extern _LIBCXXABI_FUNC_VIS void
177-
__cxa_decrement_exception_refcount(void *primary_exception) throw();
177+
__cxa_decrement_exception_refcount(void *primary_exception) _LIBCXXABI_NOEXCEPT;
178178

179179
// Apple extension to support std::uncaught_exception()
180-
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() throw();
181-
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() throw();
180+
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _LIBCXXABI_NOEXCEPT;
181+
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _LIBCXXABI_NOEXCEPT;
182182

183183
#if defined(__linux__) || defined(__Fuchsia__)
184184
// Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.
185185
// https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
186186
extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *,
187-
void *) throw();
187+
void *) _LIBCXXABI_NOEXCEPT;
188188
#endif
189189

190190
} // extern "C"

lib/libcxxabi/src/abort_message.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@
1212
#include "abort_message.h"
1313

1414
#ifdef __BIONIC__
15-
# include <android/api-level.h>
16-
# if __ANDROID_API__ >= 21
17-
# include <syslog.h>
18-
extern "C" void android_set_abort_message(const char* msg);
19-
# else
20-
# include <assert.h>
21-
# endif // __ANDROID_API__ >= 21
15+
# include <syslog.h>
16+
extern "C" void android_set_abort_message(const char* msg);
2217
#endif // __BIONIC__
2318

2419
#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
2520
# include <CrashReporterClient.h>
2621
# define _LIBCXXABI_USE_CRASHREPORTER_CLIENT
2722
#endif
2823

29-
void abort_message(const char* format, ...)
24+
void __abort_message(const char* format, ...)
3025
{
3126
// Write message to stderr. We do this before formatting into a
3227
// variable-size buffer so that we still get some information if
@@ -59,20 +54,13 @@ void abort_message(const char* format, ...)
5954
vasprintf(&buffer, format, list);
6055
va_end(list);
6156

62-
# if __ANDROID_API__ >= 21
6357
// Show error in tombstone.
6458
android_set_abort_message(buffer);
6559

6660
// Show error in logcat.
6761
openlog("libc++abi", 0, 0);
6862
syslog(LOG_CRIT, "%s", buffer);
6963
closelog();
70-
# else
71-
// The good error reporting wasn't available in Android until L. Since we're
72-
// about to abort anyway, just call __assert2, which will log _somewhere_
73-
// (tombstone and/or logcat) in older releases.
74-
__assert2(__FILE__, __LINE__, __func__, buffer);
75-
# endif // __ANDROID_API__ >= 21
7664
#endif // __BIONIC__
7765

7866
abort();

lib/libcxxabi/src/abort_message.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "cxxabi.h"
1313

1414
extern "C" _LIBCXXABI_HIDDEN _LIBCXXABI_NORETURN void
15-
abort_message(const char *format, ...) __attribute__((format(printf, 1, 2)));
15+
__abort_message(const char *format, ...) __attribute__((format(printf, 1, 2)));
1616

1717
#ifndef _LIBCXXABI_ASSERT
1818
// zig patch: respect NDEBUG. Otherwise the file path makes it into the binary,
@@ -24,7 +24,7 @@ abort_message(const char *format, ...) __attribute__((format(printf, 1, 2)));
2424
do { \
2525
if (!(expr)) { \
2626
char const* __msg = (msg); \
27-
::abort_message("%s:%d: %s", __FILE__, __LINE__, __msg); \
27+
::__abort_message("%s:%d: %s", __FILE__, __LINE__, __msg); \
2828
} \
2929
} while (false)
3030

lib/libcxxabi/src/cxa_default_handlers.cpp

+19-20
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#include <exception>
13-
#include <memory>
14-
#include <stdlib.h>
13+
#include <new>
1514
#include "abort_message.h"
1615
#include "cxxabi.h"
1716
#include "cxa_handlers.h"
@@ -23,17 +22,7 @@
2322

2423
static constinit const char* cause = "uncaught";
2524

26-
#ifndef _LIBCXXABI_NO_EXCEPTIONS
27-
// Demangle the given string, or return the string as-is in case of an error.
28-
static std::unique_ptr<char const, void (*)(char const*)> demangle(char const* str)
29-
{
30-
#if !defined(LIBCXXABI_NON_DEMANGLING_TERMINATE)
31-
if (const char* result = __cxxabiv1::__cxa_demangle(str, nullptr, nullptr, nullptr))
32-
return {result, [](char const* p) { std::free(const_cast<char*>(p)); }};
33-
#endif
34-
return {str, [](char const*) { /* nothing to free */ }};
35-
}
36-
25+
# ifndef _LIBCXXABI_NO_EXCEPTIONS
3726
__attribute__((noreturn))
3827
static void demangling_terminate_handler()
3928
{
@@ -42,46 +31,56 @@ static void demangling_terminate_handler()
4231

4332
// If there is no uncaught exception, just note that we're terminating
4433
if (!globals)
45-
abort_message("terminating");
34+
__abort_message("terminating");
4635

4736
__cxa_exception* exception_header = globals->caughtExceptions;
4837
if (!exception_header)
49-
abort_message("terminating");
38+
__abort_message("terminating");
5039

5140
_Unwind_Exception* unwind_exception =
5241
reinterpret_cast<_Unwind_Exception*>(exception_header + 1) - 1;
5342

5443
// If we're terminating due to a foreign exception
5544
if (!__isOurExceptionClass(unwind_exception))
56-
abort_message("terminating due to %s foreign exception", cause);
45+
__abort_message("terminating due to %s foreign exception", cause);
5746

5847
void* thrown_object =
5948
__getExceptionClass(unwind_exception) == kOurDependentExceptionClass ?
6049
((__cxa_dependent_exception*)exception_header)->primaryException :
6150
exception_header + 1;
6251
const __shim_type_info* thrown_type =
6352
static_cast<const __shim_type_info*>(exception_header->exceptionType);
64-
auto name = demangle(thrown_type->name());
53+
54+
auto name = [str = thrown_type->name()] {
55+
# ifndef LIBCXXABI_NON_DEMANGLING_TERMINATE
56+
if (const char* result = __cxxabiv1::__cxa_demangle(str, nullptr, nullptr, nullptr))
57+
// We're about to abort(), this memory can never be freed; so it's fine
58+
// to just return a raw pointer
59+
return result;
60+
# endif
61+
return str;
62+
}();
63+
6564
// If the uncaught exception can be caught with std::exception&
6665
const __shim_type_info* catch_type =
6766
static_cast<const __shim_type_info*>(&typeid(std::exception));
6867
if (catch_type->can_catch(thrown_type, thrown_object))
6968
{
7069
// Include the what() message from the exception
7170
const std::exception* e = static_cast<const std::exception*>(thrown_object);
72-
abort_message("terminating due to %s exception of type %s: %s", cause, name.get(), e->what());
71+
__abort_message("terminating due to %s exception of type %s: %s", cause, name, e->what());
7372
}
7473
else
7574
{
7675
// Else just note that we're terminating due to an exception
77-
abort_message("terminating due to %s exception of type %s", cause, name.get());
76+
__abort_message("terminating due to %s exception of type %s", cause, name);
7877
}
7978
}
8079
#else // !_LIBCXXABI_NO_EXCEPTIONS
8180
__attribute__((noreturn))
8281
static void demangling_terminate_handler()
8382
{
84-
abort_message("terminating");
83+
__abort_message("terminating");
8584
}
8685
#endif // !_LIBCXXABI_NO_EXCEPTIONS
8786

lib/libcxxabi/src/cxa_demangle.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828

2929
using namespace itanium_demangle;
3030

31-
constexpr const char *itanium_demangle::FloatData<float>::spec;
32-
constexpr const char *itanium_demangle::FloatData<double>::spec;
33-
constexpr const char *itanium_demangle::FloatData<long double>::spec;
34-
3531
// <discriminator> := _ <non-negative number> # when number < 10
3632
// := __ <non-negative number> _ # when number >= 10
3733
// extension := decimal-digit+ # at the end of string

lib/libcxxabi/src/cxa_exception_storage.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ extern "C" {
5656
namespace __cxxabiv1 {
5757
namespace {
5858
std::__libcpp_tls_key key_;
59-
std::__libcpp_exec_once_flag flag_ = _LIBCPP_EXEC_ONCE_INITIALIZER;
59+
constinit std::__libcpp_exec_once_flag flag_ = _LIBCPP_EXEC_ONCE_INITIALIZER;
6060

6161
void _LIBCPP_TLS_DESTRUCTOR_CC destruct_(void *p) {
6262
__free_with_fallback(p);
6363
if (0 != std::__libcpp_tls_set(key_, NULL))
64-
abort_message("cannot zero out thread value for __cxa_get_globals()");
64+
__abort_message("cannot zero out thread value for __cxa_get_globals()");
6565
}
6666

6767
void construct_() {
6868
if (0 != std::__libcpp_tls_create(&key_, destruct_))
69-
abort_message("cannot create thread specific key for __cxa_get_globals()");
69+
__abort_message("cannot create thread specific key for __cxa_get_globals()");
7070
}
7171
} // namespace
7272

@@ -80,9 +80,9 @@ extern "C" {
8080
retVal = static_cast<__cxa_eh_globals*>(
8181
__calloc_with_fallback(1, sizeof(__cxa_eh_globals)));
8282
if (NULL == retVal)
83-
abort_message("cannot allocate __cxa_eh_globals");
83+
__abort_message("cannot allocate __cxa_eh_globals");
8484
if (0 != std::__libcpp_tls_set(key_, retVal))
85-
abort_message("std::__libcpp_tls_set failure in __cxa_get_globals()");
85+
__abort_message("std::__libcpp_tls_set failure in __cxa_get_globals()");
8686
}
8787
return retVal;
8888
}
@@ -94,7 +94,7 @@ extern "C" {
9494
__cxa_eh_globals *__cxa_get_globals_fast() {
9595
// First time through, create the key.
9696
if (0 != std::__libcpp_execute_once(&flag_, construct_))
97-
abort_message("execute once failure in __cxa_get_globals_fast()");
97+
__abort_message("execute once failure in __cxa_get_globals_fast()");
9898
return static_cast<__cxa_eh_globals*>(std::__libcpp_tls_get(key_));
9999
}
100100
} // extern "C"

lib/libcxxabi/src/cxa_guard_impl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
// the former.
9292
#ifdef BUILDING_CXA_GUARD
9393
# include "abort_message.h"
94-
# define ABORT_WITH_MESSAGE(...) ::abort_message(__VA_ARGS__)
94+
# define ABORT_WITH_MESSAGE(...) ::__abort_message(__VA_ARGS__)
9595
#elif defined(TESTING_CXA_GUARD)
9696
# define ABORT_WITH_MESSAGE(...) ::abort()
9797
#else
@@ -156,12 +156,12 @@ class AtomicInt {
156156
// PlatformGetThreadID
157157
//===----------------------------------------------------------------------===//
158158

159-
#if defined(__APPLE__) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
159+
#if defined(__APPLE__) && _LIBCPP_HAS_THREAD_API_PTHREAD
160160
uint32_t PlatformThreadID() {
161161
static_assert(sizeof(mach_port_t) == sizeof(uint32_t), "");
162162
return static_cast<uint32_t>(pthread_mach_thread_np(std::__libcpp_thread_get_current_id()));
163163
}
164-
#elif defined(SYS_gettid) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
164+
#elif defined(SYS_gettid) && _LIBCPP_HAS_THREAD_API_PTHREAD
165165
uint32_t PlatformThreadID() {
166166
static_assert(sizeof(pid_t) == sizeof(uint32_t), "");
167167
return static_cast<uint32_t>(syscall(SYS_gettid));
@@ -676,8 +676,8 @@ static_assert(CurrentImplementation != Implementation::Futex || PlatformSupports
676676

677677
using SelectedImplementation = SelectImplementation<CurrentImplementation>::type;
678678

679-
} // end namespace
680-
} // end namespace __cxxabiv1
679+
} // namespace
680+
} // namespace __cxxabiv1
681681

682682
#if defined(__clang__)
683683
# pragma clang diagnostic pop

lib/libcxxabi/src/cxa_handlers.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ __unexpected(unexpected_handler func)
3333
{
3434
func();
3535
// unexpected handler should not return
36-
abort_message("unexpected_handler unexpectedly returned");
36+
__abort_message("unexpected_handler unexpectedly returned");
3737
}
3838

3939
__attribute__((noreturn))
@@ -58,13 +58,13 @@ __terminate(terminate_handler func) noexcept
5858
#endif // _LIBCXXABI_NO_EXCEPTIONS
5959
func();
6060
// handler should not return
61-
abort_message("terminate_handler unexpectedly returned");
61+
__abort_message("terminate_handler unexpectedly returned");
6262
#ifndef _LIBCXXABI_NO_EXCEPTIONS
6363
}
6464
catch (...)
6565
{
6666
// handler should not throw exception
67-
abort_message("terminate_handler unexpectedly threw an exception");
67+
__abort_message("terminate_handler unexpectedly threw an exception");
6868
}
6969
#endif // _LIBCXXABI_NO_EXCEPTIONS
7070
}

lib/libcxxabi/src/cxa_personality.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ uintptr_t readPointerHelper(const uint8_t*& p) {
167167
return static_cast<uintptr_t>(value);
168168
}
169169

170-
} // end namespace
170+
} // namespace
171171

172172
extern "C"
173173
{

lib/libcxxabi/src/cxa_thread_atexit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace {
8989
// __cxa_thread_atexit() may be called arbitrarily late (for example, from
9090
// global destructors or atexit() handlers).
9191
if (std::__libcpp_tls_create(&dtors_key, run_dtors) != 0) {
92-
abort_message("std::__libcpp_tls_create() failed in __cxa_thread_atexit()");
92+
__abort_message("std::__libcpp_tls_create() failed in __cxa_thread_atexit()");
9393
}
9494
}
9595

lib/libcxxabi/src/cxa_vector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void throw_bad_array_new_length() {
121121
#ifndef _LIBCXXABI_NO_EXCEPTIONS
122122
throw std::bad_array_new_length();
123123
#else
124-
abort_message("__cxa_vec_new failed to allocate memory");
124+
__abort_message("__cxa_vec_new failed to allocate memory");
125125
#endif
126126
}
127127

lib/libcxxabi/src/cxa_virtual.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ namespace __cxxabiv1 {
1313
extern "C" {
1414
_LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN
1515
void __cxa_pure_virtual(void) {
16-
abort_message("Pure virtual function called!");
16+
__abort_message("Pure virtual function called!");
1717
}
1818

1919
_LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN
2020
void __cxa_deleted_virtual(void) {
21-
abort_message("Deleted virtual function called!");
21+
__abort_message("Deleted virtual function called!");
2222
}
2323
} // extern "C"
2424
} // abi

0 commit comments

Comments
 (0)