You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JIT: (bug) Failed isinst to an interface is treated as non-null, folding a GetType() compare and swallowing a NullReferenceException #134193
The result of an isinst helper call inherits the isNonNull property of its input, but a failed isinst returns null. The optimizer then drops the null check and constant-folds a type comparison, producing a silently wrong answer.
Minimal Repro
usingSystem;usingSystem.Runtime.CompilerServices;publicclassProgram{[MethodImpl(MethodImplOptions.NoInlining)]publicstaticboolTest<T>(){objecto="hi";IComparable<T>?c=oasIComparable<T>;// null when T is not stringreturnc!.GetType()==typeof(string);}publicstaticvoidMain(){Console.WriteLine("Test<string>() = "+Test<string>());try{Console.WriteLine("Test<object>() = "+Test<object>());}catch(NullReferenceException){Console.WriteLine("Test<object>(): NullReferenceException (expected)");}}}
Correct under DOTNET_JITMinOpts=1, so this is an optimizer bug. Also repros on released .NET 10.0.12.
The shared-generic (__Canon) instantiation folds to mov eax, 1 / ret: the isinst helper call is dead-coded, the implicit null check is gone and the comparison is constant-folded. Compiler::gtGetHelperCallClassHandle falls back to the value argument for CORINFO_HELP_ISINSTANCEOF* with an interface/unknown target and copies its isNonNull; gtFoldTypeCompare then trusts it.
Activity
dotnet-policy-service commentedon Sep 18, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
EgorBo commentedon Sep 18, 2026
Affected SDK versions:
JIT: Do not propagate non-nullness through isinst helpers (#135723)