Skip to content

JIT: Do not propagate non-nullness through isinst helpers - #135723

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-jit-134193
Oct 14, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-jit-134193

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

gtGetHelperCallClassHandle falls back to the class of the value argument for interface or unknown targets and copied its non-null property. That holds for chkcast, but a failed isinst returns null, so the type compare folding dropped the null check. Clear isNonNull for the isinst helpers.

Fixes #134193

No diffs.

gtGetHelperCallClassHandle falls back to the class of the value argument for interface or unknown targets and copied its non-null property. That holds for chkcast, but a failed isinst returns null, so the type compare folding dropped the null check. Clear isNonNull for the isinst helpers.

Fixes dotnet#134193

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 88502efb-96e2-4483-b698-59f5003a2e2c
@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 13, 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.

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

🟡 Changes recommended

The regression test does not cover the distinct non-variant interface-helper path modified by the fix.

1 open finding
What changed in this PR

Fixes incorrect JIT non-null propagation through failed isinst helpers, preserving required null checks.

Changes:

  • Clears inferred non-nullness for isinst helper results.
  • Adds a regression test for the generic catch-all helper.
  • Non-variant interface-helper coverage is still missing.
File Description
src/​coreclr/​jit/​gentree.cpp Corrects nullability inference for isinst results.
src/​tests/​JIT/​Regression_ro_2/​Runtime_134193.cs Tests failed generic interface casts.

🧠 Review effort: Balanced

@EgorBo

EgorBo commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib, trivial bug-fix

@EgorBo
EgorBo requested a review from a team October 14, 2026 02:04

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

Looks reasonable to me. The copilot feedback about exercising the CORINFO_ISINSTANCEOFINTERFACE handling might be worth addressing?

castHnd = gtGetClassHandle(valueArg, pIsExact, pIsNonNull);

// A failed isinst returns null even for a non-null value, only cast helpers preserve non-nullness.
if ((helper == CORINFO_HELP_ISINSTANCEOFINTERFACE) || (helper == CORINFO_HELP_ISINSTANCEOFARRAY) ||

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.

Is there a way for us to set or track the assertion so that the true path is known non-null?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@tannergooding we already create assertions for that, yep e.g.

if (obj is List<int>)
{
    // obj is known to be of (either exact or subclass) List<int> here (and non-null).
}

(although, only for global assertion prop)

This function is for early phases when we don't know much.

@EgorBo
EgorBo enabled auto-merge (squash) October 14, 2026 21:59
@EgorBo
EgorBo merged commit daae8a4 into dotnet:main Oct 14, 2026
136 of 138 checks passed
@EgorBo
EgorBo deleted the fix-jit-134193 branch October 14, 2026 22:14
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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) Failed isinst to an interface is treated as non-null, folding a GetType() compare and swallowing a NullReferenceException

4 participants