Skip to content

Commit fba4d09

Browse files
committed
TypeFlow: Simplify interface.
1 parent 3939eff commit fba4d09

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/TypeFlow.qll

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private module Input implements TypeFlowInput<Location> {
159159
)
160160
}
161161

162-
predicate joinStep(TypeFlowNode n1, TypeFlowNode n2) {
162+
predicate step(TypeFlowNode n1, TypeFlowNode n2) {
163163
// instruction -> phi
164164
getAnUltimateLocalDefinition(n2.asInstruction()) = n1.asInstruction()
165165
or
@@ -179,6 +179,8 @@ private module Input implements TypeFlowInput<Location> {
179179
n1.asInstruction() = arg and
180180
n2.asInstruction() = p
181181
)
182+
or
183+
instructionStep(n1.asInstruction(), n2.asInstruction())
182184
}
183185

184186
/**
@@ -199,10 +201,6 @@ private module Input implements TypeFlowInput<Location> {
199201
i2.(PointerArithmeticInstruction).getLeft() = i1
200202
}
201203

202-
predicate uniqStep(TypeFlowNode n1, TypeFlowNode n2) {
203-
instructionStep(n1.asInstruction(), n2.asInstruction())
204-
}
205-
206204
predicate isNullValue(TypeFlowNode n) { n.isNullValue() }
207205

208206
private newtype TType =
@@ -245,11 +243,7 @@ private module Input implements TypeFlowInput<Location> {
245243

246244
pragma[nomagic]
247245
private predicate upcastCand(TypeFlowNode n, Type t1, Type t2) {
248-
exists(TypeFlowNode next |
249-
uniqStep(n, next)
250-
or
251-
joinStep(n, next)
252-
|
246+
exists(TypeFlowNode next | step(n, next) |
253247
n.getType() = t1 and
254248
next.getType() = t2 and
255249
t1 != t2

java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ private module Input implements TypeFlowInput<Location> {
8484
}
8585

8686
/**
87-
* Holds if data can flow from `n1` to `n2` in one step, and `n1` is not
88-
* necessarily functionally determined by `n2`.
87+
* Holds if data can flow from `n1` to `n2` in one step.
88+
*
89+
* For a given `n2`, this predicate must include all possible `n1` that can flow to `n2`.
8990
*/
90-
predicate joinStep(TypeFlowNode n1, TypeFlowNode n2) {
91+
predicate step(TypeFlowNode n1, TypeFlowNode n2) {
9192
n2.asExpr().(ChooseExpr).getAResultExpr() = n1.asExpr()
9293
or
9394
exists(Field f, Expr e |
@@ -112,13 +113,7 @@ private module Input implements TypeFlowInput<Location> {
112113
// skip trivial recursion
113114
not arg = n2.asSsa().getAUse()
114115
)
115-
}
116-
117-
/**
118-
* Holds if data can flow from `n1` to `n2` in one step, and `n1` is
119-
* functionally determined by `n2`.
120-
*/
121-
predicate uniqStep(TypeFlowNode n1, TypeFlowNode n2) {
116+
or
122117
n2.asExpr() = n1.asField().getAnAccess()
123118
or
124119
n2.asExpr() = n1.asSsa().getAUse()
@@ -169,7 +164,7 @@ private module Input implements TypeFlowInput<Location> {
169164
*/
170165
pragma[nomagic]
171166
private predicate upcastCand(TypeFlowNode n, RefType t1, RefType t1e, RefType t2, RefType t2e) {
172-
exists(TypeFlowNode next | uniqStep(n, next) or joinStep(n, next) |
167+
exists(TypeFlowNode next | step(n, next) |
173168
n.getType() = t1 and
174169
next.getType() = t2 and
175170
t1.getErasure() = t1e and

shared/typeflow/codeql/typeflow/TypeFlow.qll

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,11 @@ signature module TypeFlowInput<LocationSig Location> {
2828
}
2929

3030
/**
31-
* Holds if data can flow from `n1` to `n2` in one step, and `n1` is not
32-
* necessarily functionally determined by `n2`.
33-
*/
34-
predicate joinStep(TypeFlowNode n1, TypeFlowNode n2);
35-
36-
/**
37-
* Holds if data can flow from `n1` to `n2` in one step, and `n1` is
38-
* functionally determined by `n2`.
31+
* Holds if data can flow from `n1` to `n2` in one step.
32+
*
33+
* For a given `n2`, this predicate must include all possible `n1` that can flow to `n2`.
3934
*/
40-
predicate uniqStep(TypeFlowNode n1, TypeFlowNode n2);
35+
predicate step(TypeFlowNode n1, TypeFlowNode n2);
4136

4237
/** Holds if `n` represents a `null` value. */
4338
predicate isNullValue(TypeFlowNode n);

shared/typeflow/codeql/typeflow/internal/TypeFlowImpl.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ private import codeql.util.Unit
55
module TypeFlow<LocationSig Location, TypeFlowInput<Location> I> {
66
private import I
77

8+
/**
9+
* Holds if data can flow from `n1` to `n2` in one step, and `n1` is
10+
* functionally determined by `n2`.
11+
*/
12+
private predicate uniqStep(TypeFlowNode n1, TypeFlowNode n2) { n1 = unique(TypeFlowNode n | step(n, n2)) }
13+
14+
/**
15+
* Holds if data can flow from `n1` to `n2` in one step, and `n1` is not
16+
* functionally determined by `n2`.
17+
*/
18+
private predicate joinStep(TypeFlowNode n1, TypeFlowNode n2) { step(n1, n2) and not uniqStep(n1, n2) }
19+
820
/** Holds if `null` is the only value that flows to `n`. */
9-
predicate isNull(TypeFlowNode n) {
21+
private predicate isNull(TypeFlowNode n) {
1022
isNullValue(n)
1123
or
1224
exists(TypeFlowNode mid | isNull(mid) and uniqStep(mid, n))

0 commit comments

Comments
 (0)