Skip to content

JIT: Avoid implicit byref retbufs in async calls #115888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jakobbotsch
Copy link
Member

The check in the importer did not take into account that a LCL_ADDR of an implicit byref local will turn into LCL_VAR after morph. The async transformation requires the retbuf to be the address of a local, so enhance the check to take this into account.

Also switch the compIsAsync() check to call->IsAsync(). Inside async functions it is ok for non-async calls to use the normal logic.

Fix #115884

The check in the importer did not take into account that a `LCL_ADDR` of
an implicit byref local will turn into `LCL_VAR` after morph. The async
transformation requires the retbuf to be the address of a local, so
enhance the check to take this into account.

Also switch the `compIsAsync()` check to `call->IsAsync()`. Inside async
functions it is ok for non-async calls to use the normal logic.
@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 May 22, 2025
Copy link
Contributor

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

@jakobbotsch jakobbotsch marked this pull request as ready for review May 22, 2025 15:22
@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 15:22
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @EgorBo

@jakobbotsch jakobbotsch requested a review from EgorBo May 22, 2025 15:22
Copy link
Contributor

@Copilot 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 centralizes return-buffer legality checks by introducing impIsLegalRetBuf and replaces ad-hoc logic in impStoreStruct with calls to the new helper, ensuring proper handling for async and non-async calls.

  • Replaces duplicated inline checks in impStoreStruct with impIsLegalRetBuf.
  • Implements Compiler::impIsLegalRetBuf to encapsulate ABI and async invariants.
  • Adds the new helper’s declaration to compiler.h.

Reviewed Changes

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

File Description
src/coreclr/jit/importer.cpp Replaced inline retbuf checks with impIsLegalRetBuf; implemented helper
src/coreclr/jit/compiler.h Declared impIsLegalRetBuf
Comments suppressed due to low confidence (1)

src/coreclr/jit/importer.cpp:1081

  • Consider adding unit or integration tests for impIsLegalRetBuf, especially covering async calls with implicit byref locals and non-async scenarios with byref-like return types.
bool Compiler::impIsLegalRetBuf(GenTree* retBuf, GenTreeCall* call)

@@ -1068,6 +1062,46 @@ GenTree* Compiler::impStoreStruct(GenTree* store,
return store;
}

//------------------------------------------------------------------------
// impIsLegalRetbuf:
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

The comment header uses impIsLegalRetbuf (lowercase 'b') but the function is named impIsLegalRetBuf. Update the comment to match the function’s exact casing for clarity.

Suggested change
// impIsLegalRetbuf:
// impIsLegalRetBuf:

Copilot uses AI. Check for mistakes.

@@ -4797,6 +4797,7 @@ class Compiler
Statement** pAfterStmt = nullptr,
const DebugInfo& di = DebugInfo(),
BasicBlock* block = nullptr);
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

[nitpick] Add a brief Doxygen-style comment above this declaration to explain when impIsLegalRetBuf should be used and its ABI/async guarantees.

Suggested change
BasicBlock* block = nullptr);
BasicBlock* block = nullptr);
/**
* @brief Determines if the specified return buffer is legal for the given call.
*
* This function checks whether the provided return buffer (`retBuf`) is valid
* for use with the specified call (`call`). It ensures compliance with the
* platform's ABI (Application Binary Interface) requirements and handles
* any constraints related to asynchronous operations.
*
* @param retBuf The return buffer to validate.
* @param call The call for which the return buffer is being validated.
* @return true if the return buffer is legal; false otherwise.
*/

Copilot uses AI. Check for mistakes.

Copy link
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

So #115884 happened because retbuf arg was spilled to a local?

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JIT: Assertion failed 'retbufArg->GetNode()->OperIs(GT_LCL_ADDR)' during 'Transform async'
2 participants