Repository navigation
An empty catch clause catches - #597
Merged
Merged
Conversation
An untyped `catch { }` emits no ops into the TryOp's catches region, and
TryOpLowering took a region holding only its terminator for "no catch
clause" - the shape of the TryOps that only wrap a scope for its cleanup -
so it made no landing pad and the exception went uncaught.
mlirGen(TryStatement) now marks a TryOp that has a catch clause with
HAS_CATCH_ATTR_NAME, and TryOpLowering treats a marked TryOp as having a
catch whatever its region holds. The cleanup-only TryOps stay unmarked.
Test 00try_empty_catch.ts (compile, JIT, corpus).
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.
An empty catch clause did not catch anything. This program died with
tslang: error: uncaught exceptionunder every-mm:Cause. An untyped
catch { }puts no ops in the TryOp's catches region.TryOpLoweringsetcatchHasOpsfrom whether that region held anything besides its terminator. So it treated the empty catch as "no catch clause", which is what the TryOps that only wrap a scope for its cleanup look like. It made no landing pad, and the exception went uncaught.Fix.
mlirGen(TryStatement)now marks a TryOp that has a catch clause with aHAS_CATCH_ATTR_NAMEunit attribute.TryOpLoweringtreats a marked TryOp as having a catch even when the region is empty. The cleanup-only TryOps (block/usingwraps) stay unmarked, so for them an empty region still means "no catch".Test.
00try_empty_catch.tscovers:catch { },catch (e) { }andcatch { ; }finallyIt is registered for compile, JIT and TSLANG_CORPUS.
The repro prints "end" under gc, rc, none and own. Full
ctest -C Release -j 8 --timeout 300passes: 4138 tests, 0 failures.Found while working on #596.
🤖 Generated with Claude Code