C++: Measure bounds for Enum constants and reduce getBoundsLimit#21313
Open
MathiasVP wants to merge 4 commits intogithub:mainfrom
Open
C++: Measure bounds for Enum constants and reduce getBoundsLimit#21313MathiasVP wants to merge 4 commits intogithub:mainfrom
Enum constants and reduce getBoundsLimit#21313MathiasVP wants to merge 4 commits intogithub:mainfrom
Conversation
cpp/ql/lib/semmle/code/cpp/rangeanalysis/RangeAnalysisUtils.qll
Dismissed
Show dismissed
Hide dismissed
734b601 to
c71f1af
Compare
MathiasVP
added a commit
to MathiasVP/codeql-coding-standards
that referenced
this pull request
Feb 11, 2026
30 tasks
c71f1af to
2dc91a5
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Improves C++ SimpleRangeAnalysis performance by ensuring enum-typed expressions get appropriate type bounds (so the bounds estimator stays functional) and by lowering the widening trigger threshold to avoid pathological blowups.
Changes:
- Add enum underlying-type handling to type-bound computation used by range analysis utilities.
- Reduce
BoundsEstimate.getBoundsLimitfrom2^40to2^29. - Add a regression test (
missing_bounds.cpp) and update rangeanalysis test expectations.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cpp/ql/lib/semmle/code/cpp/rangeanalysis/RangeAnalysisUtils.qll | Extend type-bound logic to cover Enum types via an inferred/explicit underlying integral type. |
| cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll | Lower the bounds-estimate limit used to decide when to enable widening. |
| cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/missing_bounds.cpp | New regression test exercising enum constants / flag-like operations for bounds estimation. |
| cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/nrOfBounds.ql | Tighten functionality test to assert expected estimator behavior for the new regression input. |
| cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/nrOfBounds.expected | Updated expected results for bounds-estimation test output. |
| cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/lowerBound.expected | Updated expected lower-bound results for the new regression input. |
| cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/upperBound.expected | Updated expected upper-bound results for the new regression input. |
| @@ -513,7 +513,7 @@ private module BoundsEstimate { | |||
| float getBoundsLimit() { | |||
| // This limit is arbitrary, but low enough that it prevents timeouts on | |||
| // specific observed customer databases (and the in the tests). | |||
There was a problem hiding this comment.
Comment text has a grammatical typo: "(and the in the tests)" reads incorrectly. Consider changing it to "(and in the tests)" (or similar).
Suggested change
| // specific observed customer databases (and the in the tests). | |
| // specific observed customer databases (and in the tests). |
cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/missing_bounds.cpp
Show resolved
Hide resolved
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.
This PR fixes a
SimpleRangeAnalysisperformance problem we've seen at Microsoft.There were two problems (both of which are fixed in this PR):
Enumtypes. This let toanalyzableExprnot being satisfied for expressions ofEnumtypes, which let tonrOfBoundsExprnot having a result for expressionsEnum.getBoundsLimittreshold was set way too high. Since this was just the arbitrary default value picked in C++: Range analysis measure bounds #20645 to fix the initial performance problem that PR was meant to solve, I think it's fair to reduce it to a more sane value now that we have yet another performance problem. Reducing it from 2^40 to 2^29 fixes this performance problem, and on anything greater we'll timeout even duringcodeql test run.Commit-by-commit review recommended.