Skip to content

JIT: Make async insertion of "rethrow BB" deterministic to fix debug info#123343

Merged
jakobbotsch merged 1 commit intodotnet:mainfrom
jakobbotsch:fix-123316
Jan 21, 2026
Merged

JIT: Make async insertion of "rethrow BB" deterministic to fix debug info#123343
jakobbotsch merged 1 commit intodotnet:mainfrom
jakobbotsch:fix-123316

Conversation

@jakobbotsch
Copy link
Copy Markdown
Member

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.

Fix #123316

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.
Copilot AI review requested due to automatic review settings January 19, 2026 11:51
@jakobbotsch jakobbotsch changed the title JIT: Make async insertion of "rethrow BB" deterministic JIT: Make async insertion of "rethrow BB" deterministic to fix debug info Jan 19, 2026
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 19, 2026
Copy link
Copy Markdown
Contributor

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 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 fgNewBBinRegion to fgNewBBafter to 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

@jakobbotsch jakobbotsch added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 19, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
See info in area-owners.md if you want to be subscribed.

@jakobbotsch
Copy link
Copy Markdown
Member Author

cc @dotnet/jit-contrib PTAL @EgorBo

@jakobbotsch jakobbotsch requested a review from EgorBo January 20, 2026 10:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Runtime-async] Valid mappings not guaranteed after Await (causing incomplete/misleading stacktrace)

4 participants