Open
Preserve checked overflow for unsigned range additions#130435
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/runtime-infrastructure |
Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
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
EgorBo
approved these changes
Jul 10, 2026
Contributor
There was a problem hiding this comment.
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 toUnknownwhen 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. |
This was referenced Jul 10, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tier 1 assertion propagation could incorrectly remove an unsigned addition’s overflow check because JIT ranges use signed intervals.
Range analysis
Regression coverage