Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4929db

Browse files
committed
C++: Adopt range analysis interface in the SimpleRangeAnalysis library
1 parent 5c1275e commit b4929db

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

cpp/ql/src/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import cpp
4646
private import RangeAnalysisUtils
47+
private import semmle.code.cpp.models.interfaces.RangeAnalysisExpr
4748
import RangeSSA
4849
import SimpleRangeAnalysisCached
4950
private import NanAnalysis
@@ -207,6 +208,9 @@ private predicate analyzableExpr(Expr e) {
207208
or
208209
// `>>` by a constant
209210
exists(e.(RShiftExpr).getRightOperand().getValue())
211+
or
212+
// A modeled expression for range analysis
213+
e instanceof RangeAnalysisExpr
210214
)
211215
}
212216

@@ -318,6 +322,11 @@ private predicate exprDependsOnDef(Expr e, RangeSsaDefinition srcDef, StackVaria
318322
)
319323
or
320324
e = srcDef.getAUse(srcVar)
325+
or
326+
// A modeled expression for range analysis
327+
exists(RangeAnalysisExpr rae |
328+
rae.dependsOnDef(srcDef, srcVar)
329+
)
321330
}
322331

323332
/**
@@ -438,7 +447,7 @@ private float addRoundingDownSmall(float x, float small) {
438447
/**
439448
* Gets the truncated lower bounds of the fully converted expression.
440449
*/
441-
private float getFullyConvertedLowerBounds(Expr expr) {
450+
float getFullyConvertedLowerBounds(Expr expr) {
442451
result = getTruncatedLowerBounds(expr.getFullyConverted())
443452
}
444453

@@ -491,7 +500,7 @@ private float getTruncatedLowerBounds(Expr expr) {
491500
/**
492501
* Gets the truncated upper bounds of the fully converted expression.
493502
*/
494-
private float getFullyConvertedUpperBounds(Expr expr) {
503+
float getFullyConvertedUpperBounds(Expr expr) {
495504
result = getTruncatedUpperBounds(expr.getFullyConverted())
496505
}
497506

@@ -727,6 +736,12 @@ private float getLowerBoundsImpl(Expr expr) {
727736
right = rsExpr.getRightOperand().getValue().toInt() and
728737
result = safeFloor(left / 2.pow(right))
729738
)
739+
or
740+
// A modeled expression for range analysis
741+
exists(RangeAnalysisExpr rangeAnalysisExpr |
742+
rangeAnalysisExpr = expr and
743+
result = rangeAnalysisExpr.getLowerBounds()
744+
)
730745
}
731746

732747
/** Only to be called by `getTruncatedUpperBounds`. */
@@ -896,6 +911,12 @@ private float getUpperBoundsImpl(Expr expr) {
896911
right = rsExpr.getRightOperand().getValue().toInt() and
897912
result = safeFloor(left / 2.pow(right))
898913
)
914+
or
915+
// A modeled expression for range analysis
916+
exists(RangeAnalysisExpr rangeAnalysisExpr |
917+
rangeAnalysisExpr = expr and
918+
result = rangeAnalysisExpr.getUpperBounds()
919+
)
899920
}
900921

901922
/**

0 commit comments

Comments
 (0)