Skip to content

JIT: Fix wasm ABI register type mismatch - #133510

Merged
AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:fix-wasm-abi-register-type
Sep 11, 2026
Merged

AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:fix-wasm-abi-register-type

Conversation

@AndyAyersMS

@AndyAyersMS AndyAyersMS commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Fixes #133502.

The wasm register allocator previously assigned an enregistered struct argument directly to its ABI parameter register even when their wasm value types differed. Keep the ABI parameter in its original register, allocate the local using its canonical register type, and reinterpret the value while homing parameters in the prolog.

Adds a focused regression test for a single-double fixed-buffer wrapper.

Note

This pull request description was generated with GitHub Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e89a8f4e-a8a4-438c-ae2f-264cc6b2be41
Copilot AI lite review requested due to automatic review settings September 9, 2026 17:12
@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 Sep 9, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 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.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@dotnet/wasm-contrib FYI

@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Sep 9, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

Copilot AI 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.

🟢 Approval recommended

The changes are targeted, preserve existing wasm RA invariants, and add a focused regression test covering the reported type-mismatch scenario.

Pull request overview

This PR fixes a WebAssembly ABI/register-allocation mismatch where a struct parameter could be treated as enregistered in its ABI parameter local even when the wasm value type didn’t match the local’s canonical register type, and adds a small regression to cover the scenario.

Changes:

  • Update wasm reg allocation to only pin a parameter local to its ABI register when the wasm value types match; otherwise allocate a new local of the canonical type.
  • Teach wasm prolog homing to bitcast (reinterpret) the incoming ABI-typed parameter local into the RA-assigned local when their types differ.
  • Add a focused JitBlue regression test for a fixed-buffer wrapper containing a single double.
File summaries
File Description
src/coreclr/jit/regallocwasm.cpp Avoid forcing ABI-parameter register assignment when the wasm value type differs from the virtual/canonical register type.
src/coreclr/jit/codegenwasm.cpp Add a centralized wasm bitcast instruction helper and use it in prolog parameter homing to reinterpret between ABI and local register types.
src/tests/JIT/Regression/JitBlue/Runtime_133502/Runtime_133502.csproj New regression test project enabling unsafe (for fixed buffers) and optimized compilation.
src/tests/JIT/Regression/JitBlue/Runtime_133502/Runtime_133502.cs New regression test exercising struct argument passing/return with a single-double fixed buffer.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8a89f1ed-34bb-452a-aefe-95d85e695c3b
Copilot AI review requested due to automatic review settings September 10, 2026 16:34
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@lewing can you re-approve (removed the test exclusion)

Copilot AI 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.

🔵 Needs a closer look

It changes low-level wasm JIT register assignment and prolog code emission in ways that can subtly affect validation/codegen, so a human maintainer should do the final correctness/risk review.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@AndyAyersMS

Copy link
Copy Markdown
Member Author

57 test failures all in mono testing. Unrelated.

@lewing any suggestions as to how to handle these? Are we at some point going to disable mono testing?

@AndyAyersMS

Copy link
Copy Markdown
Member Author

Failures are tracked in #133702

@AndyAyersMS

Copy link
Copy Markdown
Member Author

/ba-g known failures with mono testing

@AndyAyersMS
AndyAyersMS merged commit f362119 into dotnet:main Sep 11, 2026
141 of 143 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 14, 2026
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.

[wasm][R2R] StructABI emits invalid reinterpret operand type

4 participants