Skip to content

Fix ReadyToRun allocation side effects for versionable base types - #137933

Merged
jkotas merged 4 commits into
mainfrom
copilot/crossgen-fix-allocator-bug
Nov 20, 2026
Merged

jkotas merged 4 commits into
mainfrom
copilot/crossgen-fix-allocator-bug

Conversation

@jkotas

@jkotas jkotas commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Crossgen2 can hoist an in-bubble type’s allocation above a throwing argument even when an out-of-bubble base could gain a finalizer. After the base is updated, this can finalize an object whose constructor never ran.

  • Compiler: Check version-bubble membership across the inheritance chain, stopping at System.Object, which cannot gain a finalizer.
  • Regression coverage: Extend existing versioning tests with direct, derived, and indirectly derived allocations after a throwing argument.

@azure-pipelines

azure-pipelines Bot commented Nov 19, 2026 •

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: @dotnet/crossgen-contrib
See info in area-owners.md if you want to be subscribed.

@jkotas jkotas changed the title [WIP] Fix allocation behavior for in-bubble types with out-of-bubble base Fix ReadyToRun allocation side effects for versionable base types Nov 19, 2026
@jkotas
jkotas marked this pull request as ready for review November 19, 2026 18:28
@jkotas
jkotas requested review from EgorBo and davidwrighton and a balanced review from Copilot November 19, 2026 18:28

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

Execution was unavailable, leaving unverified whether mainv2 runs the new allocation methods as ReadyToRun code and whether derived and indirect cases fail without the fix and pass with it.

No open issues 🎉

What changed in this PR

Fixes Crossgen2’s ReadyToRun allocation analysis to account for base types outside the version bubble that could gain a finalizer. This preserves allocation ordering around throwing arguments, preventing finalization of objects whose constructors never ran.

Changes:

  • Check version-bubble membership throughout the inheritance chain, stopping at System.Object.
  • Extend versioning regression tests with direct, derived, and indirectly derived allocations after a throwing argument.
File Description
src/​tests/​readytorun/​tests/​test.cs Adds a versioned fixture that gains a finalizer and tracks finalization.
src/​tests/​readytorun/​tests/​main.cs Adds allocation-ordering checks for three inheritance scenarios.
src/​coreclr/​tools/​aot/​ILCompiler.ReadyToRun/​JitInterface/​CorInfoImpl.ReadyToRun.cs Includes versionable base types when determining allocation side effects.

Review effort: Balanced

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

Generally good, need to handle ValueTypes specially.

@jkotas
jkotas requested a review from davidwrighton November 19, 2026 21:13
@jkotas

jkotas commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

/ba-g dead letter

@jkotas
jkotas merged commit 223be71 into main Nov 20, 2026
99 of 101 checks passed
@jkotas
jkotas deleted the copilot/crossgen-fix-allocator-bug branch November 20, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

5 participants