Skip to content

Fix Enum.Equals folding for nullable boxed arguments - #133826

Merged
EgorBo merged 3 commits into
mainfrom
copilot/fix-nullreferenceexception-enum-equals
Sep 24, 2026
Merged

EgorBo merged 3 commits into
mainfrom
copilot/fix-nullreferenceexception-enum-equals

Conversation

Copilot AI commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

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.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 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 Sep 13, 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.

Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Enum.Equals folding for null argument to return false Fix Enum.Equals folding for nullable boxed arguments Sep 13, 2026
Copilot AI requested a review from EgorBo September 13, 2026 16:55
@EgorBo

EgorBo commented Sep 13, 2026

Copy link
Copy Markdown
Member

@copilot fix ci failures

Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>

Copilot AI commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix ci failures

Fixed in e2f6aba. Enum-valued [InlineData] broke assembly aliases in the merged runner; all four cases now run from TestEntryPoint. Reproduced the CI compile failure, then rebuilt JIT_others successfully and passed enum coverage in four JIT modes. The other failures in that CI run are known issues #133798 and #133645.

@EgorBo
EgorBo marked this pull request as ready for review September 14, 2026 10:43
Copilot AI lite review requested due to automatic review settings September 14, 2026 10:43
@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.

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

The fix is narrowly scoped and includes regression coverage with no unresolved review comments.

Pull request overview

Fixes JIT Enum.Equals folding for nullable enum values that box to null.

Changes:

  • Guard payload comparison until the argument is known non-null.
  • Add nullable-boxing regression tests.
File summaries
File Description
src/tests/JIT/Intrinsics/EnumIntrinsics.cs Adds null, equal, and unequal nullable-boxing coverage.
src/coreclr/jit/gentree.cpp Prevents unsafe folding of nullable boxed arguments.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

@EgorBo

EgorBo commented Sep 21, 2026

Copy link
Copy Markdown
Member

A few diffs

PTAL @jakobbotsch @dotnet/jit-contrib

@EgorBo
EgorBo requested a review from jakobbotsch September 21, 2026 11:22
@EgorBo

EgorBo commented Sep 23, 2026

Copy link
Copy Markdown
Member

ping @jakobbotsch, presumably, simple change

@EgorBo
EgorBo enabled auto-merge (squash) September 24, 2026 10:49
@EgorBo

EgorBo commented Sep 24, 2026

Copy link
Copy Markdown
Member

/ba-g DIC failure is already fixed in main

@EgorBo
EgorBo merged commit ddbf2d9 into main Sep 24, 2026
142 of 144 checks passed
@EgorBo
EgorBo deleted the copilot/fix-nullreferenceexception-enum-equals branch September 24, 2026 10:50
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 25, 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) Enum.Equals folding throws NullReferenceException instead of returning false for a null argument

5 participants