Skip to content

Commit 2547a8d

Browse files
committed
C++: Fix join orders in 'DataFlowDispatch.qll' and Ssa.qll.
1 parent 21a1ee7 commit 2547a8d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ private module VirtualDispatch {
6363
|
6464
// Call argument
6565
exists(DataFlowCall call, int i |
66-
other.(DataFlow::ParameterNode).isParameterOf(call.getStaticCallTarget(), i) and
67-
src.(ArgumentNode).argumentOf(call, i)
66+
other
67+
.(DataFlow::ParameterNode)
68+
.isParameterOf(pragma[only_bind_into](call).getStaticCallTarget(), i) and
69+
src.(ArgumentNode).argumentOf(call, pragma[only_bind_into](pragma[only_bind_out](i)))
6870
) and
6971
allowOtherFromArg = true and
7072
allowFromArg = true
@@ -128,6 +130,7 @@ private module VirtualDispatch {
128130
*
129131
* Used to fix a join ordering issue in flowsFrom.
130132
*/
133+
pragma[noinline]
131134
private predicate returnNodeWithKindAndEnclosingCallable(
132135
ReturnNode node, ReturnKind kind, DataFlowCallable callable
133136
) {

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,16 @@ private module Cached {
436436
iTo.(InheritanceConversionInstruction).getUnary() = iFrom
437437
}
438438

439+
pragma[noinline]
440+
private predicate callTargetHasInputOutput(
441+
CallInstruction call, DataFlow::FunctionInput input, DataFlow::FunctionOutput output
442+
) {
443+
exists(DataFlow::DataFlowFunction func |
444+
call.getStaticCallTarget() = func and
445+
func.hasDataFlow(input, output)
446+
)
447+
}
448+
439449
private predicate flowOutOfAddressStep(Operand operand, Node nTo) {
440450
// Flow into a read node
441451
exists(ReadNode readNode | readNode = nTo |
@@ -500,13 +510,12 @@ private module Cached {
500510
or
501511
// Flow through a modelled function that has parameter -> return value flow.
502512
exists(
503-
CallInstruction call, DataFlow::DataFlowFunction func, int index,
504-
DataFlow::FunctionInput input, DataFlow::FunctionOutput output
513+
CallInstruction call, int index, DataFlow::FunctionInput input,
514+
DataFlow::FunctionOutput output
505515
|
506-
call.getStaticCallTarget() = func and
516+
callTargetHasInputOutput(call, input, output) and
507517
call.getArgumentOperand(index) = operand and
508518
not getSideEffectFor(call, index) instanceof ReadSideEffectInstruction and
509-
func.hasDataFlow(input, output) and
510519
input.isParameter(index) and
511520
output.isReturnValue() and
512521
flowOutOfAddressStep(call.getAUse(), nTo)

0 commit comments

Comments
 (0)