Skip to content

[Wasm RyuJIT] Handle case where a TYP_STRUCT return has had its type information erased and we are trying to write it to a TYP_STRUCT local#125279

Merged
kg merged 4 commits intodotnet:mainfrom
kg:issue125199-2
Mar 9, 2026
Merged

Conversation

@kg
Copy link
Member

@kg kg commented Mar 6, 2026

Addresses part of #125199
Don't love this solution, feedback welcome.

Copilot AI review requested due to automatic review settings March 6, 2026 21:39
@kg kg added arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels Mar 6, 2026
@kg
Copy link
Member Author

kg commented Mar 6, 2026

cc @AndyAyersMS

@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 fixes a crash in the Wasm RyuJIT backend's RewriteLocalStackStore function that occurs when a CALL node returns a small struct as a primitive type (e.g., TYP_INT) due to WASM ABI type erasure, but the STORE_LCL_VAR node still has TYP_STRUCT as its type. The crash happened because the code tried to create a STORE_BLK node via gtNewStoreBlkNode, which requires the value to have struct layout information—but the value's type info had been erased to a primitive type.

Changes:

  • Modified the isStruct check to require both the store destination and the value to be TYP_STRUCT, preventing the code from attempting to create a STORE_BLK when the value has no layout.
  • In the non-struct else branch, when storeType is TYP_STRUCT (type mismatch case), the code now uses the value's actual type instead, avoiding the assert(type != TYP_STRUCT) in gtNewStoreIndNode.

@kg kg marked this pull request as ready for review March 7, 2026 00:26
Copilot AI review requested due to automatic review settings March 7, 2026 00:26
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

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

@kg
Copy link
Member Author

kg commented Mar 9, 2026

cc @dotnet/jit-contrib

kg added 2 commits March 9, 2026 10:18
…ased and we are trying to write it to a TYP_STRUCT local
@SingleAccretion
Copy link
Contributor

Don't love this solution, feedback welcome.

Heh, the contract is surprisingly convoluted when it comes to these stores.

I think the right logic should be something like:

var_types storeType  = lclNode->TypeGet();
if ((storeType == TYP_STRUCT) && lclNode->OperIsCopyBlkOp()) {
  var_types lclRegType = varDsc->GetRegisterType(lclStore);
  if (lclRegType != TYP_UNDEF)
    storeType = lclRegType;
}

@kg kg force-pushed the issue125199-2 branch from 926b3b4 to 026c7db Compare March 9, 2026 18:30
@kg
Copy link
Member Author

kg commented Mar 9, 2026

Don't love this solution, feedback welcome.

Heh, the contract is surprisingly convoluted when it comes to these stores.

I think the right logic should be something like:

var_types storeType  = lclNode->TypeGet();
if ((storeType == TYP_STRUCT) && lclNode->OperIsCopyBlkOp()) {
  var_types lclRegType = varDsc->GetRegisterType(lclStore);
  if (lclRegType != TYP_UNDEF)
    storeType = lclRegType;
}

I like that a lot better, thanks! It seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture 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.

4 participants