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) signed int.Log2(x) expansion throws before earlier operands are evaluated (wrong exception order, skipped side effect) #135816
impPrimitiveNamedIntrinsic expands signed Log2 into a throwing QMARK stored as a separate statement ahead of still-unspilled earlier operands, so Side() + int.Log2(-1) never calls Side() and a[i] + int.Log2(-1) throws ArgumentOutOfRangeException instead of IndexOutOfRangeException.
Side() is never called; the Log2 range check (test ecx, ecx / jl) is emitted before the Side() call / the bounds check. Same with DOTNET_JITMinOpts=1.
Regression?
Default env, Release JIT, same source per TFM:
.NET 8.0.32 / 9.0.21 / 10.0.13: expected output
.NET 11.0.0-rc.1.26425.128 and main (Checked): reproduces
Notes
Case NI_PRIMITIVE_Log2 in impPrimitiveNamedIntrinsic: impCloneExpr(op1, ..., CHECK_SPILL_ALL) doesn't spill anything for a plain local, then impStoreToTemp(tmp, qmark, CHECK_SPILL_NONE) appends the store before the unspilled stack entries (Side() call / a[i] load).
The qmark has GTF_CALL | GTF_EXCEPT, so it needs CHECK_SPILL_ALL (or an explicit spill of side-effecting stack entries). Only the negative-argument path is affected.
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: spill pending side effects before signed Log2 expansion (#135834)