Skip to content

Commit 32b5c7f

Browse files
committed
C++: Model implied dataflow
1 parent a4d7bfb commit 32b5c7f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,27 @@ private predicate modelFlow(Operand opFrom, Instruction iTo) {
920920
)
921921
)
922922
)
923+
or
924+
impliedModelFlow(opFrom, iTo)
925+
}
926+
927+
/**
928+
* When a `DataFlowFunction` specifies dataflow from a parameter `p` to the return value there should
929+
* also be dataflow from the parameter dereference (i.e., `*p`) to the return value dereference.
930+
*/
931+
private predicate impliedModelFlow(Operand opFrom, Instruction iTo) {
932+
exists(
933+
CallInstruction call, DataFlowFunction func, FunctionInput modelIn, FunctionOutput modelOut,
934+
int index
935+
|
936+
call.getStaticCallTarget() = func and
937+
func.hasDataFlow(modelIn, modelOut)
938+
|
939+
modelIn.isParameterOrQualifierAddress(index) and
940+
modelOut.isReturnValue() and
941+
opFrom = getSideEffectFor(call, index).(ReadSideEffectInstruction).getSideEffectOperand() and
942+
iTo = call // TODO: Add write side effects for return values
943+
)
923944
}
924945

925946
/**

cpp/ql/src/semmle/code/cpp/models/interfaces/FunctionInputsAndOutputs.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ class FunctionInput extends TFunctionInput {
108108
*/
109109
predicate isQualifierAddress() { none() }
110110

111+
/**
112+
* Holds if `i >= 0` and `isParameter(i)` holds for this value, or
113+
* if `i = -1` and `isQualifierAddress()` holds for this value.
114+
*/
115+
final predicate isParameterOrQualifierAddress(ParameterIndex i) {
116+
i >= 0 and this.isParameter(i)
117+
or
118+
i = -1 and this.isQualifierAddress()
119+
}
120+
111121
/**
112122
* Holds if this is the input value pointed to by the return value of a
113123
* function, if the function returns a pointer, or the input value referred
@@ -134,7 +144,7 @@ class FunctionInput extends TFunctionInput {
134144
predicate isReturnValueDeref() { none() }
135145

136146
/**
137-
* Holds if `i >= 0` and `isParameterDeref(i)` holds for this is value, or
147+
* Holds if `i >= 0` and `isParameterDeref(i)` holds for this value, or
138148
* if `i = -1` and `isQualifierObject()` holds for this value.
139149
*/
140150
final predicate isParameterDerefOrQualifierObject(ParameterIndex i) {

0 commit comments

Comments
 (0)