Skip to content

[release/11.0] Fix Enum.Equals folding for nullable boxed arguments - #137392

Merged
JulieLeeMSFT merged 1 commit into
release/11.0from
backport/pr-133826-to-release/11.0
Nov 13, 2026
Merged

JulieLeeMSFT merged 1 commit into
release/11.0from
backport/pr-133826-to-release/11.0

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #133826 to release/11.0

/cc @AndyAyersMS @copilot

Customer Impact

  • Customer reported
  • Found internally

Incorrect null reference exception from a bad JIT optimization.

#137270 noted this fix was missing in 11.0. #137382 shows that this issue can occur in the iText package.

Regression

  • Yes
  • No

Regression in 11.0, introduced in #122779

Testing

Issue was fixed in main after 11.0 branched, not backported.

Testing in progress, will update when done.

Risk

Low, porting an existing fix from main.

<!-- -->

Boxing a nullable enum can yield `null` while retaining an exact enum
type. `Enum.Equals` folding currently dereferences that argument,
throwing instead of returning `false`.

- **JIT:** Require a known non-null argument before comparing boxed
payloads; otherwise retain the call. Preserve null-receiver exception
behavior.
- **Coverage:** Add nullable-boxing cases for null, equal, and unequal
arguments.

<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #133817

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: EgorBo <[email protected]>
@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.

@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 Nov 11, 2026
@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.

@AndyAyersMS
AndyAyersMS requested a balanced review from Copilot November 11, 2026 23:25
@AndyAyersMS AndyAyersMS added this to the 11.0.0 milestone Nov 11, 2026

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 JIT servicing backport received only static review, leaving nullable regression behavior unverified under optimized JIT and NativeAOT before merge.

No open issues 🎉

What changed in this PR

Backports #133826 to release/11.0 to fix incorrect NullReferenceException behavior when Enum.Equals receives a boxed nullable enum with no value.

Changes:

  • Requires a known non-null argument before folding Enum.Equals into a payload comparison, preserving null-receiver exception behavior.
  • Adds regression cases for null, equal, and unequal nullable enum arguments.

Builds and tests were not run during this review.

File Description
src/​tests/​JIT/​Intrinsics/​EnumIntrinsics.cs Adds nullable enum argument regression coverage.
src/​coreclr/​jit/​gentree.cpp Prevents unsafe folding when the boxed argument may be null.

Review effort: Balanced

@AndyAyersMS AndyAyersMS added the Servicing-consider Issue for next servicing release review label Nov 11, 2026
@AndyAyersMS
AndyAyersMS requested a review from EgorBo November 11, 2026 23:41
@AndyAyersMS

Copy link
Copy Markdown
Member

fyi @dotnet/jit-contrib
@EgorBo PTAL if you're back

@JulieLeeMSFT

Copy link
Copy Markdown
Member

/ba-g known issues.

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 Servicing-approved Approved for servicing release

Projects

None yet

4 participants