Skip to content

Commit d7e965f

Browse files
committed
Dataflow: Add lightweight api based on TypeTracking.
1 parent d7bd8c7 commit d7e965f

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
private import codeql.dataflow.DataFlow
2+
private import codeql.typetracking.TypeTracking as Tt
23

34
module MakeImplCommon<InputSig Lang> {
45
private import Lang
@@ -52,8 +53,82 @@ module MakeImplCommon<InputSig Lang> {
5253
class FeatureEqualSourceSinkCallContext extends FlowFeature, TFeatureEqualSourceSinkCallContext {
5354
override string toString() { result = "FeatureEqualSourceSinkCallContext" }
5455
}
56+
57+
signature predicate sourceNode(Node n);
58+
59+
/**
60+
* EXPERIMENTAL: This API is subject to change without notice.
61+
*
62+
* Given a source definition, this constructs a simple forward flow
63+
* computation with an access path limit of 1.
64+
*/
65+
module SimpleGlobal<sourceNode/1 source> {
66+
import TypeTracking::TypeTrack<source/1>
67+
}
5568
}
5669

70+
private module TypeTrackingInput implements Tt::TypeTrackingInput {
71+
final class Node = Lang::Node;
72+
73+
class LocalSourceNode extends Node {
74+
LocalSourceNode() {
75+
storeStep(_, this, _) or
76+
loadStep(_, this, _) or
77+
jumpStepCached(_, this) or
78+
this instanceof ParamNode or
79+
this instanceof OutNodeExt
80+
}
81+
}
82+
83+
final private class LangContentSet = Lang::ContentSet;
84+
85+
class Content extends LangContentSet {
86+
string toString() { result = "Content" }
87+
}
88+
89+
class ContentFilter extends Content {
90+
Content getAMatchingContent() { result = this }
91+
}
92+
93+
predicate compatibleContents(Content storeContents, Content loadContents) {
94+
storeContents.getAStoreContent() = loadContents.getAReadContent()
95+
}
96+
97+
predicate simpleLocalSmallStep = simpleLocalFlowStepExt/2;
98+
99+
predicate levelStepNoCall(Node n1, LocalSourceNode n2) { none() }
100+
101+
predicate levelStepCall(Node n1, LocalSourceNode n2) {
102+
argumentValueFlowsThrough(n1, TReadStepTypesNone(), n2)
103+
}
104+
105+
predicate storeStep(Node n1, Node n2, Content f) { storeSet(n1, f, n2, _, _) }
106+
107+
predicate loadStep(Node n1, LocalSourceNode n2, Content f) {
108+
readSet(n1, f, n2)
109+
or
110+
argumentValueFlowsThrough(n1, TReadStepTypesSome(_, f, _), n2)
111+
}
112+
113+
predicate loadStoreStep(Node nodeFrom, Node nodeTo, Content f1, Content f2) { none() }
114+
115+
predicate withContentStep(Node nodeFrom, LocalSourceNode nodeTo, ContentFilter f) { none() }
116+
117+
predicate withoutContentStep(Node nodeFrom, LocalSourceNode nodeTo, ContentFilter f) { none() }
118+
119+
predicate jumpStep(Node n1, LocalSourceNode n2) { jumpStepCached(n1, n2) }
120+
121+
predicate callStep(Node n1, LocalSourceNode n2) { viableParamArg(_, n2, n1) }
122+
123+
predicate returnStep(Node n1, LocalSourceNode n2) {
124+
viableReturnPosOut(_, getReturnPosition(n1), n2)
125+
}
126+
127+
predicate hasFeatureBacktrackStoreTarget() { none() }
128+
}
129+
130+
private module TypeTracking = Tt::TypeTracking<TypeTrackingInput>;
131+
57132
/**
58133
* The cost limits for the `AccessPathFront` to `AccessPathApprox` expansion.
59134
*

shared/dataflow/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ groups: shared
44
library: true
55
dependencies:
66
codeql/ssa: ${workspace}
7+
codeql/typetracking: ${workspace}
78
codeql/util: ${workspace}
89
warnOnImplicitThis: true

0 commit comments

Comments
 (0)