Repository navigation
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIblocking-outerloopBlocking the 'runtime-coreclr outerloop' and 'runtime-libraries-coreclr outerloop' runs
Description
Failed in: runtime-coreclr outerloop 20260421.3
Failed tests:
R2R-CG2 windows x86 Checked @ Windows.10.Amd64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 windows x86 Checked no_tiered_compilation @ Windows.10.Amd64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 windows x64 Checked @ Windows.10.Amd64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 windows x64 Checked no_tiered_compilation @ Windows.10.Amd64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 linux arm64 Checked @ (Alpine.323.Arm64.Open)[email protected]/dotnet-buildtools/prereqs:alpine-3.23-helix-arm64v8
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 linux arm64 Checked no_tiered_compilation @ (Alpine.323.Arm64.Open)[email protected]/dotnet-buildtools/prereqs:alpine-3.23-helix-arm64v8
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 linux arm64 Checked @ AzureLinux.3.Arm64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 linux arm64 Checked no_tiered_compilation @ AzureLinux.3.Arm64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 linux x64 Checked @ (Alpine.323.Amd64.Open)[email protected]/dotnet-buildtools/prereqs:alpine-3.23-helix-amd64
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 linux x64 Checked no_tiered_compilation @ (Alpine.323.Amd64.Open)[email protected]/dotnet-buildtools/prereqs:alpine-3.23-helix-amd64
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 linux x64 Checked @ AzureLinux.3.Amd64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 linux x64 Checked no_tiered_compilation @ AzureLinux.3.Amd64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 windows arm64 Checked @ Windows.11.Arm64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 windows arm64 Checked no_tiered_compilation @ Windows.11.Arm64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 osx x64 Checked @ OSX.15.Amd64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
R2R-CG2 osx x64 Checked no_tiered_compilation @ OSX.15.Amd64.Open
- JIT/opt/Casts/shared_Casts/shared_Casts.dll
Error message:
Assert.Equal() Failure: Values differ
Expected: 100
Actual: 0
Stack trace:
at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer) in /_/src/arcade/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs:line 102
at Xunit.Assert.Equal[T](T expected, T actual) in /_/src/arcade/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs:line 36
at Program.<<Main>$>g__TestExecutor286|0_287(StreamWriter tempLogSw, StreamWriter statsCsvSw, <>c__DisplayClass0_0&)
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIblocking-outerloopBlocking the 'runtime-coreclr outerloop' and 'runtime-libraries-coreclr outerloop' runs
Activity
dotnet-policy-service commentedon Apr 22, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
AndyAyersMS commentedon Apr 22, 2026
Might be related to #126930. So I'll take this one for now.
AndyAyersMS commentedon Apr 22, 2026
Note
This analysis was generated with assistance from GitHub Copilot.
Root cause
This is a regression from #127146 ("Handle canonical types in casting logic").
The failing test (
src/tests/JIT/opt/Casts/shared.cs) contains:When crossgen2 compiles the shared generic body
F0<__Canon>, it asks the JIT type-compare-for-cast API whetherI<__Canon>can be cast toI<object>. This is the positive-result branch inCorInfoImpl.compareTypesForCast:fromType.CanCastTo(toType)isI<__Canon>.CanCastTo(I<object>). Before #127146 that returnedfalse; after #127146 it returnstrue, because the newIsCanonEquivalentcheck inCanCastToNonVariantInterfacetreats anyI<__Canon>as matchingI<X>for any reference typeX.Returning
Musthere letsimpExpandIsinstfold theisinst I<object>to "always true":So at runtime
F0<string>(iNotObj)(whereiNotObjisI<string>) returnstrueinstead offalse, and the test's output accumulator becomes15instead of9.The canon-equivalence rule is correct for the dataflow/constraint-check scenario that #127146 targeted (#126604), but it violates the invariant
compareTypesForCastdepends on — namely that a true result fromCanCastToimplies the cast must succeed for every concrete instantiation the shared code can see.Note: the VM path (
TypeHandle::CanCastToinsrc/coreclr/vm/jitinterface.cpp) was not touched by #127146, so non-R2R runs are unaffected. The bug only reproduces under crossgen2/R2R, which matches the failure signature (all R2R platforms fail, jitstress does not).Fix
In
CorInfoImpl.compareTypesForCast, when casting from shared to unshared interface target, only trust a positiveCanCastToasMustwhentoType.HasInstantiationisfalse. Otherwise demote toMay, which preserves the runtime test and avoids miscompilation:This is a minimal, targeted fix. A broader/cleaner long-term option is to scope the canon-equivalence additions in
CastingHelper.csto only the reflection/constraint-check code paths that need them (e.g., via an explicitCanCastToWithCanonEquivalenceentrypoint), sincecompareTypesForCastis not the only consumer ofCanCastTo—DevirtualizationManager,MetadataVirtualMethodAlgorithm, andILImporter.StackValuealso call it and have the same trust assumption. Those haven't shown observable regressions yet, but auditing them (or narrowing theCastingHelperchange) would reduce future risk. Happy to do that as a follow-up.Verification
a=9(pass). R2R:a=15(fail, exit≠100).a=9and exits100.F0confirms theisinstfold no longer occurs forI<__Canon> → I<object>.JIT/optnon-R2R merged suite: 0 failures./cc @MichalStrehovsky @dotnet/jit-contrib
MichalStrehovsky commentedon Apr 22, 2026
I have a revert at #127301 (anyone can approve). Copilot lied to me that CoreCLR CanCastTo says yes for anything canonical and the managed implementation was actually more precise. I really didn't want to read C++. Looks like I still need to read C++ in the AI age.
Revert "Handle canonical types in casting logic" (dotnet#127301)
Revert "Handle canonical types in casting logic" (#127301)