Skip to content

Commit 0631bd7

Browse files
committed
C++: Add object/flow conflation for unions when resolving function pointers.
1 parent 16508b1 commit 0631bd7

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

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
@@ -1492,7 +1492,14 @@ predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
14921492
}
14931493

14941494
/** Extra data-flow steps needed for lambda flow analysis. */
1495-
predicate additionalLambdaFlowStep(Node nodeFrom, Node nodeTo, boolean preservesValue) { none() }
1495+
predicate additionalLambdaFlowStep(Node nodeFrom, Node nodeTo, boolean preservesValue) {
1496+
preservesValue = false and
1497+
exists(ContentSet cs | cs.isSingleton(any(UnionContent uc)) |
1498+
storeStep(nodeFrom, cs, nodeTo)
1499+
or
1500+
readStep(nodeFrom, cs, nodeTo)
1501+
)
1502+
}
14961503

14971504
predicate knownSourceModel(Node source, string model) { External::sourceNode(source, _, model) }
14981505

cpp/ql/test/library-tests/dataflow/dataflow-tests/dispatch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void callIdentityFunctions(Top *top, Bottom *bottom) { // $ ast-def=bottom ast-d
9393
using SinkFunctionType = void (*)(int);
9494

9595
void callSink(int x) {
96-
sink(x); // $ ir MISSING: ast,ir=107:17 ast,ir=140:8 ast,ir=144:8
96+
sink(x); // $ ir=107:17 ir=140:8 ir=144:8 MISSING: ast=107:17 ast=140:8 ast=144:8
9797
}
9898

9999
SinkFunctionType returnCallSink() {

cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ irFlow
183183
| dispatch.cpp:107:17:107:22 | call to source | dispatch.cpp:96:8:96:8 | x |
184184
| dispatch.cpp:117:38:117:43 | call to source | dispatch.cpp:129:18:129:25 | call to isSource |
185185
| dispatch.cpp:117:38:117:43 | call to source | dispatch.cpp:130:17:130:24 | call to isSource |
186+
| dispatch.cpp:140:8:140:13 | call to source | dispatch.cpp:96:8:96:8 | x |
187+
| dispatch.cpp:144:8:144:13 | call to source | dispatch.cpp:96:8:96:8 | x |
186188
| flowOut.cpp:5:16:5:21 | call to source | flowOut.cpp:31:9:31:9 | x |
187189
| flowOut.cpp:5:16:5:21 | call to source | flowOut.cpp:61:8:61:11 | access to array |
188190
| flowOut.cpp:84:18:84:23 | call to source | flowOut.cpp:85:8:85:9 | * ... |

0 commit comments

Comments
 (0)