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 the loop limit is a checked(local + const) that always overflows and the catch re-enters the loop #137677
Loop cloning peels local + const off the loop limit and derives its conditions as if the addition were an unchecked, non-throwing ADD. When the checked addition always overflows (the OverflowException is swallowed by a catch that loops back), the conditions are evaluated on the wrapped value and select the fast clone without a bounds check, which then reads far past the end of the array.
IndexOutOfRangeException: checked(limit + (int.MinValue + 5)) always overflows and is caught, i keeps increasing, and a[8] must throw. This is also what a Checked JIT prints with DOTNET_JitCloneLoops=0.
Actual
Checked and Release JIT (win-x64, main a5d7014cefc) print -1: the loop reads 1000 elements past the end of the 8-element array without a bounds check before the retry counter runs out.
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)
prints -1
Likely related to #129309 (it introduced peeling a constant offset off the loop limit into LimitOffset; not bisected).
Notes
JitDump: Conditions: (0 LT V01-2147483643) && (V01-2147483643 GE 0) && (V01-2147483643 LE V00.Length). For the repro input the wrapped (unchecked) limit is 8, so all conditions hold and the fast clone is selected.
FlowGraphNaturalLoop::MatchLimit (flowgraph.cpp) peels GT_ADD/GT_SUB with a constant off the limit without checking gtOverflow(), and the cloning condition is rebuilt as a non-throwing ADD.
Possible fix: bail out of limit matching (or of cloning) when the limit contains an overflow-checking ADD/SUB.
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: Don't peel the constant off an overflow-checked loop limit (dotn…