Skip to content

Conversation

janvorli
Copy link
Member

When there is a try/catch inside a catch handler and there is a return
in the inner catch or goto going out of the outer catch handler, we were
resuming after the inner catch at the end of the method / goto target,
so we were not returning from the call to the outer catch.
We need to inject a catch leave island that the inner catch returns as
its resume after catch location and that island can then return from the
outer catch.
This mechanism needs to be part of the finally call islands chain so that
returns from catches / calls to finallys happen correctly and in the
right order.
This change extends the finally call islands chain to implement that.

This change also fixes a problem with ordering of emission of the code
for these islands and the basic blocks linking in the GenerateCode
method.
It also fixes a bug in GetNativeRangeForClause that was in some edge
cases getting incorrectly shorter range.

To make reviewing a bit easier, I've split this PR into two commits. The
first adds the actual functionality and the second just renames things
to match the fact that the islands are no longer finally call islands
only.

When there is a try/catch inside a catch handler and there is a return
in the inner catch or goto going out of the outer catch handler, we were
resuming after the inner catch at the end of the method / goto target,
so we were not returning from the call to the outer catch.
We need to inject a catch leave island that the inner catch returns as
its resume after catch location and that island can then return from the
outer catch.
This mechanism needs to be part of the finally call islands chain so that
returns from catches / calls to finallys happen correctly and in the
right order.
This change extends the finally call islands chain to implement that.

This change also fixes a problem with ordering of emission of the code
for these islands and the basic blocks linking in the GenerateCode
method.
It also fixes a bug in GetNativeRangeForClause that was in some edge
cases getting incorrectly shorter range.

To make reviewing a bit easier, I've split this PR into two commits. The
first adds the actual functionality and the second just renames things
to match the fact that the islands are no longer finally call islands
only.
@janvorli janvorli self-assigned this Oct 16, 2025
@janvorli janvorli requested a review from BrzVlad as a code owner October 16, 2025 21:55
@Copilot Copilot AI review requested due to automatic review settings October 16, 2025 21:55
@janvorli janvorli requested a review from kg as a code owner October 16, 2025 21:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the interpreter where returns or gotos from an inner catch handler that exit an outer catch were not properly resuming execution after the outer catch. The fix introduces a "catch leave island" mechanism (similar to existing "finally call islands") to ensure proper control flow when leaving nested catch handlers.

Key changes:

  • Introduced catch leave islands to handle leaves from catch handlers that exit outer catch regions
  • Extended the finally call island chain to include catch leave islands, creating a unified "leave chain island" mechanism
  • Fixed the ordering of code emission for islands and basic block linking in GenerateCode
  • Fixed a bug in GetNativeRangeForClause that was returning incorrect ranges in edge cases

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/interpreter/compiler.h Renamed pFinallyCallIslandBB to pLeaveChainIslandBB to reflect that it handles both finally calls and catch leaves; added isFinallyCallIsland flag to distinguish island types
src/coreclr/interpreter/compiler.cpp Implemented catch leave island creation, unified finally call and catch leave island handling, fixed GetNativeRangeForClause clause type check, and reordered island code generation before basic block linking

Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants