Skip to content

Commit 271eb06

Browse files
authored
[WebAssembly] Upstream misc. EH changes (#92990)
This upstreams more recent, mostly EH changes from libcxx and libcxxabi: - `__cxa_init_primary_exception`-related changes made when updating to LLVM 18.1.2 (emscripten-core/emscripten#21638) - Removes ctype macros (emscripten-core/emscripten#20960) - Guard destructor changes with `__wasm__` (emscripten-core/emscripten#21974)
1 parent e8dd4df commit 271eb06

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

libcxx/include/__exception/exception_ptr.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ struct __cxa_exception;
3838
_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
3939
void*,
4040
std::type_info*,
41-
void(
4241
# if defined(_WIN32)
43-
__thiscall
42+
void(__thiscall*)(void*)) throw();
43+
# elif defined(__wasm__)
44+
// In Wasm, a destructor returns its argument
45+
void* (*)(void*)) throw();
46+
# else
47+
void (*)(void*)) throw();
4448
# endif
45-
*)(void*)) throw();
4649
}
4750

4851
} // namespace __cxxabiv1
@@ -92,8 +95,16 @@ _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
9295
using _Ep2 = __decay_t<_Ep>;
9396

9497
void* __ex = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ep));
98+
# ifdef __wasm__
99+
// In Wasm, a destructor returns its argument
100+
(void)__cxxabiv1::__cxa_init_primary_exception(__ex, const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) -> void* {
101+
# else
95102
(void)__cxxabiv1::__cxa_init_primary_exception(__ex, const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) {
103+
# endif
96104
std::__destroy_at(static_cast<_Ep2*>(__p));
105+
# ifdef __wasm__
106+
return __p;
107+
# endif
97108
});
98109

99110
try {

libcxx/include/__locale

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,12 @@ public:
343343
static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
344344
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
345345
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
346-
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
346+
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
347347
# ifdef __APPLE__
348348
typedef __uint32_t mask;
349349
# elif defined(__FreeBSD__)
350350
typedef unsigned long mask;
351-
# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
351+
# elif defined(__NetBSD__)
352352
typedef unsigned short mask;
353353
# endif
354354
static const mask space = _CTYPE_S;

libcxxabi/include/cxxabi.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ extern _LIBCXXABI_FUNC_VIS void
4848
__cxa_free_exception(void *thrown_exception) throw();
4949
// This function is an LLVM extension, which mirrors the same extension in libsupc++ and libcxxrt
5050
extern _LIBCXXABI_FUNC_VIS __cxa_exception*
51+
#ifdef __wasm__
52+
// 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();
54+
#else
5155
__cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
56+
#endif
5257

5358
// 2.4.3 Throwing the Exception Object
5459
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
5560
__cxa_throw(void *thrown_exception, std::type_info *tinfo,
56-
#ifdef __WASM_EXCEPTIONS__
57-
// In Wasm, a destructor returns its argument
61+
#ifdef __wasm__
5862
void *(_LIBCXXABI_DTOR_FUNC *dest)(void *));
5963
#else
6064
void (_LIBCXXABI_DTOR_FUNC *dest)(void *));

libcxxabi/src/cxa_exception.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ void __cxa_free_exception(void *thrown_object) throw() {
207207
}
208208

209209
__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* tinfo,
210+
#ifdef __wasm__
211+
// In Wasm, a destructor returns its argument
212+
void *(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() {
213+
#else
210214
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() {
215+
#endif
211216
__cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
212217
exception_header->referenceCount = 0;
213218
exception_header->unexpectedHandler = std::get_unexpected();
@@ -267,7 +272,7 @@ will call terminate, assuming that there was no handler for the
267272
exception.
268273
*/
269274
void
270-
#ifdef __WASM_EXCEPTIONS__
275+
#ifdef __wasm__
271276
// In Wasm, a destructor returns its argument
272277
__cxa_throw(void *thrown_object, std::type_info *tinfo, void *(_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
273278
#else

libcxxabi/src/cxa_exception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
4343

4444
// Manage the exception object itself.
4545
std::type_info *exceptionType;
46-
#ifdef __WASM_EXCEPTIONS__
46+
#ifdef __wasm__
4747
// In Wasm, a destructor returns its argument
4848
void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
4949
#else

0 commit comments

Comments
 (0)