Skip to content

Commit 52a232e

Browse files
committed
Dataflow: Make CallContext type private to DataFlowImplCommon.
1 parent 947c2bf commit 52a232e

File tree

2 files changed

+47
-31
lines changed

2 files changed

+47
-31
lines changed

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
32923292
exists(AccessPathApprox apa0 |
32933293
Stage5::parameterMayFlowThrough(p, _) and
32943294
Stage5::revFlow(n, state, TReturnCtxMaybeFlowThrough(_), _, apa0) and
3295-
Stage5::fwdFlow(n, state, any(CallContextCall ccc), TParamNodeSome(p.asNode()), _,
3295+
Stage5::fwdFlow(n, state, any(Stage5Param::CcCall ccc), TParamNodeSome(p.asNode()), _,
32963296
TAccessPathApproxSome(apa), _, apa0, _)
32973297
)
32983298
}
@@ -3486,8 +3486,18 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
34863486
import LocalCallContext
34873487
}
34883488

3489+
private class CallContext = PrunedCallContextSensitivityStage5::Cc;
3490+
3491+
private class CallContextCall = PrunedCallContextSensitivityStage5::CcCall;
3492+
3493+
private class CallContextNoCall = PrunedCallContextSensitivityStage5::CcNoCall;
3494+
3495+
private predicate callContextNone = PrunedCallContextSensitivityStage5::ccNone/0;
3496+
3497+
private predicate callContextSomeCall = PrunedCallContextSensitivityStage5::ccSomeCall/0;
3498+
34893499
private predicate sourceCallCtx(CallContext cc) {
3490-
if hasSourceCallCtx() then cc instanceof CallContextSomeCall else cc instanceof CallContextAny
3500+
if hasSourceCallCtx() then cc = callContextSomeCall() else cc = callContextNone()
34913501
}
34923502

34933503
private newtype TPathNode =
@@ -4071,9 +4081,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
40714081
state = mid.getState() and
40724082
cc = mid.getCallContext() and
40734083
sc = mid.getSummaryCtx() and
4074-
localCC =
4075-
getLocalCallContext(pragma[only_bind_into](pragma[only_bind_out](cc)),
4076-
midnode.getEnclosingCallable()) and
4084+
localCC = PrunedCallContextSensitivityStage5::getLocalCc(midnode.getEnclosingCallable(), cc) and
40774085
t = mid.getType() and
40784086
ap = mid.getAp() and
40794087
summaryLabel = mid.getSummaryLabel()
@@ -4119,7 +4127,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
41194127
or
41204128
jumpStepEx(mid.getNodeExOutgoing(), node) and
41214129
state = mid.getState() and
4122-
cc instanceof CallContextAny and
4130+
cc = callContextNone() and
41234131
sc instanceof SummaryCtxNone and
41244132
t = mid.getType() and
41254133
ap = mid.getAp() and
@@ -4129,7 +4137,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
41294137
or
41304138
additionalJumpStep(mid.getNodeExOutgoing(), node, label) and
41314139
state = mid.getState() and
4132-
cc instanceof CallContextAny and
4140+
cc = callContextNone() and
41334141
sc instanceof SummaryCtxNone and
41344142
mid.getAp() instanceof AccessPathNil and
41354143
t = node.getDataFlowType() and
@@ -4138,7 +4146,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
41384146
summaryLabel = "-"
41394147
or
41404148
additionalJumpStateStep(mid.getNodeExOutgoing(), mid.getState(), node, state) and
4141-
cc instanceof CallContextAny and
4149+
cc = callContextNone() and
41424150
sc instanceof SummaryCtxNone and
41434151
mid.getAp() instanceof AccessPathNil and
41444152
t = node.getDataFlowType() and
@@ -4673,22 +4681,32 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
46734681
private predicate flagDisable() { none() }
46744682

46754683
module FlowExplorationFwd<explorationLimitSig/0 explorationLimit> {
4676-
private import FlowExploration<explorationLimit/0, flagEnable/0, flagDisable/0>
4677-
import Public
4684+
private import FlowExploration<explorationLimit/0, flagEnable/0, flagDisable/0> as F
4685+
import F::Public
46784686

4679-
predicate partialFlow = partialFlowFwd/3;
4687+
predicate partialFlow = F::partialFlowFwd/3;
46804688
}
46814689

46824690
module FlowExplorationRev<explorationLimitSig/0 explorationLimit> {
4683-
private import FlowExploration<explorationLimit/0, flagDisable/0, flagEnable/0>
4684-
import Public
4691+
private import FlowExploration<explorationLimit/0, flagDisable/0, flagEnable/0> as F
4692+
import F::Public
46854693

4686-
predicate partialFlow = partialFlowRev/3;
4694+
predicate partialFlow = F::partialFlowRev/3;
46874695
}
46884696

46894697
private module FlowExploration<
46904698
explorationLimitSig/0 explorationLimit, flag/0 flagFwd, flag/0 flagRev>
46914699
{
4700+
class CallContext = CachedCallContextSensitivity::Cc;
4701+
4702+
class CallContextCall = CachedCallContextSensitivity::CcCall;
4703+
4704+
class CallContextNoCall = CachedCallContextSensitivity::CcNoCall;
4705+
4706+
predicate callContextNone = CachedCallContextSensitivity::ccNone/0;
4707+
4708+
predicate callContextSomeCall = CachedCallContextSensitivity::ccSomeCall/0;
4709+
46924710
private predicate callableStep(DataFlowCallable c1, DataFlowCallable c2) {
46934711
exists(NodeEx node1, NodeEx node2 |
46944712
jumpStepEx(node1, node2)
@@ -4859,7 +4877,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
48594877
) {
48604878
flagFwd() and
48614879
sourceNode(node, state) and
4862-
cc instanceof CallContextAny and
4880+
cc = callContextNone() and
48634881
sc1 = TSummaryCtx1None() and
48644882
sc2 = TSummaryCtx2None() and
48654883
sc3 = TSummaryCtx3None() and
@@ -5073,7 +5091,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
50735091

50745092
predicate isSource() {
50755093
sourceNode(node, state) and
5076-
cc instanceof CallContextAny and
5094+
cc = callContextNone() and
50775095
sc1 = TSummaryCtx1None() and
50785096
sc2 = TSummaryCtx2None() and
50795097
sc3 = TSummaryCtx3None() and
@@ -5125,10 +5143,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
51255143
TSummaryCtx2 sc2, TSummaryCtx3 sc3, TSummaryCtx4 sc4, DataFlowType t, PartialAccessPath ap,
51265144
boolean isStoreStep
51275145
) {
5128-
not exists(NodeRegion nr |
5129-
nr.contains(node.asNode()) and
5130-
isUnreachableInCallCached(nr, cc.(CallContextSpecificCall).getCall())
5131-
) and
5146+
not isUnreachableInCall1(node,
5147+
CachedCallContextSensitivity::LocalCallContext::getLocalCc(node.getEnclosingCallable(), cc)) and
51325148
(
51335149
localFlowStepEx(mid.getNodeEx(), node, _) and
51345150
state = mid.getState() and
@@ -5165,7 +5181,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
51655181
or
51665182
jumpStepEx(mid.getNodeEx(), node) and
51675183
state = mid.getState() and
5168-
cc instanceof CallContextAny and
5184+
cc = callContextNone() and
51695185
sc1 = TSummaryCtx1None() and
51705186
sc2 = TSummaryCtx2None() and
51715187
sc3 = TSummaryCtx3None() and
@@ -5176,7 +5192,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
51765192
or
51775193
additionalJumpStep(mid.getNodeEx(), node, _) and
51785194
state = mid.getState() and
5179-
cc instanceof CallContextAny and
5195+
cc = callContextNone() and
51805196
sc1 = TSummaryCtx1None() and
51815197
sc2 = TSummaryCtx2None() and
51825198
sc3 = TSummaryCtx3None() and
@@ -5187,7 +5203,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
51875203
isStoreStep = false
51885204
or
51895205
additionalJumpStateStep(mid.getNodeEx(), mid.getState(), node, state) and
5190-
cc instanceof CallContextAny and
5206+
cc = callContextNone() and
51915207
sc1 = TSummaryCtx1None() and
51925208
sc2 = TSummaryCtx2None() and
51935209
sc3 = TSummaryCtx3None() and

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,28 +1825,28 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
18251825
* this dispatch target of `call` implies a reduced set of dispatch origins
18261826
* to which data may flow if it should reach a `return` statement.
18271827
*/
1828-
abstract class CallContext extends TCallContext {
1828+
abstract private class CallContext extends TCallContext {
18291829
abstract string toString();
18301830

18311831
/** Holds if this call context is relevant for `callable`. */
18321832
abstract predicate relevantFor(DataFlowCallable callable);
18331833
}
18341834

1835-
abstract class CallContextNoCall extends CallContext { }
1835+
abstract private class CallContextNoCall extends CallContext { }
18361836

1837-
class CallContextAny extends CallContextNoCall, TAnyCallContext {
1837+
private class CallContextAny extends CallContextNoCall, TAnyCallContext {
18381838
override string toString() { result = "CcAny" }
18391839

18401840
override predicate relevantFor(DataFlowCallable callable) { any() }
18411841
}
18421842

1843-
abstract class CallContextCall extends CallContext {
1843+
abstract private class CallContextCall extends CallContext {
18441844
/** Holds if this call context may be `call`. */
18451845
bindingset[call]
18461846
abstract predicate matchesCall(DataFlowCall call);
18471847
}
18481848

1849-
class CallContextSpecificCall extends CallContextCall, TSpecificCall {
1849+
private class CallContextSpecificCall extends CallContextCall, TSpecificCall {
18501850
override string toString() {
18511851
exists(DataFlowCall call | this = TSpecificCall(call) | result = "CcCall(" + call + ")")
18521852
}
@@ -1860,15 +1860,15 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
18601860
DataFlowCall getCall() { this = TSpecificCall(result) }
18611861
}
18621862

1863-
class CallContextSomeCall extends CallContextCall, TSomeCall {
1863+
private class CallContextSomeCall extends CallContextCall, TSomeCall {
18641864
override string toString() { result = "CcSomeCall" }
18651865

18661866
override predicate relevantFor(DataFlowCallable callable) { any() }
18671867

18681868
override predicate matchesCall(DataFlowCall call) { any() }
18691869
}
18701870

1871-
class CallContextReturn extends CallContextNoCall, TReturn {
1871+
private class CallContextReturn extends CallContextNoCall, TReturn {
18721872
override string toString() {
18731873
exists(DataFlowCall call | this = TReturn(_, call) | result = "CcReturn(" + call + ")")
18741874
}
@@ -1923,7 +1923,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
19231923
* Gets the local call context given the call context and the callable that
19241924
* the contexts apply to.
19251925
*/
1926-
LocalCallContext getLocalCallContext(CallContext ctx, DataFlowCallable callable) {
1926+
private LocalCallContext getLocalCallContext(CallContext ctx, DataFlowCallable callable) {
19271927
ctx.relevantFor(callable) and
19281928
if relevantLocalCCtx(ctx.(CallContextSpecificCall).getCall(), callable)
19291929
then

0 commit comments

Comments
 (0)