Repository navigation
Conversation
In Emscripten EH, #25988 changed where we increment refcount to fix a refcounting inconsistency between Emscripten vs. Wasm EH (#17115). Before #25988, it was incremented in `__cxa_begin_catch`, but after #25988, it was in `__cxa_throw` and `__cxa_rethrow`, more inline with Wasm EH. `__cxa_end_catch` calls `__cxa_decrement_exception_refcount`, which decrements the refcount and destroys/frees the exception. But when an exception is rethrown, we should not destroy it in `__cxa_end_catch`. The below illutrates how a rethrown exception is (correctly) not destroyed in `__cxa_end_catch`: ```cpp // Before #25988 (refcount incremented in __cxa_begin_catch): try { throw MyEx(); // __cxa_throw: refcount = 0, rethrown = false } catch (...) { // __cxa_begin_catch: refcount = 1 (0 -> 1), rethrown = false throw; // __cxa_rethrow: refcount = 1 (unchanged), rethrown = true } // __cxa_end_catch: refcount = 0 (1 -> 0); not destroyed/freed because rethrown == true // After #25988 (refcount incremented in __cxa_throw and __cxa_rethrow): try { throw MyEx(); // __cxa_throw: refcount = 1 (0 -> 1) } catch (...) { // __cxa_begin_catch: refcount = 1 (unchanged) throw; // __cxa_rethrow: refcount = 2 (1 -> 2) } // __cxa_end_catch: refcount = 1 (2 -> 1); not destroyed/freed because refcount > 0 ``` So after #25988 we were supposed to solely rely on the refcount to determine whether to destroy an exception. But the `!exception_header->rethrown` check was incorrectly still left in `__cxa_decrement_exception_refcount`. This didn't affect C++-only programs, but this prevented an exception from being destroyed when an exception was rethrown to JS and `decrementExceptionRefcount` was called from there, as in the test added here. This removes the incorrect `rethrown` flag check. After this and #26518, no code uses the `rethrown` field, so this also removes it and its related methods. This is a part of fixes for #27705.
aheejin
force-pushed
the
remove_rethrown
branch
from
October 19, 2026 13:37
11a313c to
e2c1185
Compare
This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (2) test expectation files were updated by running the tests with `--rebaseline`: ``` codesize/test_codesize_cxx_except.json: 199227 => 199193 [-34 bytes / -0.02%] codesize/test_codesize_cxx_mangle.json: 265550 => 265516 [-34 bytes / -0.01%] Average change: -0.01% (-0.02% - -0.01%) ```
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Emscripten EH, #25988 changed where we increment refcount to fix a refcounting inconsistency between Emscripten vs. Wasm EH (#17115). Before #25988, it was incremented in
__cxa_begin_catch, but after#25988, it was in
__cxa_throwand__cxa_rethrow, more inline withWasm EH.
__cxa_end_catchcalls__cxa_decrement_exception_refcount, which decrements the refcount and destroys/frees the exception. But when an exception is rethrown, we should not destroy it in__cxa_end_catch. The below illutrates how a rethrown exception is (correctly) not destroyed in__cxa_end_catch:So after #25988 we were supposed to solely rely on the refcount to determine whether to destroy an exception. But the
!exception_header->rethrowncheck was incorrectly still left in__cxa_decrement_exception_refcount. This didn't affect C++-only programs, but this prevented an exception from being destroyed when an exception was rethrown to JS anddecrementExceptionRefcountwas called from there, as in the test added here.This removes the incorrect
rethrownflag check. After this and #26518, no code uses therethrownfield, so this also removes it and its related methods.This is a part of fixes for #27705.