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) multi-dimensional array Set checks bounds/null before evaluating the stored value #133717
usingSystem;usingSystem.Runtime.CompilerServices;classP{[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]staticvoidTest(int[,]a,inti,intd){a[i,0]=100/d;// == a.Set(i, 0, 100 / d): the RHS argument must be evaluated first}staticvoidMain(){try{Test(newint[2,2],5,0);}catch(Exceptione){Console.WriteLine(e.GetType().Name);}try{Test(null,0,0);}catch(Exceptione){Console.WriteLine(e.GetType().Name);}}}
Expected:DivideByZeroException twice — 100 / d is an argument of the int[,]::Set call and must be evaluated before Set runs its checks. Actual:IndexOutOfRangeException then NullReferenceException.
DOTNET_JITMinOpts=1 prints the correct DivideByZeroException twice; full opts (shown above, or DOTNET_TieredCompilation=0) is wrong. src\coreclr\jit\importercalls.cppimpArrayAccessIntrinsic / NI_Array_Set pops the value into the store's RHS without spilling it, unlike the SZ-array stelem path (importer.cpp:7558).
Also reproduces for rank 3 (int[,,]).
Activity
dotnet-policy-service commentedon Sep 11, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
JIT: Fix MD array store evaluation order (#133740)
JIT: Fix MD array store evaluation order (dotnet#133740)
EgorBo commentedon Sep 18, 2026
Affected SDK versions: