Repository navigation
JIT: index filter blocks after EH table sorting - #135601
Merged
Merged
Conversation
fgFindBasicBlocks stamped filter blocks with their clause's index before fgSortEHTable ran. The post-sort handler loop did not update those blocks, so moving a filter clause left its blocks with a stale handler index. In FilterInEarlierFinally, the stale index names a finally clause and the method is rejected with InvalidProgramException. In FilterInEarlierFilterHandler, the two filters retain each other's index; the main Checked JIT asserts in fgVerifyHandlerTab and the main Release JIT rejects the method with InvalidProgramException. ECMA-335 I.12.4.2.5 orders nested try blocks; fgSortEHTable also orders clauses nested in handlers. Move filter indexing into the post-sort loop next to handler indexing. Valid filters cannot contain nested EH regions, so each filter block receives its clause's sorted index unconditionally. Fixes dotnet#135592
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
This was referenced Oct 11, 2026
Mono's JIT can leave the blocks of a filter or catch handler nested in an earlier-listed handler in the enclosing handler's region. In CI the merged Regression_5 work item crashed in Runtime_135592 on mono windows-x64 (0xC0000005) and hung in it on mono linux-arm64. Shipped Mono 8.0.28 reproduces both with FilterInEarlierFinally. The Mono LLVM AOT compiler asserts on CatchInEarlierFinally (mini-llvm.c, `lhs' not met), which fails the "AOT compile CoreCLR tests" step of the llvmaot leg. Mark the test ActiveIssue on Mono and MonoAotIncompatible. The Mono bug is tracked in dotnet#135641.
jkotas
reviewed
Oct 13, 2026
jkotas
reviewed
Oct 13, 2026
… header The project file's MonoAotIncompatible and the ActiveIssue attribute already say why the test is disabled on Mono, so the header comment repeated them.
Contributor
Author
|
/azp run runtime |
|
Commenter does not have sufficient privileges for PR 135601 in repo dotnet/runtime |
jkotas
reviewed
Oct 13, 2026
The Mono runtime-test legs build and run only Priority 0 tests, so the attribute has had no effect since the test became Priority 1. The project file keeps MonoAotIncompatible and the dotnet#135641 link.
This was referenced Oct 13, 2026
Closed
Contributor
Author
jkotas
approved these changes
Nov 25, 2026
jkotas
reviewed
Nov 25, 2026
Member
|
LGTM @dotnet/jit-contrib PTLA |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression test remains enabled on Mono JIT despite known crashes and hangs, requiring a Mono-scoped ActiveIssue exclusion for #135641 alongside the existing AOT exclusion.
1 open issue
What changed in this PR
This PR fixes stale filter-block handler indices in the CoreCLR JIT when exception-handling clauses are reordered, addressing #135592.
Changes:
- Assigns filter-block indices after exception-handling table sorting while preserving existing filter validation.
- Adds four IL regression scenarios covering reordered filter clauses and control cases.
- Configures the regression test as priority 1 with a Mono AOT exclusion.
| File | Description |
|---|---|
src/tests/JIT/Regression/JitBlue/Runtime_135592/Runtime_135592.ilproj |
Registers the IL test and configures priority and Mono AOT exclusion. |
src/tests/JIT/Regression/JitBlue/Runtime_135592/Runtime_135592.il |
Exercises nested filters and a catch-only control with explicit clause ordering. |
src/coreclr/jit/fgbasic.cpp |
Moves filter-block handler indexing to the post-sort pass. |
Review effort: Balanced
AndyAyersMS
approved these changes
Nov 25, 2026
Apply jkotas's suggestion to remove the obsolete Mono AOT exclusion.
Contributor
Author
|
@jkotas I've applied your suggestion and removed |
jkotas
approved these changes
Nov 25, 2026
Contributor
Author
|
Thank you for the review and merge! |
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.

Fixes #135592.
fgFindBasicBlocksstamped the blocks of a filter with the clause's index beforefgSortEHTableran, and the post-sort loop that indexes handler blocks never revisited them. When the sort moved a filter clause, its filter blocks kept the pre-sort index, which after the sort names a different clause:FilterInEarlierFinally, the stale index names a finally clause.fgCheckBasicBlockControlFlowreportsBADCODE("Unexpected endfilter"), and the method fails withInvalidProgramException.FilterInEarlierFilterHandler, the two filters retain each other's clause index. The main Checked JIT assertsblock->bbHndIndex == blockHndIndex[block->bbNum]infgVerifyHandlerTab; the main Release JIT rejects the method withInvalidProgramException.ECMA-335 I.12.4.2.5 orders nested try blocks only; clauses nested in a handler may be listed in either order, which is what the sort exists to accept (its comment spells out the
try { } catch { try { } catch { } }case).Change
The filter stamping moves from the pre-sort scan into the post-sort loop, next to the handler stamping. The pre-sort scan still finds the
endfilterblock and checks that the filter immediately precedes its handler. Valid filters cannot contain nested EH regions, so the new loop assigns each filter block its clause's sorted index unconditionally.For valid methods whose filter indices are already correct, this preserves the final handler indices. It corrects stale indices when sorting moves a filter clause.
Test
JIT/Regression/JitBlue/Runtime_135592is an IL test that exercises explicit EH clause ordering. Its four scenario methods throw inside a nested try and return 1 when the nested handler catches. Three scenarios use filters;CatchInEarlierFinallyis a catch-only control:FilterInEarlierFinallyInvalidProgramExceptionFilterInEarlierFilterHandlerInvalidProgramException(release); checked JIT asserts infgVerifyHandlerTabFilterInEarlierFinally_InnerFirstCatchInEarlierFinallyValidation
Checked JIT at main 8630d89, baseline vs this change, each test run under
corerun:8630d89)Runtime_135592beforeRuntime_135593(PR for #135593)InvalidProgramExceptionfromFilterInEarlierFinallyInvalidProgramExceptionfromFilterInEarlierFinallyInvalidProgramExceptionfromFilterInEarlierFinallyInvalidProgramExceptionfromFilterInEarlierFinallyInvalidProgramExceptionfromFilterInEarlierFinallyThe regression test for #135593 (separate PR) was run in the same lanes and is unaffected by this change, as expected.
With this change,
JIT/Methodical/ehandJIT/Directed/ExcepFilterspass on linux-x64 Checked (168 tests, standalone). The standaloneFilterInEarlierFinallyrepro is rejected on the shipped .NET 10.0.12 runtime on linux-x64 and osx-arm64, on 10.0.11 on windows-x64 and linux-arm64, and on the explicitly selected 10.0.9 and 10.0.11 runtimes on windows-arm64.Note
This PR was prepared with AI assistance (Anthropic Claude and OpenAI Codex), under my direction. I reviewed it before posting.