Skip to content

JIT: don't treat wide retbuf writes as local defs - #137400

Merged
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-135393
Nov 12, 2026
Merged

AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-135393

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

When a call's return buffer is the address of a promoted struct field reinterpreted (via Unsafe.As) as a larger struct, local morph treated the call as a definition of just the field local, even though the callee writes past it. Value numbering then asserted (newLclValue.BothDefined()), and release builds corrupted the stack.

Skip the retbuf def optimization when the return buffer write is wider than the local, so the address escapes and the parent struct is exposed instead.

Regressed in .NET 9; .NET 8 is correct.

Validation

Windows x64 Checked:

  • .\build.cmd clr+libs -rc checked -lc release and .\src\tests\build.cmd x64 checked -Test JIT\Regression_ro_2\Regression_ro_2.csproj: passed.
  • New test Runtime_135393 (three widened-field shapes) hits the assert at valuenum.cpp:6745 with the unfixed JIT and passes with the fix.
  • SuperPMI asmdiffs (superpmi.py asmdiffs, all 11 windows x64 collections): no diffs.

Other platforms were not run.

Fixes #135393

Note

This PR description was generated by GitHub Copilot.

When a call's return buffer is the address of a promoted struct field
reinterpreted as a larger struct, the call writes past the field local.
Skip the retbuf def optimization when the write is wider than the local,
so the address escapes and the parent is exposed.

Fixes dotnet#135393.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 2b1949ed-a04d-4712-b2f5-54bbe4aec174
@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 12, 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.

@AndyAyersMS
AndyAyersMS requested review from jakobbotsch and a balanced review from Copilot November 12, 2026 01:21
@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

@jakobbotsch PTAL
fyi @dotnet/jit-contrib

Simple fix in local morph

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

No active review issues were identified for the change to oversized return-buffer write handling.

No open issues 🎉

What changed in this PR

This PR fixes CoreCLR JIT handling of return-buffer writes that extend beyond a promoted struct field, addressing assertion failures and stack corruption.

Changes:

  • Guard the local-definition optimization using the return size and destination offset, allowing oversized writes to follow address-escape handling.
  • Add regression coverage for widened writes starting at the first field, a later field, and a smaller field.
File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_135393.cs Tests three widened-field writes and verifies the resulting field values.
src/​coreclr/​jit/​lclmorph.cpp Uses IsWideAccess to exclude oversized return-buffer writes from local-definition tracking.

Review effort: Balanced

@AndyAyersMS

Copy link
Copy Markdown
Member Author

/ba-g osx build timeout

@AndyAyersMS
AndyAyersMS merged commit 4ab4fb6 into dotnet:main Nov 12, 2026
133 of 136 checks passed
@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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: (bug) return buffer written through a widened ref to a promoted Vector4 field causes assert / AccessViolationException

3 participants