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) bounds check wrongly removed under a data race (liberal VN reused as conservative VN for LCL_FLD of struct phi) #134489
For a LCL_FLD read of a struct local that has a phi SSA def, the liberal VN can end up as the conservative VN. Two separate heap reads then share a conservative VN, and range check elimination removes a bounds check. Under a data race this gives an AV in safe C# code.
Minimal Repro
usingSystem;usingSystem.Runtime.CompilerServices;usingSystem.Threading;publicstructS{publicintA,B,C,D,E;}publicclassHolder{publicSF;}publicclassProgram{[MethodImpl(MethodImplOptions.NoInlining)]staticstringUse(Ss)=>"";[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]staticintTest(Holderh,int[]arr,boolc){Ss=h.F;if(c)s=h.F;if((uint)s.A<(uint)arr.Length){St=h.F;if(c)t=h.F;// arr[t.A] has its bounds check removed: t.A is a separate read of h.F.AthrownewException(Use(s)+Use(t)+arr[t.A]+s.B);}return-1;}publicstaticvoidMain(){varh=newHolder();vararr=newint[10];newThread(()=>{while(true){Volatile.Write(refh.F.A,0);Volatile.Write(refh.F.A,100_000_000);}}){IsBackground=true}.Start();for(inti=0;i<1_000_000;i++){try{Test(h,arr,true);}catch(Exception){}}Console.WriteLine("Done");}}
Expected
Done
Actual
UB
Regression?
Yes, a regression from .NET 8. .NET 8.0.31 works (the bounds check is still there). .NET 9.0.20, 10.0.12, 11.0.0-rc.2 and main fail.
Notes
VNForMapSelectWork caches results in MapSelectWorkCache with the key (VNF_MapSelect, map, index) only, so vnk is not part of the key.
For a struct phi, the liberal and conservative sides share the PhiDef map VN. The conservative select therefore hits the cached liberal result, even though the phi args' conservative VNs are different.
Possible fix: add vnk to the cache key, or use separate caches. The Use(...) calls are only there to block physical promotion.
Activity
dotnet-policy-service commentedon Sep 23, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
JIT: Separate map select caches by VN kind (dotnet#137855)