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) Loop cloning removes the bounds check when limit + negativeConst wraps to a small positive value: the stride-overflow guard tests only the unwrapped limit #137678
For for (int i = start; i < limit + C; i += stride) with a large stride, loop cloning emits the IV-overflow guard on the unwrapped limit but the range conditions on the wrapped limit + C. When limit + C wraps to a small positive value all conditions pass, the fast clone (no bounds check) runs, and i wraps negative on the 2nd iteration.
IndexOutOfRangeException: the first iteration reads a[32], then i wraps to int.MinValue + 31, i < 103 (the wrapped limit) still holds, so a[int.MinValue + 31] must throw. This is also what a Checked JIT prints with DOTNET_JitCloneLoops=0.
Actual
Checked and Release JIT (win-x64, main a5d7014cefc): System.AccessViolationException. The fast clone has no bounds check and reads at a ~8 GB offset from the array.
Regression?
Yes. Same repro, default settings:
Runtime
Result
.NET 8 (8.0.34)
OK (IndexOutOfRangeException)
.NET 9 (9.0.23)
OK
.NET 10 (10.0.15)
OK
.NET 11 (11.0.0) / main (a5d7014cefc)
AccessViolationException
Likely related to #129309 (LimitOffset / the stride > 1 overflow guard; not bisected). The same area was already touched by #133834 (fix for #133823), which doesn't cover this case.
Notes
JitDump: Added stride>1 overflow guard: V02 <= 2147483549, then Conditions: (V02 LE 2147483549) && (V04 GE 0) && (V02-2147483548 GE 0) && (V02-2147483548 LE V00.Length).
In the HasInvariantLocalLimit branch of optDeriveLoopCloningConditions (loopcloning.cpp) the stride-overflow guard limit <= 0x7FFFFF9D is computed from LimitBase (the unwrapped limit), ignoring that LimitBase + LimitOffset can wrap.
The range conditions are evaluated on the wrapped sum (103 for the repro input), so they hold.
Possible fix: compute the guard on the wrapped limit + offset, or don't clone when the limit is local + const with a large stride.
Activity
dotnet-policy-service commentedon Nov 16, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
JIT: Guard loop cloning against limit offset underflow (dotnet#137782)