Skip to content

Conversation

@paldepind
Copy link
Contributor

@paldepind paldepind commented Jan 7, 2026

This PR removes the safeFloor predicate from the simple range analysis library. The predicate is a workaround for the fact that QL's floor operates on 32 bit integers. We no longer need this after the recently introduced floorFloat predicate, which operates directly on float without any loss in range.

In addition to getting rid of safeFloor, as the test shows, this also enables correct flooring on fractional numbers greater than 2^32. This problem was pointed out by @geoffw0 back in #3445:

There are some edge cases for int64 types that we don't handle well (because QL floor() fails on large numbers!) so such cases are simply excluded from the analysis.

@github-actions github-actions bot added the C++ label Jan 7, 2026
@paldepind paldepind changed the title Cpp/range analysis float ceil C++: Remove safeFloor in simple range analysis Jan 7, 2026
@paldepind paldepind changed the title C++: Remove safeFloor in simple range analysis C++: Remove safeFloor in simple range analysis Jan 7, 2026
@paldepind paldepind force-pushed the cpp/range-analysis-float-ceil branch from 7555440 to f5ddb1d Compare January 7, 2026 11:49
@paldepind paldepind marked this pull request as ready for review January 7, 2026 12:15
@paldepind paldepind requested a review from a team as a code owner January 7, 2026 12:15
Copilot AI review requested due to automatic review settings January 7, 2026 12:15
Copy link
Contributor

Copilot AI left a comment

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 removes the safeFloor predicate from the simple range analysis library, which was a workaround for QL's floor() method operating on 32-bit integers. The new floorFloat predicate directly operates on float values without range limitations, enabling correct handling of fractional numbers greater than 2^32.

Key Changes:

  • Removed the safeFloor predicate and its workaround logic
  • Replaced safeFloor calls with direct floorFloat() method calls on float expressions
  • Added test case demonstrating correct analysis of large numbers (2^53 - 1)

Reviewed changes

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

Show a summary per file
File Description
cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll Removed safeFloor predicate and updated right shift operations to use floorFloat()
cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/test.c Added test case for shift operations on large numbers (2^53)
cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.cpp Updated comments to reflect corrected analysis (removed "INCORRECT MESSAGE" notes)
cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected Updated expected results with corrected integer bounds (removed .5 fractional values)
cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/*.expected Updated test expectations with new line numbers and corrected bounds for large number handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@paldepind paldepind added the no-change-note-required This PR does not need a change note label Jan 7, 2026
@paldepind paldepind requested a review from geoffw0 January 7, 2026 12:19
geoffw0
geoffw0 previously approved these changes Jan 7, 2026
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

LGTM. Glad to see the back of safeFloor. 👍

Please check there are no surprises when the DCA run finishes before merging.

Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
@paldepind
Copy link
Contributor Author

Please check there are no surprises when the DCA run finishes before merging.

The DCA report seems fine, it shows something about a bad join, but I don't think it's related to the PR?

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

The DCA report seems fine, it shows something about a bad join, but I don't think it's related to the PR?

I don't generally worry about such things unless there's an overall regression to be explained (which I don't see here). And yeah, the predicate its on doesn't seem related to your changes.

@paldepind paldepind merged commit 26bd332 into github:main Jan 8, 2026
17 checks passed
@paldepind paldepind deleted the cpp/range-analysis-float-ceil branch January 8, 2026 12:07
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