Skip to content

JIT: Handle possibility of late optimized out async calls - #121502

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
jakobbotsch:fix-async-valid-emit-loc
Nov 11, 2025
Merged

JIT: Handle possibility of late optimized out async calls#121502
jakobbotsch merged 1 commit into
dotnet:mainfrom
jakobbotsch:fix-async-valid-emit-loc

Conversation

@jakobbotsch

@jakobbotschjakobbotsch commented Nov 10, 2025

Copy link
Copy Markdown
Member

If we optimize an async call away after the suspension/resumption code has been created then the emit locations used for resumption info and diagnostic info will not be valid. Handle this rare case by just storing 0. The value should not matter as we will never suspend here.

Suspension blocks can be removed in this case, but resumption blocks cannot as they are referenced by the resumption switch. Ideally we would model things so that resumption blocks could too be removed in these cases, but that's not so simple.

Fixes issue reported in #121298 (comment)

If we optimize an async call away after the suspension/resumption code
has been created then the emit locations used for resumption info and
diagnostic info will not be valid. Handle this rare case by just storing
0. The value should not matter as we will never suspend here.
Ideally we would model things so that suspension/resumption blocks could
too be removed in these cases, but that's not so simple (we do not have
a mechanism to represent a data dependency of a basic block, only a
control flow dependency).
CopilotAI review requested due to automatic review settings November 10, 2025 17:29
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 10, 2025
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 addresses a rare edge case where async calls are optimized away late in the compilation process, after suspension/resumption code has already been created. The fix ensures that invalid emit locations are safely handled by checking validity before use.

Key Changes

  • Added validity checks for emitLocation objects before dereferencing them
  • Use fallback values (nullptr/0) when emit locations are invalid due to late optimizations
  • Conditional relocation recording to avoid processing invalid targets

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

FileDescription
src/coreclr/jit/emit.cppAdded validity check before calling emitOffsetToPtr, uses nullptr as fallback, and conditionally records relocation only for valid targets
src/coreclr/jit/codegencommon.cppAdded validity check before calling CodeOffset, uses 0 as fallback for diagnostic native offset

@VSadov

Copy link
Copy Markdown
Member

I will run this in the Libraries + async PR. In most legs this was the only failure remaining.

@VSadov

Copy link
Copy Markdown
Member

I will run this in the Libraries + async PR. In most legs this was the only failure remaining.

I did not see the assert in the PR with these changes added

@VSadovVSadov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks!

@jakobbotsch

Copy link
Copy Markdown
MemberAuthor

/ba-g Android timeout, and async only change whose testing was done out-of-band

@jakobbotsch
jakobbotsch merged commit 7bcfee1 into dotnet:mainNov 11, 2025
112 of 122 checks passed
@jakobbotsch
jakobbotsch deleted the fix-async-valid-emit-loc branch November 11, 2025 12:38
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Dec 12, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIruntime-async

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jakobbotsch@VSadov@jkotas