Repository navigation
Fix try/catch: sequential tries, per-class throw info, nested mismatches - #346
Merged
Merged
Conversation
… mismatches Four run-time failures, none of them visible at compile time: - A catch followed directly by a try whose body starts with a call got no catchret: Win32ExceptionPass took that invoke for the catch's own end-of-catch invoke, so the next try ran inside the catch funclet. - Every class shared one ThrowInfo/CatchableTypeArray name, so the first class a module threw fixed the descriptors for all of them. - A typed catch nested in another try in the same function, with no call in its body, left nothing unwinding to the outer pad; the pad was deleted and a non-matching exception escaped. The Linux mismatch-rethrow edge now also exists on Windows for that case (never executed: the filter already matched). - The same mismatch skipped its own try's finally; the edge goes there first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Linux a typed catch nested in another try of the same function (or with its own finally) listed only its typed clause, so any other exception type never entered the pad and the process called std::terminate. Such a catch now gets a catch-all clause and, on mismatch, begins the catch and rethrows to the finally or the enclosing try - the pattern the nested finally/cleanup paths already use. The Linux LandingPadOp lowering kept only the first clause and silently dropped that catch-all (and the one linuxHasCleanups adds). The catch binding now lives in its own symbol scope, so a second `catch (e)` in the same block is no longer reported as a redeclaration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Five try/catch failures. Each one compiled cleanly and then crashed or behaved wrongly at run time.
Windows
invokecomes directly after the first catch's end marker.Win32ExceptionPassmistook it for the catch's own end-of-catch invoke and emitted nocatchret, so the second try ran inside the first catch's funclet._TI2PEAV/_CTA2PEAV, bothlinkonce_odr). The first class a module threw fixed the descriptors for every other class, sothrow new B()went out as anA. The names are now per class, in both RTTI helpers.CompareCatchTypeOpis always true there, so the rethrow never runs). This only applies to a try in its parent's body (newinParentTryBodyside table): in a catch or finally it would loop back into the handler that is already running.finally. The edge now goes to the finally first.Linux
std::terminate. The inner landingpad listed only its typed clause. The catch now gets a catch-all clause, and on a mismatch it calls__cxa_begin_catchand rethrows to the finally or the parent pad, the same pattern the nested finally and cleanup paths already use. The LinuxLandingPadOplowering also kept only the first clause and dropped this catch-all (and the onelinuxHasCleanupsadds).Also: the catch binding now has its own symbol scope, so a second
catch (e)in the same block no longer warns "variable e redeclared".New test:
00try_catch_sequence_and_nesting.ts, registered for compile, jit and the rc/none corpus.Verified locally: Windows ctest 2800/2800, Linux (WSL, ninja release) ctest 2788/2788.
🤖 Generated with Claude Code