Skip to content

Fix auto-layout gap filling for derived classes - #138180

Open
jkoritzinsky wants to merge 1 commit into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/derived-field-layout
Open

jkoritzinsky wants to merge 1 commit into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/derived-field-layout

Conversation

@jkoritzinsky

@jkoritzinsky jkoritzinsky commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Auto-layout gap filling can confuse a by-value field's size in bytes with a primitive field's logarithmic size class. This can place derived fields over base or struct fields, silently corrupting data.

Exclude by-value fields from the candidate scan while preserving GC-reference handling. Add regression cases for one-byte and empty structs, reference and long fields, and overlap with a later struct field.

Validation on Windows x64:

  • .\build.cmd clr+libs+host -rc Checked: passed on the unfixed baseline.
  • Four regression cases failed individually on the unfixed runtime.
  • .\build.cmd clr.runtime -rc Checked: passed after the fix.
  • .\src\tests\build.cmd x64 Checked -GenerateLayoutOnly /p:LibrariesConfiguration=Debug /p:HostConfiguration=Debug: passed.
  • Standalone ManagedSequential runner: all 10 tests passed with the fixed runtime, both normally and with ReadyToRun and tiering disabled.

Resolves #138000

Note

This pull request description was generated with GitHub Copilot.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 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: @agocke
See info in area-owners.md if you want to be subscribed.

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

Backport candidate?

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 remain for the auto-layout gap-filling change.

No open issues 🎉

What changed in this PR

Fixes CoreCLR auto-layout gap filling so derived fields do not overlap base or struct fields when a struct’s byte size is mistaken for a primitive size class.

Changes:

  • Excludes by-value fields from the gap-filling candidate scan while preserving GC-reference handling.
  • Adds four regression cases covering one-byte and empty structs, reference and long fields, and overlap with a later struct field.
File Description
src/​tests/​Loader/​classloader/​SequentialLayout/​ManagedSequential/​ManagedSequential.cs Adds field-value checks that detect layout overlap across four regression cases.
src/​coreclr/​vm/​methodtablebuilder.cpp Filters out by-value fields when selecting the next gap-filling candidate.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Regression in .NET 10: auto layout places a derived class field at offset 0, over a base class field

3 participants