Skip to content

JIT: Fix runtime-async awaits of Task<T> upcast to Task - #137251

Merged
jakobbotsch merged 3 commits into
dotnet:mainfrom
jakobbotsch:fix-135215-2
Nov 13, 2026
Merged

jakobbotsch merged 3 commits into
dotnet:mainfrom
jakobbotsch:fix-135215-2

Conversation

@jakobbotsch

@jakobbotsch jakobbotsch commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Folding a Task<T>-returning call followed by AsyncHelpers.Await(Task) leaves an unconsumed result on the IL stack, causing InvalidProgramException. Discard the unused result in the JIT and interpreter while retaining the fold.

Reuse the async variant's call info and skip signature queries for generic Await calls, keeping the common path free of extra JIT-EE calls. Add regression coverage for completed and suspending tasks, ConfigureAwait, and different result types.

Fixes #135215

Folding a Task<T>-returning call followed by AsyncHelpers.Await(Task)
leaves an unconsumed result on the IL stack, causing
InvalidProgramException. Discard the unused result in the JIT and
interpreter while retaining the fold.

Reuse the async variant's call info and skip signature queries for
generic Await<T> calls, keeping the common path free of extra JIT-EE
calls. Add regression coverage for completed and suspending tasks,
ConfigureAwait, and different result types.

Fixes dotnet#135215

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 31ebe810-b436-428b-9238-ba41ee05ed8d
@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, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

Comment thread src/coreclr/interpreter/compiler.cpp Resolved
Identify void Await overloads from the token kind instead of querying their signatures. Track isVoidAwait in the interpreter and retain the async variant return-type check before discarding its result.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 31ebe810-b436-428b-9238-ba41ee05ed8d
@jakobbotsch

Copy link
Copy Markdown
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

Comment thread src/coreclr/jit/importer.cpp Resolved

@AndyAyersMS AndyAyersMS 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, just one possibly misleading comment?

@jakobbotsch

Copy link
Copy Markdown
Member Author

/azp run runtime, runtime-coreclr superpmi-diffs, runtime-dev-innerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@jakobbotsch
jakobbotsch merged commit 9de2163 into dotnet:main Nov 13, 2026
131 of 134 checks passed
@jakobbotsch
jakobbotsch deleted the fix-135215-2 branch November 13, 2026 08:36
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 13, 2026
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.

Runtime-async: invalid program when awaiting generic Task upcasted to Task.

4 participants