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) redundant branch opts remove a null check that a non-faulting load depends on (spurious NullReferenceException) #135811
In FullOpts, optRedundantDominatingBranch removes the dominating obj != null check even though obj.Value in the dominated block was marked non-faulting only because of that check. The load then runs with obj == null and throws a spurious NullReferenceException in valid safe C#.
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Program.Test(C obj)
at Program.Main()
The outer obj != null branch is gone and cmp dword ptr [rcx+0x08], 0 executes unconditionally.
Regression?
Yes, a regression in .NET 11 (not bisected): 8.0.x, 9.0.x and 10.0.12 print 3; 11.0.0-rc.1 and current main throw.
Notes
DOTNET_JitDoRedundantBranchOpts=0 and DOTNET_JITMinOpts=1 both print 3.
Morph's non-null assertion prop marks the obj.ValueIND as GTF_IND_NONFAULTING (clearing GTF_EXCEPT) because of the obj != null guard. Redundant branch opts then infer that same guard from the AND(notNull, obj.Value > 0) predicate and fold it away.
Activity
dotnet-policy-service commentedon Oct 14, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
JIT: don't let RBO speculate nodes that depend on a removed check (do…