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
RangeCheck::IsMonotonicallyIncreasing concludes that an index derived from a decreasing integer recurrence is monotonically increasing, so the array bounds check is removed. The negative index is then zero-extended into the element address, giving an out-of-bounds read / AccessViolationException instead of IndexOutOfRangeException.
x walks -5, -5, -10, -15, -25, -40, -65, -105, so on the 8th iteration idx == -5 passes the user's upper-bound guard.
Expected
Test: IndexOutOfRangeException
Actual
UB
No CORINFO_HELP_RNGCHKFAIL is emitted; the negative index is zero-extended (mov r9d, r9d) into the load address. DOTNET_JITMinOpts=1 is correct.
Notes
x64, main @ 6ed2ba318dcaa936da60f7d6bc9eb30cad54fc0c. Also reproduces on .NET 10.0.12 Release, so it is not a regression in main; memory-safety hole reachable from safe C#.
Root cause: the search path in RangeCheck::IsMonotonicallyIncreasing (src/coreclr/jit/rangecheck.cpp) is keyed only on expr, not on (expr, rejectNegativeConst). x = PHI(-5, x + y) re-enters with rejectNegativeConst == true for the ADD(x, y) operand, hits alreadyPresent and returns true without ever re-checking the -5 seed.
JitDump shows the resulting bogus lower bound: Computed Range [000031] => <90, $145 + -1>, then [RangeCheck::OptimizeRangeCheck] Between bounds.
Activity
dotnet-policy-service commentedon Sep 13, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
[-]JIT (bug): Bounds check wrongly removed — decreasing recurrence treated as monotonically increasing[/-][+]JIT: (bug) Bounds check wrongly removed — decreasing recurrence treated as monotonically increasing[/+]EgorBo commentedon Sep 18, 2026
Affected SDK versions:
JIT: fix range check monotonicity for negative-seed recurrences (dotn…