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) constrained. callvirt boxes the value-type receiver before the arguments are evaluated #133716
usingSystem;usingSystem.Runtime.CompilerServices;structS{publicintX;}classP{staticSs;[MethodImpl(MethodImplOptions.NoInlining)]staticobjectMutate(){s.X=7;returnnewS{X=7};}// `s` is boxed for the constrained. callvirt to Object.Equals. Per ECMA-335 III.2.1// the dereference+box is part of executing the callvirt, i.e. after Mutate() has run.[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]staticboolTest(){returns.Equals(Mutate());}[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]staticboolControl(){objectarg=Mutate();returns.Equals(arg);}staticvoidMain(){s.X=1;Console.WriteLine("Test = "+Test());s.X=1;Console.WriteLine("Control = "+Control());}}
Expected:Test = True / Control = True (the box of s must observe X == 7 written by the argument). Actual:Test = False / Control = True — Test boxes the stale X == 1.
Notes:
csc -optimize+, then corerun repro.dll (reproduces with tiering on and with DOTNET_TieredCompilation=0). Building the same source with -optimize- (DebuggableAttribute DisableOptimizations) prints True, so the IL is semantically identical and only the JIT path differs.
src/coreclr/jit/importercalls.cpp:1036-1050 spills pending side effects only for CORINFO_DEREF_THIS; CORINFO_BOX_THIS is not covered, and impTransformThis/impImportAndPushBox run after impPopCallArgs has detached the (still unevaluated) argument trees.
Requires the argument call to be a non-inline candidate ([MethodImpl(MethodImplOptions.NoInlining)]); if it is inlined it is appended as its own statement first and the ordering happens to come out right.
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.
MihuBot commentedon Sep 11, 2026
I'm a bot. Here are possible related and/or duplicate issues (I may be wrong):
JIT: Preserve constrained boxing order (#133735)
JIT: Preserve constrained boxing order (dotnet#133735)
EgorBo commentedon Sep 18, 2026
Affected SDK versions: