Skip to content

Conversation

@jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Nov 10, 2025

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).
Copilot AI review requested due to automatic review settings November 10, 2025 17:29
@github-actions github-actions bot 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
Contributor

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

Copy link
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 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.

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

@VSadov
Copy link
Member

VSadov commented Nov 10, 2025

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

@VSadov
Copy link
Member

VSadov commented Nov 11, 2025

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

Copy link
Member

@VSadov VSadov left a comment

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
Member Author

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

@jakobbotsch jakobbotsch merged commit 7bcfee1 into dotnet:main Nov 11, 2025
112 of 122 checks passed
@jakobbotsch jakobbotsch deleted the fix-async-valid-emit-loc branch November 11, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants