Skip to content

Fix try/catch: sequential tries, per-class throw info, nested mismatches - #346

Merged
ASDAlexander77 merged 2 commits into
mainfrom
fix-catch-gaps
Sep 23, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
fix-catch-gaps

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Five try/catch failures. Each one compiled cleanly and then crashed or behaved wrongly at run time.

Windows

  • Two try/catch statements in a row crashed when the second try's body started with a call. After canonicalization, that call's invoke comes directly after the first catch's end marker. Win32ExceptionPass mistook it for the catch's own end-of-catch invoke and emitted no catchret, so the second try ran inside the first catch's funclet.
  • All classes shared one ThrowInfo/CatchableTypeArray (_TI2PEAV / _CTA2PEAV, both linkonce_odr). The first class a module threw fixed the descriptors for every other class, so throw new B() went out as an A. The names are now per class, in both RTTI helpers.
  • A typed catch that didn't match, nested in another try in the same function, let the exception escape. The catchswitch takes its unwind target from an invoke inside the catch body. With no call in the body, nothing reached the outer pad, and the pad was deleted as unreachable. Windows now gets the same mismatch-rethrow edge that Linux already had (CompareCatchTypeOp is always true there, so the rethrow never runs). This only applies to a try in its parent's body (new inParentTryBody side table): in a catch or finally it would loop back into the handler that is already running.
  • The same kind of mismatch skipped the try's own finally. The edge now goes to the finally first.

Linux

  • The same nested-mismatch cases called 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_catch and rethrows to the finally or the parent pad, the same pattern the nested finally and cleanup paths already use. The Linux LandingPadOp lowering also kept only the first clause and dropped this catch-all (and the one linuxHasCleanups adds).

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

ASDAlexander77 and others added 2 commits September 23, 2026 11:12
… 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>
@ASDAlexander77
ASDAlexander77 merged commit abe8b0e into main Sep 23, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-catch-gaps branch September 23, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant