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) OptimizeBools merges x < 0 || v.GetElement(x) < 0 and speculates a GetElement whose bounds check was removed #135815
Optimize bools folds x < 0 || v.GetElement(x) < 0 into (x | v.GetElement(x)) < 0 after assertion prop removed the bounds check of GetElement(x). The variable-index GetElement is then evaluated unconditionally, also for x < 0, reading out-of-bounds stack memory and crashing with AccessViolationException in valid safe C#.
The disassembly spills v to the stack and does mov eax, dword ptr [rsp+4*rax] before the x < 0 check (with x = -1 this reads far outside the frame).
Regression?
Not a regression: 8.0.x, 9.0.x, 10.0.12, 11.0.0-rc.1 and current main all throw; 7.0.20 prints 3 21 2.
Notes
DOTNET_JITMinOpts=1 prints 3 21 2. Vector256<int> with an x >= 8 guard also fails. The extra uses of v only lower the GetElement cost to the merge threshold (GetCostEx() <= 12).
Assertion prop removes the BOUNDS_CHECK using 0 <= x < 4 from the dominating branches, so the HWINTRINSIC loses GTF_EXCEPT and (unlike IND/array elements) can't carry GTF_ORDER_SIDEEFF (OperSupportsOrderingSideEffect).
optOptimizeBoolsChkTypeCostCond (optimizebools.cpp) only checks GTF_GLOB_EFFECT and cost for m_c2, so it treats the second condition as safe to speculate. It could reject such nodes or check the VN exception set (still has IndexOutOfRangeExc), as loop hoisting does. Related: JIT: (bug) x >= 0 && x < (a[x] & int.MaxValue) drops the x >= 0 guard #134202 (same pattern for FoldNeverNegativeRangeTest, fixed via GTF_ORDER_SIDEEFF).
Activity
dotnet-policy-service commentedon Oct 14, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
JIT: Keep vector element accesses ordered after their range check (do…