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: Head merging can reorder a null dereference ahead of a division and throw the wrong exception #137253
Head merging can move a field read shared by both branches ahead of the condition that established its non-nullness. The interference check misses this when the condition contains an invariant load that can throw but has no GTF_GLOB_REF.
If the condition evaluates a division first, a null receiver and zero divisor incorrectly produce NullReferenceException instead of DivideByZeroException.
Reproduction Steps
Similar codegen is already present in ILCompiler.IBC.IBCProfileParser.GetSigTypeFromIBCZapSig. Discovered through the verifier added in #137045
usingSystem;usingSystem.Runtime.CompilerServices;classProgram{classReceiver{publicintValue=42;}staticints_marker;[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]staticintRead(Receiverreceiver,intdivisor){intvalue;// Both branches read receiver.Value after GetType has checked receiver.// Moving that read before the condition invalidates its non-null proof.if((10/divisor>0)==(receiver.GetType()==typeof(Receiver))){value=receiver.Value;s_marker=1;}else{value=receiver.Value;s_marker=2;}returnvalue;}staticvoidMain(){try{Read(null,0);}catch(Exceptionex){Console.WriteLine(ex.GetType().Name);Console.WriteLine(s_marker);}}}
Expected behavior
DivideByZeroException
Actual behavior
NullReferenceException
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
The hole is that the interference check misses faulting invariant loads without GTF_GLOB_REF, which inlining or devirtualization can leave behind. GetType() is just an easy way to get one.
Activity
dotnet-policy-service commentedon Nov 10, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
Preserve exception order when head merging ordered statements (dotnet…