[clr-interp] Fix EH logic edge case#122993
Merged
davidwrighton merged 2 commits intodotnet:mainfrom Jan 9, 2026
Merged
Conversation
When a try block exactly encloses another try/finally or try/catch block and the handler ends at the same point the try body ends we had an off by one issue in our reprentation of the ilOffset on the leave chain islands. This fixes the off by one issue for that kind of basic block. The C# compiler seems to always inject a nop to avoid this issue, but I do not know why and I can find no justification for that rule. Fixes badcodeinsidefinally tests
Contributor
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an off-by-one issue in the CLR interpreter's exception handling (EH) logic for leave chain islands. The issue occurs when a try block exactly encloses another try/finally or try/catch block and the handler ends at the same point the try body ends.
Key changes:
- Added
isLeaveChainIslandfield toInterpBasicBlockto identify leave chain island basic blocks - Updated EH clause overlap counting logic to skip leave chain islands that coincide with handler/filter boundaries
- Modified
GetNativeRangeForClauseto include leave chain islands at clause boundaries when determining native ranges
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/coreclr/interpreter/compiler.h | Added new isLeaveChainIsland boolean field to InterpBasicBlock struct and initialized it in the constructor |
| src/coreclr/interpreter/compiler.cpp | Updated EH clause overlap logic to handle leave chain islands at boundaries, modified native range calculation to include boundary leave chain islands, added debug logging, and set the new flag during leave chain island creation |
Member
Author
|
/azp run runtime-interpreter |
|
Azure Pipelines successfully started running 1 pipeline(s). |
janvorli
reviewed
Jan 8, 2026
…ify GetNativeRangeForClause
This was referenced Jan 8, 2026
Open
This was referenced Jan 9, 2026
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.
When a try block exactly encloses another try/finally or try/catch block and the handler ends at the same point the try body ends we had an off by one issue in our reprentation of the ilOffset on the leave chain islands. This fixes the off by one issue for that kind of basic block. The C# compiler seems to always inject a nop to avoid this issue, but I do not know why and I can find no justification for that rule.
Fixes badcodeinsidefinally tests