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) Wrong exception order for stelem.ref: the array range check runs before the value expression #133860
For stelem.ref the value operand must be evaluated before the array store's range check. When morph
demotes the array-store helper call into a plain STOREIND, the range check ends up first and the wrong
exception is reported.
Minimal Repro
usingSystem;usingSystem.Runtime.CompilerServices;classC{publicobjectF;}classProgram{[MethodImpl(MethodImplOptions.AggressiveInlining)]staticobject[]Make(intlen)=>newobject[len];[MethodImpl(MethodImplOptions.NoInlining)]staticvoidUse(object[]a){}[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]staticvoidTest(intlen,intindex,Cc){object[]arr=Make(len);arr[index]=c.F;// 'c.F' must be evaluated before the store's range checkUse(arr);}staticvoidMain(){try{Test(1,5,null);Console.WriteLine("no exception");}catch(Exceptione){Console.WriteLine(e.GetType().Name);}}}
Expected
NullReferenceException
Actual
IndexOutOfRangeException
The bounds check precedes the faulting load of c.F:
The CEE_STELEM_REF helper-call path in importer.cpp does not apply the ARR_ST ("strict ordering of
exceptions for array store") spill that the inline INDEX_ADDR path applies. When gtCanSkipCovariantStoreCheck
later succeeds in fgMorphCall and rewrites the helper call into STOREIND(INDEX_ADDR(arr, index), value),
that ordering guarantee is lost. Writing new object[len] directly (no inlined Make) takes the inline path
and behaves correctly. Also reproduces on .NET 10.0.12, so not a main-only regression.
Activity
dotnet-policy-service commentedon Sep 14, 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: preserve value evaluation when expanding reference array stores (#…