Skip to content

Commit 7920939

Browse files
committed
Fix lto0.test_exceptions_allowed_uncaught failure
This test started failing after #16627. Prior to that change the exceptions destructors were called via the following code in JS: ``` // In Wasm, destructors return 'this' as in ARM {{{ makeDynCall('pp', 'destructor') }}}(info.excPtr); ``` For some reason the LTO build produces the following for for the call to `exception_header->exceptionDestructor(thrown_object)` in `__cxa_decrement_exception_refcount`: ``` call_indirect 0 (type 0) ``` Where as the normal non-LTO build produces: ``` call 13 <invoke_ii> ``` Because invoke_ii goes via JS it uses the sloppy type checking and doesn't trap, but `call_indirect` has strict type checking and so does trap.
1 parent 3c5bac9 commit 7920939

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ jobs:
492492
title: "core3+extras"
493493
test_targets: "
494494
lto2.test_dylink_syslibs_all
495+
lto0.test_exceptions_allowed_uncaught
495496
core3
496497
core2g.test_externref
497498
corez.test_dylink_iostream

system/lib/libcxxabi/src/cxa_exception.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace __cxxabiv1 {
2424
struct _LIBCXXABI_HIDDEN __cxa_exception {
2525
size_t referenceCount;
2626
std::type_info *exceptionType;
27-
void (*exceptionDestructor)(void *);
27+
// In wasm, destructors return 'this' as in ARM
28+
void* (*exceptionDestructor)(void *);
2829
uint8_t caught;
2930
uint8_t rethrown;
3031
void *adjustedPtr;

system/lib/libcxxabi/src/cxa_exception_emscripten.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
// Define to enable extra debugging on stderr.
2222
#if EXCEPTIONS_DEBUG
23-
#define DEBUG printf
23+
#include "emscripten/console.h"
24+
#define DEBUG _emscripten_errf
2425
#else
2526
#define DEBUG(...)
2627
#endif
@@ -48,7 +49,7 @@ inline
4849
__cxa_exception*
4950
cxa_exception_from_thrown_object(void* thrown_object)
5051
{
51-
DEBUG("cxa_exception_from_thrown_object %p -> %p\n",
52+
DEBUG("cxa_exception_from_thrown_object %p -> %p",
5253
thrown_object, static_cast<__cxa_exception*>(thrown_object) - 1);
5354
return static_cast<__cxa_exception*>(thrown_object) - 1;
5455
}
@@ -60,7 +61,7 @@ inline
6061
void*
6162
thrown_object_from_cxa_exception(__cxa_exception* exception_header)
6263
{
63-
DEBUG("thrown_object_from_cxa_exception %p -> %p\n",
64+
DEBUG("thrown_object_from_cxa_exception %p -> %p",
6465
exception_header, static_cast<void*>(exception_header + 1));
6566
return static_cast<void*>(exception_header + 1);
6667
}
@@ -118,7 +119,7 @@ __cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
118119
if (thrown_object != NULL )
119120
{
120121
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
121-
DEBUG("INC: %p refcnt=%zu\n", thrown_object, exception_header->referenceCount);
122+
DEBUG("INC: %p refcnt=%zu", thrown_object, exception_header->referenceCount);
122123
std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(1));
123124
}
124125
}
@@ -136,12 +137,12 @@ void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
136137
if (thrown_object != NULL )
137138
{
138139
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
139-
DEBUG("DEC: %p refcnt=%zu rethrown=%d\n", thrown_object,
140+
DEBUG("DEC: %p refcnt=%zu rethrown=%d", thrown_object,
140141
exception_header->referenceCount, exception_header->rethrown);
141142
assert(exception_header->referenceCount > 0);
142143
if (std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(-1)) == 0 && !exception_header->rethrown)
143144
{
144-
DEBUG("DEL: %p\n", thrown_object);
145+
DEBUG("DEL: %p (dtor=%p)", thrown_object, exception_header->exceptionDestructor);
145146
if (NULL != exception_header->exceptionDestructor)
146147
exception_header->exceptionDestructor(thrown_object);
147148
__cxa_free_exception(thrown_object);

0 commit comments

Comments
 (0)