Skip to content

Commit 35a6784

Browse files
committed
C++: Implement ParameterPosition et al
1 parent 540ecf3 commit 35a6784

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
private import cpp
2+
private import semmle.code.cpp.dataflow.internal.DataFlowPrivate
3+
private import semmle.code.cpp.dataflow.internal.DataFlowUtil
24

35
/**
46
* Gets a function that might be called by `call`.
@@ -63,3 +65,17 @@ predicate mayBenefitFromCallContext(Call call, Function f) { none() }
6365
* restricted to those `call`s for which a context might make a difference.
6466
*/
6567
Function viableImplInCallContext(Call call, Call ctx) { none() }
68+
69+
/** A parameter position represented by an integer. */
70+
class ParameterPosition extends int {
71+
ParameterPosition() { any(ParameterNode p).isParameterOf(_, this) }
72+
}
73+
74+
/** An argument position represented by an integer. */
75+
class ArgumentPosition extends int {
76+
ArgumentPosition() { any(ArgumentNode a).argumentOf(_, this) }
77+
}
78+
79+
/** Holds if arguments at position `apos` match parameters at position `ppos`. */
80+
pragma[inline]
81+
predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) { ppos = apos }

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ private import DataFlowImplConsistency
88
DataFlowCallable nodeGetEnclosingCallable(Node n) { result = n.getEnclosingCallable() }
99

1010
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
11-
predicate isParameterNode(ParameterNode p, DataFlowCallable c, int pos) { p.isParameterOf(c, pos) }
11+
predicate isParameterNode(ParameterNode p, DataFlowCallable c, ParameterPosition pos) {
12+
p.isParameterOf(c, pos)
13+
}
14+
15+
/** Holds if `arg` is an `ArgumentNode` of `c` with position `pos`. */
16+
predicate isArgumentNode(ArgumentNode arg, DataFlowCall c, ArgumentPosition pos) {
17+
arg.argumentOf(c, pos)
18+
}
1219

1320
/** Gets the instance argument of a non-static call. */
1421
private Node getInstanceArgument(Call call) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ private import cpp
22
private import semmle.code.cpp.ir.IR
33
private import semmle.code.cpp.ir.dataflow.DataFlow
44
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
5+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil
56
private import DataFlowImplCommon as DataFlowImplCommon
67

78
/**
@@ -266,3 +267,17 @@ Function viableImplInCallContext(CallInstruction call, CallInstruction ctx) {
266267
result = ctx.getArgument(i).getUnconvertedResultExpression().(FunctionAccess).getTarget()
267268
)
268269
}
270+
271+
/** A parameter position represented by an integer. */
272+
class ParameterPosition extends int {
273+
ParameterPosition() { any(ParameterNode p).isParameterOf(_, this) }
274+
}
275+
276+
/** An argument position represented by an integer. */
277+
class ArgumentPosition extends int {
278+
ArgumentPosition() { any(ArgumentNode a).argumentOf(_, this) }
279+
}
280+
281+
/** Holds if arguments at position `apos` match parameters at position `ppos`. */
282+
pragma[inline]
283+
predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) { ppos = apos }

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ private import DataFlowImplConsistency
88
DataFlowCallable nodeGetEnclosingCallable(Node n) { result = n.getEnclosingCallable() }
99

1010
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
11-
predicate isParameterNode(ParameterNode p, DataFlowCallable c, int pos) { p.isParameterOf(c, pos) }
11+
predicate isParameterNode(ParameterNode p, DataFlowCallable c, ParameterPosition pos) {
12+
p.isParameterOf(c, pos)
13+
}
14+
15+
/** Holds if `arg` is an `ArgumentNode` of `c` with position `pos`. */
16+
predicate isArgumentNode(ArgumentNode arg, DataFlowCall c, ArgumentPosition pos) {
17+
arg.argumentOf(c, pos)
18+
}
1219

1320
/**
1421
* A data flow node that occurs as the argument of a call and is passed as-is

0 commit comments

Comments
 (0)