Skip to content

JIT: copy large local structs through their address when decomposing - #135486

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:egorbo/fix-jit-133581
Oct 10, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:egorbo/fix-jit-133581

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

When lowering decomposes a GC-containing struct copy into individual stores, it reads a local source through LCL_FLD nodes. Their offsets are limited to 16 bits, so with structs larger than 64 KiB they wrapped. The copy then read the wrong data, dropping fields past 64 KiB (Checked builds asserted).

If the local's fields cannot all be encoded as LCL_FLDs (IsValidLclAddr), take the local's address once and load each piece through it. This is the same path already used for indirect sources.

Fixes #133581

No diffs

PR description draft:
<!-- -->
When lowering decomposes a GC-containing struct copy into individual stores, it reads a local source through LCL_FLD nodes. Their offsets are limited to 16 bits, so with structs larger than 64 KiB they wrapped. The copy then read the wrong data, dropping fields past 64 KiB (Checked builds asserted).

If the local's fields cannot all be encoded as LCL_FLDs (IsValidLclAddr), take the local's address once and load each piece through it. This is the same path already used for indirect sources.

Add a single-file regression copying a 65600-byte struct, with a GC ref and a long beyond 64 KiB, to a heap field and to a ref destination.

Fixes dotnet#133581

Co-authored-by: Copilot <[email protected]>
Copilot-Session: ae8155d6-f240-4542-a1da-c721ba933c91
@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 Oct 9, 2026
@EgorBo
EgorBo requested a balanced review from Copilot October 9, 2026 10:04
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 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.

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

The focused fix appears consistent, but cross-platform JIT lowering and GC behavior require completed CI and maintainer validation.

0 open findings

What changed in this PR

Fixes JIT corruption when decomposing copies of GC-containing structs larger than 64 KiB.

Changes:

  • Loads oversized local structs through their address instead of overflowing LCL_FLD offsets.
  • Adds regression coverage for heap-field and ref destinations.
File Description
src/​coreclr/​jit/​lower.cpp Adds address-based source loading for large struct copies.
src/​tests/​JIT/​Regression_ro_2/​Runtime_133581.cs Verifies fields beyond the 64-KiB boundary are copied correctly.

🧠 Review effort: Balanced

@EgorBo

EgorBo commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib

@EgorBo
EgorBo requested a review from a team October 9, 2026 14:49

@JulieLeeMSFT JulieLeeMSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: the LCL_ADDR fallback for non-encodable LCL_FLD sources correctly reuses the ReplaceWithLclVar spill pattern from the GT_IND path, leaves no orphaned or dangling nodes in the post-loop cleanup, and clears the stale contained flag.

@EgorBo
EgorBo merged commit 1bfed53 into dotnet:main Oct 10, 2026
147 of 149 checks passed
@EgorBo
EgorBo deleted the egorbo/fix-jit-133581 branch October 10, 2026 13:08
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 13, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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) Copying a struct larger than 64 KiB silently drops fields past the 64 KiB mark

4 participants