Skip to content

Preserve checked overflow for unsigned range additions#130435

Open
EgorBo with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-overflow-check-optimization
Open

Preserve checked overflow for unsigned range additions#130435
EgorBo with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-overflow-check-optimization

Conversation

Copilot AI commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Tier 1 assertion propagation could incorrectly remove an unsigned addition’s overflow check because JIT ranges use signed intervals.

  • Range analysis

    • Reject unsigned ranges that straddle signed zero.
    • Require sums to remain representable by the signed range model.
  • Regression coverage

    • Cover the reported checked-addition failure and sign-straddling ranges.

Copilot AI requested review from Copilot and removed request for Copilot July 9, 2026 21:20
Copilot AI linked an issue Jul 9, 2026 that may be closed by this pull request
@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.

Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 9, 2026 21:48
Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 9, 2026 21:57
Copilot AI changed the title [WIP] Fix overflow check being optimized out in Test method Preserve checked overflow for unsigned range additions Jul 9, 2026
Copilot finished work on behalf of EgorBo July 9, 2026 22:02
Copilot AI requested a review from EgorBo July 9, 2026 22:02
@EgorBo EgorBo marked this pull request as ready for review July 10, 2026 00:56
Copilot AI review requested due to automatic review settings July 10, 2026 00:56

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.

Pull request overview

This PR adjusts CoreCLR JIT range arithmetic to avoid incorrectly proving that certain unsigned checked additions cannot overflow when the underlying range model is expressed as signed intervals, and adds a regression test to lock the behavior in.

Changes:

  • Make RangeOps::Add(..., unsignedAdd: true) bail out to Unknown when either operand’s signed constant range straddles zero (non-monotonic under unsigned interpretation).
  • Prevent forming constant range sums for unsigned adds unless the endpoint addition is also signed-non-overflowing, avoiding unsafe signed overflow during range endpoint computation.
  • Add a JIT regression test covering a checked-unsigned-add overflow and a sign-straddling range scenario, and include it in the regression csproj.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/rangecheck.h Tightens unsigned range-add handling to avoid unsound overflow-check removal when ranges straddle signed zero or when signed endpoint sums would overflow.
src/tests/JIT/Regression/JitBlue/Runtime_130431/Runtime_130431.cs Adds regression coverage ensuring checked unsigned additions still throw OverflowException in the affected scenarios.
src/tests/JIT/Regression/Regression_ro_2.csproj Includes the new regression test source in the build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Bug: overflow check is optimized out

3 participants