JIT: Make async insertion of "rethrow BB" deterministic to fix debug info#123343
Merged
jakobbotsch merged 1 commit intodotnet:mainfrom Jan 21, 2026
Merged
JIT: Make async insertion of "rethrow BB" deterministic to fix debug info#123343jakobbotsch merged 1 commit intodotnet:mainfrom
jakobbotsch merged 1 commit intodotnet:mainfrom
Conversation
When an async resumption needs to rethrow an exception we use `fgNewBBinRegion` to create a basic block where the rethrow happens. This results in an internal basic block being created, and to ensure that basic block does not break debug info for surrounding code there is some compensating code that makes the block IL-imported. It turns out this compensating code is not enough. The code assumes that `fgNewBBinRegion` inserts after a specific basic block, but for a few reasons (related to old fall-through behavior) that may not be the case. If we end up inserting the block elsewhere we still have the potential of breaking debug info. Fix the issue by always inserting the rethrow BB after the async call that we rethrow for. The compensation code can be simplified slightly as well once we do that.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a non-deterministic code generation issue in the JIT's async transformation where a rethrow basic block could be inserted in an unpredictable location, potentially breaking debug information.
Changes:
- Changed block insertion method from
fgNewBBinRegiontofgNewBBafterto ensure deterministic placement - Simplified the condition for removing BBF_INTERNAL flag since the block is now always inserted after the async call block
- Updated comments to reflect the deterministic insertion behavior
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
Member
Author
|
cc @dotnet/jit-contrib PTAL @EgorBo |
AndyAyersMS
approved these changes
Jan 20, 2026
EgorBo
approved these changes
Jan 20, 2026
This was referenced Jan 21, 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 an async resumption needs to rethrow an exception we use
fgNewBBinRegionto create a basic block where the rethrow happens. This results in an internal basic block being created, and to ensure that basic block does not break debug info for surrounding code there is some compensating code that makes the block IL-imported.It turns out this compensating code is not enough. The code assumes that
fgNewBBinRegioninserts after a specific basic block, but for a few reasons (related to old fall-through behavior) that may not be the case. If we end up inserting the block elsewhere we still have the potential of breaking debug info.Fix the issue by always inserting the rethrow BB after the async call that we rethrow for. The compensation code can be simplified slightly as well once we do that.
Fix #123316