Skip to content

Commit 4908721

Browse files
committed
Data flow: Sync files
1 parent 07ca1c2 commit 4908721

File tree

7 files changed

+150
-104
lines changed

7 files changed

+150
-104
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
6262
tupleLimit = 1000
6363
}
6464

65+
/**
66+
* Holds if `arg` is an argument of `call` with an argument position that matches
67+
* parameter position `ppos`.
68+
*/
69+
pragma[noinline]
70+
predicate argumentPositionMatch(DataFlowCall call, ArgNode arg, ParameterPosition ppos) {
71+
exists(ArgumentPosition apos |
72+
arg.argumentOf(call, apos) and
73+
parameterMatch(ppos, apos)
74+
)
75+
}
76+
6577
/**
6678
* Provides a simple data-flow analysis for resolving lambda calls. The analysis
6779
* currently excludes read-steps, store-steps, and flow-through.
@@ -71,31 +83,27 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
7183
* calls. For this reason, we cannot reuse the code from `DataFlowImpl.qll` directly.
7284
*/
7385
private module LambdaFlow {
74-
private predicate viableParamNonLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
75-
exists(ParameterPosition ppos |
76-
p.isParameterOf(viableCallable(call), ppos) and
77-
parameterMatch(ppos, apos)
78-
)
86+
pragma[noinline]
87+
private predicate viableParamNonLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
88+
p.isParameterOf(viableCallable(call), ppos)
7989
}
8090

81-
private predicate viableParamLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
82-
exists(ParameterPosition ppos |
83-
p.isParameterOf(viableCallableLambda(call, _), ppos) and
84-
parameterMatch(ppos, apos)
85-
)
91+
pragma[noinline]
92+
private predicate viableParamLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
93+
p.isParameterOf(viableCallableLambda(call, _), ppos)
8694
}
8795

8896
private predicate viableParamArgNonLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
89-
exists(ArgumentPosition pos |
90-
viableParamNonLambda(call, pos, p) and
91-
arg.argumentOf(call, pos)
97+
exists(ParameterPosition ppos |
98+
viableParamNonLambda(call, ppos, p) and
99+
argumentPositionMatch(call, arg, ppos)
92100
)
93101
}
94102

95103
private predicate viableParamArgLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
96-
exists(ArgumentPosition pos |
97-
viableParamLambda(call, pos, p) and
98-
arg.argumentOf(call, pos)
104+
exists(ParameterPosition ppos |
105+
viableParamLambda(call, ppos, p) and
106+
argumentPositionMatch(call, arg, ppos)
99107
)
100108
}
101109

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
6262
tupleLimit = 1000
6363
}
6464

65+
/**
66+
* Holds if `arg` is an argument of `call` with an argument position that matches
67+
* parameter position `ppos`.
68+
*/
69+
pragma[noinline]
70+
predicate argumentPositionMatch(DataFlowCall call, ArgNode arg, ParameterPosition ppos) {
71+
exists(ArgumentPosition apos |
72+
arg.argumentOf(call, apos) and
73+
parameterMatch(ppos, apos)
74+
)
75+
}
76+
6577
/**
6678
* Provides a simple data-flow analysis for resolving lambda calls. The analysis
6779
* currently excludes read-steps, store-steps, and flow-through.
@@ -71,31 +83,27 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
7183
* calls. For this reason, we cannot reuse the code from `DataFlowImpl.qll` directly.
7284
*/
7385
private module LambdaFlow {
74-
private predicate viableParamNonLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
75-
exists(ParameterPosition ppos |
76-
p.isParameterOf(viableCallable(call), ppos) and
77-
parameterMatch(ppos, apos)
78-
)
86+
pragma[noinline]
87+
private predicate viableParamNonLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
88+
p.isParameterOf(viableCallable(call), ppos)
7989
}
8090

81-
private predicate viableParamLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
82-
exists(ParameterPosition ppos |
83-
p.isParameterOf(viableCallableLambda(call, _), ppos) and
84-
parameterMatch(ppos, apos)
85-
)
91+
pragma[noinline]
92+
private predicate viableParamLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
93+
p.isParameterOf(viableCallableLambda(call, _), ppos)
8694
}
8795

8896
private predicate viableParamArgNonLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
89-
exists(ArgumentPosition pos |
90-
viableParamNonLambda(call, pos, p) and
91-
arg.argumentOf(call, pos)
97+
exists(ParameterPosition ppos |
98+
viableParamNonLambda(call, ppos, p) and
99+
argumentPositionMatch(call, arg, ppos)
92100
)
93101
}
94102

95103
private predicate viableParamArgLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
96-
exists(ArgumentPosition pos |
97-
viableParamLambda(call, pos, p) and
98-
arg.argumentOf(call, pos)
104+
exists(ParameterPosition ppos |
105+
viableParamLambda(call, ppos, p) and
106+
argumentPositionMatch(call, arg, ppos)
99107
)
100108
}
101109

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
6262
tupleLimit = 1000
6363
}
6464

65+
/**
66+
* Holds if `arg` is an argument of `call` with an argument position that matches
67+
* parameter position `ppos`.
68+
*/
69+
pragma[noinline]
70+
predicate argumentPositionMatch(DataFlowCall call, ArgNode arg, ParameterPosition ppos) {
71+
exists(ArgumentPosition apos |
72+
arg.argumentOf(call, apos) and
73+
parameterMatch(ppos, apos)
74+
)
75+
}
76+
6577
/**
6678
* Provides a simple data-flow analysis for resolving lambda calls. The analysis
6779
* currently excludes read-steps, store-steps, and flow-through.
@@ -71,31 +83,27 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
7183
* calls. For this reason, we cannot reuse the code from `DataFlowImpl.qll` directly.
7284
*/
7385
private module LambdaFlow {
74-
private predicate viableParamNonLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
75-
exists(ParameterPosition ppos |
76-
p.isParameterOf(viableCallable(call), ppos) and
77-
parameterMatch(ppos, apos)
78-
)
86+
pragma[noinline]
87+
private predicate viableParamNonLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
88+
p.isParameterOf(viableCallable(call), ppos)
7989
}
8090

81-
private predicate viableParamLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
82-
exists(ParameterPosition ppos |
83-
p.isParameterOf(viableCallableLambda(call, _), ppos) and
84-
parameterMatch(ppos, apos)
85-
)
91+
pragma[noinline]
92+
private predicate viableParamLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
93+
p.isParameterOf(viableCallableLambda(call, _), ppos)
8694
}
8795

8896
private predicate viableParamArgNonLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
89-
exists(ArgumentPosition pos |
90-
viableParamNonLambda(call, pos, p) and
91-
arg.argumentOf(call, pos)
97+
exists(ParameterPosition ppos |
98+
viableParamNonLambda(call, ppos, p) and
99+
argumentPositionMatch(call, arg, ppos)
92100
)
93101
}
94102

95103
private predicate viableParamArgLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
96-
exists(ArgumentPosition pos |
97-
viableParamLambda(call, pos, p) and
98-
arg.argumentOf(call, pos)
104+
exists(ParameterPosition ppos |
105+
viableParamLambda(call, ppos, p) and
106+
argumentPositionMatch(call, arg, ppos)
99107
)
100108
}
101109

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,14 @@ module Private {
710710
)
711711
}
712712

713+
pragma[noinline]
714+
private predicate viableParam(
715+
DataFlowCall call, SummarizedCallable sc, ParameterPosition ppos, ParamNode p
716+
) {
717+
p.isParameterOf(sc, ppos) and
718+
sc = viableCallable(call)
719+
}
720+
713721
/**
714722
* Holds if values stored inside content `c` are cleared inside a
715723
* callable to which `arg` is an argument.
@@ -718,23 +726,18 @@ module Private {
718726
* `arg` (see comment for `summaryClearsContent`).
719727
*/
720728
predicate summaryClearsContentArg(ArgNode arg, Content c) {
721-
exists(DataFlowCall call, ParameterPosition ppos, ArgumentPosition apos |
722-
viableCallable(call).(SummarizedCallable).clearsContent(ppos, c) and
723-
arg.argumentOf(call, apos) and
724-
parameterMatch(ppos, apos)
729+
exists(DataFlowCall call, SummarizedCallable sc, ParameterPosition ppos |
730+
argumentPositionMatch(call, arg, ppos) and
731+
viableParam(call, sc, ppos, _) and
732+
sc.clearsContent(ppos, c)
725733
)
726734
}
727735

728736
pragma[nomagic]
729737
private ParamNode summaryArgParam(ArgNode arg, ReturnKindExt rk, OutNodeExt out) {
730-
exists(
731-
DataFlowCall call, ParameterPosition ppos, ArgumentPosition apos,
732-
SummarizedCallable callable
733-
|
734-
arg.argumentOf(call, apos) and
735-
viableCallable(call) = callable and
736-
result.isParameterOf(callable, ppos) and
737-
parameterMatch(ppos, apos) and
738+
exists(DataFlowCall call, ParameterPosition ppos, SummarizedCallable sc |
739+
argumentPositionMatch(call, arg, ppos) and
740+
viableParam(call, sc, ppos, result) and
738741
out = rk.getAnOutNode(call)
739742
)
740743
}

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImplCommon.qll

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
6262
tupleLimit = 1000
6363
}
6464

65+
/**
66+
* Holds if `arg` is an argument of `call` with an argument position that matches
67+
* parameter position `ppos`.
68+
*/
69+
pragma[noinline]
70+
predicate argumentPositionMatch(DataFlowCall call, ArgNode arg, ParameterPosition ppos) {
71+
exists(ArgumentPosition apos |
72+
arg.argumentOf(call, apos) and
73+
parameterMatch(ppos, apos)
74+
)
75+
}
76+
6577
/**
6678
* Provides a simple data-flow analysis for resolving lambda calls. The analysis
6779
* currently excludes read-steps, store-steps, and flow-through.
@@ -71,31 +83,27 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
7183
* calls. For this reason, we cannot reuse the code from `DataFlowImpl.qll` directly.
7284
*/
7385
private module LambdaFlow {
74-
private predicate viableParamNonLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
75-
exists(ParameterPosition ppos |
76-
p.isParameterOf(viableCallable(call), ppos) and
77-
parameterMatch(ppos, apos)
78-
)
86+
pragma[noinline]
87+
private predicate viableParamNonLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
88+
p.isParameterOf(viableCallable(call), ppos)
7989
}
8090

81-
private predicate viableParamLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
82-
exists(ParameterPosition ppos |
83-
p.isParameterOf(viableCallableLambda(call, _), ppos) and
84-
parameterMatch(ppos, apos)
85-
)
91+
pragma[noinline]
92+
private predicate viableParamLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
93+
p.isParameterOf(viableCallableLambda(call, _), ppos)
8694
}
8795

8896
private predicate viableParamArgNonLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
89-
exists(ArgumentPosition pos |
90-
viableParamNonLambda(call, pos, p) and
91-
arg.argumentOf(call, pos)
97+
exists(ParameterPosition ppos |
98+
viableParamNonLambda(call, ppos, p) and
99+
argumentPositionMatch(call, arg, ppos)
92100
)
93101
}
94102

95103
private predicate viableParamArgLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
96-
exists(ArgumentPosition pos |
97-
viableParamLambda(call, pos, p) and
98-
arg.argumentOf(call, pos)
104+
exists(ParameterPosition ppos |
105+
viableParamLambda(call, ppos, p) and
106+
argumentPositionMatch(call, arg, ppos)
99107
)
100108
}
101109

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
6262
tupleLimit = 1000
6363
}
6464

65+
/**
66+
* Holds if `arg` is an argument of `call` with an argument position that matches
67+
* parameter position `ppos`.
68+
*/
69+
pragma[noinline]
70+
predicate argumentPositionMatch(DataFlowCall call, ArgNode arg, ParameterPosition ppos) {
71+
exists(ArgumentPosition apos |
72+
arg.argumentOf(call, apos) and
73+
parameterMatch(ppos, apos)
74+
)
75+
}
76+
6577
/**
6678
* Provides a simple data-flow analysis for resolving lambda calls. The analysis
6779
* currently excludes read-steps, store-steps, and flow-through.
@@ -71,31 +83,27 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
7183
* calls. For this reason, we cannot reuse the code from `DataFlowImpl.qll` directly.
7284
*/
7385
private module LambdaFlow {
74-
private predicate viableParamNonLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
75-
exists(ParameterPosition ppos |
76-
p.isParameterOf(viableCallable(call), ppos) and
77-
parameterMatch(ppos, apos)
78-
)
86+
pragma[noinline]
87+
private predicate viableParamNonLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
88+
p.isParameterOf(viableCallable(call), ppos)
7989
}
8090

81-
private predicate viableParamLambda(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
82-
exists(ParameterPosition ppos |
83-
p.isParameterOf(viableCallableLambda(call, _), ppos) and
84-
parameterMatch(ppos, apos)
85-
)
91+
pragma[noinline]
92+
private predicate viableParamLambda(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
93+
p.isParameterOf(viableCallableLambda(call, _), ppos)
8694
}
8795

8896
private predicate viableParamArgNonLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
89-
exists(ArgumentPosition pos |
90-
viableParamNonLambda(call, pos, p) and
91-
arg.argumentOf(call, pos)
97+
exists(ParameterPosition ppos |
98+
viableParamNonLambda(call, ppos, p) and
99+
argumentPositionMatch(call, arg, ppos)
92100
)
93101
}
94102

95103
private predicate viableParamArgLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
96-
exists(ArgumentPosition pos |
97-
viableParamLambda(call, pos, p) and
98-
arg.argumentOf(call, pos)
104+
exists(ParameterPosition ppos |
105+
viableParamLambda(call, ppos, p) and
106+
argumentPositionMatch(call, arg, ppos)
99107
)
100108
}
101109

0 commit comments

Comments
 (0)