Skip to content

Commit 39aaccc

Browse files
committed
C++: Add QLDoc for AST range analysis libraries
1 parent 3e6a198 commit 39aaccc

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides classes and predicates for recognizing floating point expressions which cannot be NaN.
3+
*/
4+
15
import cpp
26
private import semmle.code.cpp.rangeanalysis.RangeSSA
37

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ private float lowerBoundFC(Expr expr) { result = lowerBound(expr.getFullyConvert
1111
/** Gets the upper bound of the fully converted expression. */
1212
private float upperBoundFC(Expr expr) { result = upperBound(expr.getFullyConverted()) }
1313

14+
/**
15+
* Describes which side of a pointless comparison is known to be smaller.
16+
*/
1417
newtype SmallSide =
18+
/**
19+
* Represents that the left side of a pointless comparison is known to be smaller.
20+
*/
1521
LeftIsSmaller() or
22+
/**
23+
* Represents that the right side of a pointless comparison is known to be smaller.
24+
*/
1625
RightIsSmaller()
1726

1827
/**

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@ import cpp
55
* relation) or 'non-strict' (a `<=` or `>=` relation).
66
*/
77
newtype RelationStrictness =
8+
/**
9+
* Represents that a relation is 'strict' (that is, a `<` or `>` relation).
10+
*/
811
Strict() or
12+
/**
13+
* Represents that a relation is 'non-strict' (that is, a `<+` or `>+` relation)
14+
*/
915
Nonstrict()
1016

1117
/**
1218
* Describes whether a relation is 'greater' (that is, a `>` or `>=`
1319
* relation) or 'lesser' (a `<` or `<=` relation).
1420
*/
1521
newtype RelationDirection =
22+
/**
23+
* Represents that a relation is 'greater' (that is, a `>` or `>=` relation).
24+
*/
1625
Greater() or
26+
/**
27+
* Represents that a relation is 'lesser' (that is, a `<` or `<=` relation).
28+
*/
1729
Lesser()
1830

1931
private RelationStrictness negateStrictness(RelationStrictness strict) {
@@ -28,12 +40,18 @@ private RelationDirection negateDirection(RelationDirection dir) {
2840
dir = Lesser() and result = Greater()
2941
}
3042

43+
/**
44+
* Holds if `dir` is `Greater` (that is, a `>` or `>=` relation)
45+
*/
3146
boolean directionIsGreater(RelationDirection dir) {
3247
dir = Greater() and result = true
3348
or
3449
dir = Lesser() and result = false
3550
}
3651

52+
/**
53+
* Holds if `dir` is `Lesser` (that is, a `<` or `<=` relation)
54+
*/
3755
boolean directionIsLesser(RelationDirection dir) {
3856
dir = Greater() and result = false
3957
or

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import semmle.code.cpp.controlflow.Dominance
2525
import semmle.code.cpp.controlflow.SSAUtils
2626
private import RangeAnalysisUtils
2727

28+
/**
29+
* The SSA logic comes in two versions: the standard SSA and range-analysis RangeSSA.
30+
* This class provides the range-analysis SSA logic.
31+
*/
2832
library class RangeSSA extends SSAHelper {
2933
RangeSSA() { this = 1 }
3034

@@ -84,6 +88,7 @@ class RangeSsaDefinition extends ControlFlowNodeBase {
8488
/** Gets the control flow node for this definition. */
8589
ControlFlowNode getDefinition() { result = this }
8690

91+
/** Gets the basic block containing this definition. */
8792
BasicBlock getBasicBlock() { result.contains(getDefinition()) }
8893

8994
/** Whether this definition is a phi node for variable `v`. */
@@ -97,11 +102,13 @@ class RangeSsaDefinition extends ControlFlowNodeBase {
97102
guard_defn(v, guard, this, branch)
98103
}
99104

105+
/** Gets the primary location of this definition. */
100106
Location getLocation() { result = this.(ControlFlowNode).getLocation() }
101107

102108
/** Whether this definition is from a parameter */
103109
predicate definedByParameter(Parameter p) { this = p.getFunction().getEntryPoint() }
104110

111+
/** Gets a definition of `v` that is a phi input for this basic block. */
105112
RangeSsaDefinition getAPhiInput(StackVariable v) {
106113
this.isPhiNode(v) and
107114
exists(BasicBlock pred |
@@ -153,6 +160,9 @@ class RangeSsaDefinition extends ControlFlowNodeBase {
153160
)
154161
}
155162

163+
/**
164+
* Holds if this definition of the variable `v` reached the end of the basic block `b`.
165+
*/
156166
predicate reachesEndOfBB(StackVariable v, BasicBlock b) {
157167
exists(RangeSSA x | x.ssaDefinitionReachesEndOfBB(v, this, b))
158168
}

0 commit comments

Comments
 (0)