Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

Fixes the build crash in #121697.

Since with TrimMode=partial, we consider all static fields targets of reflection, we cannot allow inlining their contents. With full trimming allowed, the optimization is unlocked and we hit an assert when trying to nullcheck a constant.

Fixes the build crash in dotnet#121697.

Since with TrimMode=partial, we consider all static fields targets of reflection, we cannot allow inlining their contents. With full trimming allowed, the optimization is unlocked and we hit an assert when trying to nullcheck a constant.
@MichalStrehovsky MichalStrehovsky added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 17, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a build crash (#121697) that occurs when trying to perform null checks on frozen objects during unbox optimization. The issue arises with full trimming enabled, where static field contents can be inlined, and the JIT encounters an assertion failure when attempting to null-check constants (frozen/preinitialized objects).

  • Conditionally generates null checks only when fgAddrCouldBeNull returns true
  • Skips null checks for frozen/preinitialized objects that cannot be null
  • Adds explanatory comment for the optimization

@jakobbotsch
Copy link
Member

we hit an assert when trying to nullcheck a constant

What assert?

@MichalStrehovsky
Copy link
Member Author

we hit an assert when trying to nullcheck a constant

What assert?

gtNewNullCheck asserts that the value can be null.

Copy link
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

Interesting, I can see why we never hit it on CoreCLR before

@MichalStrehovsky MichalStrehovsky merged commit ea694d8 into dotnet:main Nov 17, 2025
120 checks passed
@MichalStrehovsky MichalStrehovsky deleted the unboxfrozen branch November 17, 2025 22:02
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.

3 participants