Skip to content

Commit 4e44201

Browse files
committed
C++: Remap calls to source functions to the summarized function.
1 parent 98265dd commit 4e44201

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,21 @@ class DataFlowCall extends TDataFlowCall {
11271127
/**
11281128
* Gets the `Function` that the call targets, if this is statically known.
11291129
*/
1130-
DataFlowCallable getStaticCallTarget() { none() }
1130+
Function getStaticCallSourceTarget() { none() }
1131+
1132+
/**
1133+
* Gets the target of this call. If a summarized callable exists for the
1134+
* target this is chosen, and otherwise the callable is the implementation
1135+
* from the source code.
1136+
*/
1137+
DataFlowCallable getStaticCallTarget() {
1138+
exists(Function target | target = this.getStaticCallSourceTarget() |
1139+
not exists(TSummarizedCallable(target)) and
1140+
result.asSourceCallable() = target
1141+
or
1142+
result.asSummarizedCallable() = target
1143+
)
1144+
}
11311145

11321146
/**
11331147
* Gets the `index`'th argument operand. The qualifier is considered to have index `-1`.
@@ -1173,14 +1187,12 @@ private class NormalCall extends DataFlowCall, TNormalCall {
11731187

11741188
override CallTargetOperand getCallTargetOperand() { result = call.getCallTargetOperand() }
11751189

1176-
override DataFlowCallable getStaticCallTarget() {
1177-
result.getUnderlyingCallable() = call.getStaticCallTarget()
1178-
}
1190+
override Function getStaticCallSourceTarget() { result = call.getStaticCallTarget() }
11791191

11801192
override ArgumentOperand getArgumentOperand(int index) { result = call.getArgumentOperand(index) }
11811193

11821194
override DataFlowCallable getEnclosingCallable() {
1183-
result.getUnderlyingCallable() = call.getEnclosingFunction()
1195+
result.asSourceCallable() = call.getEnclosingFunction()
11841196
}
11851197

11861198
override string toString() { result = call.toString() }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| tests.cpp:208:7:208:30 | call to madAndImplementedComplex | Unexpected result: ir |

0 commit comments

Comments
 (0)