Repository navigation
JIT: Do not propagate non-nullness through isinst helpers - #135723
Conversation
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
|
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. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
🟡 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
isinsthelper 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
|
PTAL @dotnet/jit-contrib, trivial bug-fix |
adamperlin
left a comment
There was a problem hiding this comment.
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) || |
There was a problem hiding this comment.
Is there a way for us to set or track the assertion so that the true path is known non-null?
There was a problem hiding this comment.
@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.

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.