Skip to content

Commit 86e6d0b

Browse files
committed
Dataflow: Switch local call contexts to use canonical representative.
1 parent 012e1b4 commit 86e6d0b

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
350350

351351
pragma[nomagic]
352352
private predicate isUnreachableInCall1(NodeEx n, LocalCallContextSpecificCall cc) {
353-
exists(NodeRegion nr |
354-
nr.contains(n.asNode()) and
355-
isUnreachableInCallCached(nr, cc.getCall())
356-
)
353+
cc.unreachable(n.asNode())
357354
}
358355

359356
/**

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ private import codeql.typetracking.TypeTracking as Tt
33
private import codeql.util.Location
44
private import codeql.util.Unit
55
private import codeql.util.Option
6+
private import codeql.util.internal.MakeSets
67

78
module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
89
private import Lang
@@ -406,6 +407,27 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
406407
result = viableCallableLambda(call, _)
407408
}
408409

410+
private newtype TCallEdge =
411+
TMkCallEdge(DataFlowCall call, DataFlowCallable tgt) { viableCallableExt(call) = tgt }
412+
413+
private module UnreachableSetsInput implements MkSetsInp {
414+
class Key = TCallEdge;
415+
416+
class Value = NodeRegion;
417+
418+
NodeRegion getAValue(TCallEdge edge) {
419+
exists(DataFlowCall call, DataFlowCallable tgt |
420+
edge = TMkCallEdge(call, tgt) and
421+
getNodeRegionEnclosingCallable(result) = tgt and
422+
isUnreachableInCallCached(result, call)
423+
)
424+
}
425+
426+
int totalorder(NodeRegion nr) { result = nr.totalOrder() }
427+
}
428+
429+
private module UnreachableSets = MakeSets<UnreachableSetsInput>;
430+
409431
signature module CallContextSensitivityInputSig {
410432
/** Holds if the edge is possibly needed in the direction `call` to `c`. */
411433
predicate relevantCallEdgeIn(DataFlowCall call, DataFlowCallable c);
@@ -1254,7 +1276,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
12541276
cached
12551277
newtype TLocalFlowCallContext =
12561278
TAnyLocalCall() or
1257-
TSpecificLocalCall(DataFlowCall call) { isUnreachableInCallCached(_, call) }
1279+
TSpecificLocalCall(UnreachableSets::ValueSet ns)
12581280

12591281
cached
12601282
newtype TReturnKindExt =
@@ -1814,15 +1836,18 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
18141836
}
18151837

18161838
class LocalCallContextSpecificCall extends LocalCallContext, TSpecificLocalCall {
1817-
LocalCallContextSpecificCall() { this = TSpecificLocalCall(call) }
1839+
LocalCallContextSpecificCall() { this = TSpecificLocalCall(ns) }
18181840

1819-
DataFlowCall call;
1841+
UnreachableSets::ValueSet ns;
18201842

1821-
DataFlowCall getCall() { result = call }
1843+
override string toString() { result = "LocalCcCall" }
18221844

1823-
override string toString() { result = "LocalCcCall(" + call + ")" }
1845+
override predicate relevantFor(DataFlowCallable callable) {
1846+
exists(NodeRegion nr | ns.contains(nr) and callable = getNodeRegionEnclosingCallable(nr))
1847+
}
18241848

1825-
override predicate relevantFor(DataFlowCallable callable) { relevantLocalCCtx(call, callable) }
1849+
/** Holds if this call context makes `n` unreachable. */
1850+
predicate unreachable(Node n) { exists(NodeRegion nr | ns.contains(nr) and nr.contains(n)) }
18261851
}
18271852

18281853
private DataFlowCallable getNodeRegionEnclosingCallable(NodeRegion nr) {
@@ -1842,7 +1867,10 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
18421867
LocalCallContext getLocalCallContext(CallContext ctx, DataFlowCallable callable) {
18431868
ctx.relevantFor(callable) and
18441869
if relevantLocalCCtx(ctx.(CallContextSpecificCall).getCall(), callable)
1845-
then result.(LocalCallContextSpecificCall).getCall() = ctx.(CallContextSpecificCall).getCall()
1870+
then
1871+
result =
1872+
TSpecificLocalCall(UnreachableSets::getValueSet(TMkCallEdge(ctx.(CallContextSpecificCall)
1873+
.getCall(), callable)))
18461874
else result instanceof LocalCallContextAny
18471875
}
18481876

0 commit comments

Comments
 (0)