Skip to content

[Wasm / RyuJit]: don't mark CORINFO_HELP_GETREFANY pure on wasm#129060

Open
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-wasm-getrefany-purity
Open

[Wasm / RyuJit]: don't mark CORINFO_HELP_GETREFANY pure on wasm#129060
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-wasm-getrefany-purity

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

The wasm ABI passes TypedReference as implicit byref. So CORINFO_HELP_GETREFANY cannot be considered pure (just like on windows x64).

Affects refanyval users JIT/Methodical/refany/array2_{d,r} and array3_{d,r}.

See #128234 (comment)

The wasm ABI passes any struct without a single scalar lowering by
implicit byref (WasmClassifier::Classify -> passByRef = true for
CORINFO_WASM_TYPE_VOID). TypedReference is two pointers and has no
scalar lowering, so its struct arg to GETREFANY is implicit byref --
the same situation as win-x64 that dotnet#80292 already guarded against.

Marking the helper pure in this case violates the contract enforced by
fgValueNumberHelperCallFunc's default branch and trips:

  Assertion failed '!arg.AbiInfo.IsPassedByReference() && "Helpers
  taking implicit byref arguments should not be marked as pure"' in
  'JitTest_array2_refany_il.Test:TestRef(System.TypedReference)' during
  'Do value numbering' (valuenum.cpp:14328)

Affects refanyval users JIT/Methodical/refany/array2_{d,r} and
array3_{d,r}.

Fix: exclude TARGET_WASM from the pure-marking guard alongside
WINDOWS_AMD64_ABI, and expand the comment so future ports know to
re-evaluate. Other FEATURE_IMPLICIT_BYREFS targets (arm64, riscv64,
loongarch64) pass the 16-byte aggregate in two registers and are not
affected.

Verified: with the fix, crossgen2 emits array2_d.wasm and array3_r.wasm
successfully (no assert), and both tests pass at runtime under R2R.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 5, 2026 23:23
@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 Jun 5, 2026
@AndyAyersMS
Copy link
Copy Markdown
Member Author

@dotnet/wasm-contrib PTAL
fyi @dotnet/jit-contrib

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

Copy link
Copy Markdown
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 adjusts JIT helper-call metadata so CORINFO_HELP_GETREFANY is not treated as a pure helper when targeting Wasm, aligning with the Wasm ABI behavior where TypedReference is passed as an implicit byref (i.e., the helper can observe memory).

Changes:

  • Stop marking CORINFO_HELP_GETREFANY as isPure for TARGET_WASM in HelperCallProperties::init().
  • Expand the existing comment to document why Wasm matches the Windows x64 “implicit byref” purity restriction for this helper.

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.

3 participants