Repository navigation
JIT: don't treat wide retbuf writes as local defs - #137400
Merged
Merged
Conversation
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
|
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
requested review from
jakobbotsch
and
a balanced review from Copilot
November 12, 2026 01:21
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Member
Author
|
@jakobbotsch PTAL Simple fix in local morph |
Contributor
There was a problem hiding this comment.
🟢 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
jakobbotsch
approved these changes
Nov 12, 2026
This was referenced Nov 12, 2026
Member
Author
|
/ba-g osx build timeout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 releaseand.\src\tests\build.cmd x64 checked -Test JIT\Regression_ro_2\Regression_ro_2.csproj: passed.Runtime_135393(three widened-field shapes) hits the assert atvaluenum.cpp:6745with the unfixed JIT and passes with the fix.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.