Skip to content

JIT: preserve GTF_IND_INITCLASS when inlining BOX of Nullable<T> - #135835

Merged
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:fix/jit-135817-nullable-initclass
Oct 15, 2026
Merged

EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:fix/jit-135817-nullable-initclass

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

impImportAndPushBoxForNullable gets the indirection flags of the boxed value from impGetNodeAddr (which also splits off the class-init helper into a separate statement) but never applied them to the decomposed hasValue/value loads. Without GTF_IND_INITCLASS, loop hoisting moved a static Nullable field load ahead of the static constructor check. Pass the flags to both loads.

Fixes #135817

No diffs

impImportAndPushBoxForNullable gets the indirection flags of the boxed value from impGetNodeAddr
(which also splits off the class-init helper into a separate statement) but never applied them to
the decomposed hasValue/value loads. Without GTF_IND_INITCLASS, loop hoisting moved a static
Nullable<T> field load ahead of the static constructor check. Pass the flags to both loads.

Fixes dotnet#135817

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6ec7c151-8b7f-4bf9-8b1a-8c601a2965ec
@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 15, 2026
@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.

@EgorBo
EgorBo requested a balanced review from Copilot October 15, 2026 01:55
@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

JIT build validation and confirmation that the regression fails before the fix and passes afterward remain unverified.

0 open findings

What changed in this PR

Fixes nullable boxing in the JIT so static field loads retain their class-initialization dependency and cannot be hoisted before initialization.

Changes:

  • Preserves indirection flags on both decomposed nullable loads.
  • Adds a regression test for boxing a static nullable field inside a loop.
File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_135817.cs Adds the reported regression scenario.
src/​coreclr/​jit/​importer.cpp Passes indirection flags to both nullable loads.

🧠 Review effort: Balanced

@EgorBo
EgorBo requested a review from a team October 15, 2026 13:09
@EgorBo

EgorBo commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib, trivial change, no diffs

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

This looks reasonable to me. Very straightforward fix

@EgorBo
EgorBo merged commit 3994df1 into dotnet:main Oct 15, 2026
134 of 136 checks passed
@EgorBo
EgorBo deleted the fix/jit-135817-nullable-initclass branch October 15, 2026 23:58
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 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) impImportAndPushBoxForNullable drops GTF_IND_INITCLASS, allowing Nullable<T> loads to be hoisted before static constructor

3 participants