Repository navigation
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Description
A constant nint/long array index produces a native-width (TYP_LONG) bounds check. optRangeCheckCloning accepts such checks as candidates but hardcodes TYP_INT for the guard nodes it synthesizes, so it builds relops whose operands have different actual types. A Checked JIT asserts in the remorph that runs inside the same phase; a Release JIT silently accepts the type-invalid IR.
Minimal repro
using System;
using System.Runtime.CompilerServices;
public class Program
{
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void Test(int[] arr)
{
arr[(nint)0] = 1;
arr[(nint)1] = 2;
arr[(nint)2] = 3;
arr[(nint)3] = 4;
}
public static void Main()
{
int[] a = new int[8];
Test(a);
Console.WriteLine(string.Join(",", a));
}
}set DOTNET_TieredCompilation=0
corerun out\rcc.dll
Expected
1,2,3,4,0,0,0,0
Actual
Assert failure(PID 2680 [0x00000a78], Thread: 105160 [0x19ac8]): Assertion failed
'genActualType(op1) == genActualType(op2)' in 'Program:Test(int[])'
during 'Clone blocks with range checks' (IL size 25; hash 0xb79562b4; FullOpts)
File: C:\prj\runtime-main2\src\coreclr\jit\morph.cpp:9269
Process fail-fast (0xC0000602). The malformed guards built by optRangeCheckCloning_DoClone (DOTNET_JitDump=Test):
Lower bound check:
[000089] J---------- \--* GT int
[000087] ----------- +--* CNS_INT int 0
[000088] ----------- \--* CNS_INT long 0 $100
Upper bound check:
[000092] J---------- \--* GT int
[000085] ----------- +--* LCL_VAR long V02 cse0 u:1 $200
[000091] ----------- \--* CNS_INT int 3
Notes
main@498a04c34ea, Windows x64, Checked JIT.AggressiveOptimizationonly makes FullOpts deterministic; plain tier-1 rejit reaches the same shape, so this also fires with a fully default configuration once the method is promoted (for examplearr[0L]=1; arr[5L]=2; arr[9L]=3; arr[13L]=4;called in a warm-up loop).- Other index spellings that reproduce identically:
arr[0L] = 1; arr[1L] = 2; arr[2L] = 3; arr[3L] = 4;. fgMorphIndexAddrbuilds aTYP_I_IMPLGT_BOUNDS_CHECKfor a native-int index, whose length operand isCAST(long <- ARR_LENGTH).BoundsCheckInfo::Initialize(rangecheckcloning.cpp:71) gates the index type only on the non-constant path (TypeOfVN(idxVN) != TYP_INT). The constant path is entered viaGenTree::IsIntCnsFitsInI32(), which tests the constant value, not the node type, so aTYP_LONGGT_CNS_INTis treated as a pure offset andidxVNis overwritten withVNZeroForType(TYP_INT), erasing the width.optRangeCheckCloning_DoClone(rangecheckcloning.cpp:232-273) then createsGT_ADD/GT_LT/GT_GTnodes hardcoded toTYP_INToverTYP_LONGoperands. The assert isfgOptimizeRelationalComparisonWithConst(morph.cpp:9269).- Not a recent regression: it arrived with the feature ("Clone blocks with bounds checks", [Experiment] Clone blocks with bounds checks #112595,
5486a2664e7f, Feb 2025, .NET 10 timeframe). .NET 8/9 have no such phase. - Release builds cannot assert and produce correct output on .NET 10, .NET 11 rc.2 and
main, but they still consume the invalid IR: the 64-bit array length ends up compared with a 32-bitcmp eax, 3, which is only benign because an array length always fits inint. - Impact: hard assert / fail-fast for Checked and Debug JIT users (CI legs, SPMI replay, JIT developers) on ordinary C#, plus a latent type hazard in Release.
- Fix directions: reject the candidate unless
idx->TypeIs(TYP_INT), or synthesize the guard nodes with the index's actual type instead of a hardcodedTYP_INT.
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Activity
dotnet-policy-service commentedon Sep 22, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
JIT: Reject native-int bounds checks in range check cloning (#135725)