Skip to content

JIT: preserve importer stack for negative constant Log2 - #133725

Merged
EgorBo merged 2 commits into
mainfrom
copilot/fix-jit-invalidprogramexception-log2
Sep 14, 2026
Merged

EgorBo merged 2 commits into
mainfrom
copilot/fix-jit-invalidprogramexception-log2

Conversation

Copilot AI commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Calls such as int.Log2(-1) and long.Log2(-1L) pop their argument before declining intrinsic expansion, corrupting the importer stack and producing InvalidProgramException instead of ArgumentOutOfRangeException.

  • Importer: Pop the constant argument only when folding succeeds, preserving it for normal-call fallback otherwise.
  • Regression coverage: Exercise negative int, long, and nint constants with and without another value underneath on the stack, plus valid signed and unsigned boundary constants.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 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: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Copilot AI changed the title [WIP] Fix int.Log2/long.Log2 with negative constant causing InvalidProgramException JIT: preserve importer stack for negative constant Log2 Sep 11, 2026
Copilot AI requested a review from EgorBo September 11, 2026 18:25
@EgorBo
EgorBo marked this pull request as ready for review September 11, 2026 18:30
Copilot AI lite review requested due to automatic review settings September 11, 2026 18:30
@EgorBo
EgorBo requested a review from AndyAyersMS September 11, 2026 18:30
@EgorBo

EgorBo commented Sep 11, 2026

Copy link
Copy Markdown
Member

PTAL @AndyAyersMS @dotnet/jit-contrib

@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.

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.

🟡 Changes recommended

Native-sized constants are still incorrectly truncated on 64-bit targets.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes JIT importer stack corruption for negative constant Log2 calls and adds regression coverage.

Changes:

  • Preserves arguments when intrinsic folding is declined.
  • Adds tests for signed, unsigned, native-sized, and stacked operands.
File summaries
File Summary
src/coreclr/jit/importercalls.cpp Updates constant Log2 stack handling.
src/tests/JIT/Regression_ro_2/Runtime_133711.cs Adds regression tests for issue #133711.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/coreclr/jit/importercalls.cpp Resolved
@EgorBo
EgorBo enabled auto-merge (squash) September 11, 2026 18:52
@EgorBo

EgorBo commented Sep 14, 2026

Copy link
Copy Markdown
Member

/ba-g unrelated mono failures

@EgorBo
EgorBo merged commit 09638d0 into main Sep 14, 2026
139 of 141 checks passed
@EgorBo
EgorBo deleted the copilot/fix-jit-invalidprogramexception-log2 branch September 14, 2026 10:50
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 15, 2026
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 18, 2026
<!-- -->

Calls such as `int.Log2(-1)` and `long.Log2(-1L)` pop their argument
before declining intrinsic expansion, corrupting the importer stack and
producing `InvalidProgramException` instead of
`ArgumentOutOfRangeException`.

- **Importer:** Pop the constant argument only when folding succeeds,
preserving it for normal-call fallback otherwise.
- **Regression coverage:** Exercise negative `int`, `long`, and `nint`
constants with and without another value underneath on the stack, plus
valid signed and unsigned boundary constants.

<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes dotnet#133711

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: EgorBo <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

JIT: (bug) int.Log2/long.Log2 with a negative constant corrupts the importer stack (InvalidProgramException)

5 participants