Skip to content

JIT: spill pending side effects before signed Log2 expansion - #135834

Merged
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:fix/jit-135816-log2-order
Oct 15, 2026
Merged

EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:fix/jit-135816-log2-order

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

The signed Log2 expansion stores a QMARK whose fallback throws ArgumentOutOfRangeException (GTF_CALL | GTF_EXCEPT) to a temp, but appended it with CHECK_SPILL_NONE. Side-effecting entries still on the IL stack (calls, bounds checks of earlier operands) were then evaluated after the throw. Use CHECK_SPILL_ALL so they are spilled first.

Fixes #135816

No diffs

The signed Log2 expansion stores a QMARK whose fallback throws ArgumentOutOfRangeException
(GTF_CALL | GTF_EXCEPT) to a temp, but appended it with CHECK_SPILL_NONE. Side-effecting entries
still on the IL stack (calls, bounds checks of earlier operands) were then evaluated after the
throw. Use CHECK_SPILL_ALL so they are spilled first.

Fixes dotnet#135816

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6ec7c151-8b7f-4bf9-8b1a-8c601a2965ec
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 15, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix uses the existing ordering mechanism and includes regression coverage for the reported failures.

0 open findings

What changed in this PR

Fixes signed Log2 evaluation order so earlier operands execute before its negative-argument exception.

Changes:

  • Uses the importer’s existing spill mechanism to preserve pending side effects.
  • Adds regression coverage for skipped calls and exception ordering with int and long.

Builds and tests were not run.

File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_135816.cs Tests side effects and exception ordering.
src/​coreclr/​jit/​importercalls.cpp Uses CHECK_SPILL_ALL before storing the signed Log2 expansion.

🧠 Review effort: Balanced

@EgorBo

EgorBo commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib, trivial change, no diffs

@EgorBo
EgorBo requested a review from a team October 15, 2026 13:09
@EgorBo
EgorBo merged commit 05d39ab into dotnet:main Oct 15, 2026
134 of 136 checks passed
@EgorBo
EgorBo deleted the fix/jit-135816-log2-order branch October 15, 2026 18:11
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: (bug) signed int.Log2(x) expansion throws before earlier operands are evaluated (wrong exception order, skipped side effect)

3 participants