Skip to content

C++: Fix off–by-one in range analysis for RemExpr.#6315

Merged
rdmarsh2 merged 3 commits intogithub:mainfrom
MathiasVP:fix-off-by-one-in-rem-expr-range-analysis
Jul 16, 2021
Merged

C++: Fix off–by-one in range analysis for RemExpr.#6315
rdmarsh2 merged 3 commits intogithub:mainfrom
MathiasVP:fix-off-by-one-in-rem-expr-range-analysis

Conversation

@MathiasVP
Copy link
Copy Markdown
Contributor

This PR fixes two bugs related to range analysis of RemExpr:

  1. 81aa115 fixes a bug where the sign of both the left-hand side, and the right-hand side of the RemExpr was used instead of the right-hand side only.
    This caused expressions like my_signed_int % 5 to receive incorrect upper bounds, and because the lower-bound calculation of RemExpr depended on the upper-bound, such expressions would also receive incorrect lower-bound values. See dc2eea5 for an example of this.

  2. 39d9395 fixes an off-by-one bug where we'd conclude that x % y was upper-bounded by the value of y, whereas in reality we could refine this to y - 1.

The last bug caused a false-positive in #6081. I recommend commit-by-commit reviewing of this PR.

@MathiasVP MathiasVP added C++ no-change-note-required This PR does not need a change note labels Jul 16, 2021
@MathiasVP MathiasVP requested a review from a team as a code owner July 16, 2021 14:40
@rdmarsh2 rdmarsh2 merged commit e0ff1d9 into github:main Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants