Skip to content

Commit ec9ef33

Browse files
committed
C++: IR data flow through inheritance conversions
This makes IR data flow behave more like AST data flow, and it makes IR virtual dispatch work without further changes.
1 parent 49008c9 commit ec9ef33

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction
205205
iTo.(CopyInstruction).getSourceValue() = iFrom or
206206
iTo.(PhiInstruction).getAnOperand().getDef() = iFrom or
207207
// Treat all conversions as flow, even conversions between different numeric types.
208-
iTo.(ConvertInstruction).getUnary() = iFrom
208+
iTo.(ConvertInstruction).getUnary() = iFrom or
209+
iTo.(InheritanceConversionInstruction).getUnary() = iFrom
209210
}
210211

211212
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ struct Bottom : Middle {
2828
void VirtualDispatch(Bottom *bottomPtr, Bottom &bottomRef) {
2929
Top *topPtr = bottomPtr, &topRef = bottomRef;
3030

31-
sink(topPtr->isSource1()); // flow [NOT DETECTED]
31+
sink(topPtr->isSource1()); // flow [NOT DETECTED by AST]
3232
sink(topPtr->isSource2()); // flow [NOT DETECTED by AST]
33-
topPtr->isSink(source()); // flow [NOT DETECTED]
33+
topPtr->isSink(source()); // flow [NOT DETECTED by AST]
3434

3535
sink(topPtr->notSource1()); // no flow [FALSE POSITIVE]
3636
sink(topPtr->notSource2()); // no flow [FALSE POSITIVE]
3737
topPtr->notSink(source()); // no flow [FALSE POSITIVE]
3838

39-
sink(topRef.isSource1()); // flow [NOT DETECTED]
39+
sink(topRef.isSource1()); // flow [NOT DETECTED by AST]
4040
sink(topRef.isSource2()); // flow [NOT DETECTED by AST]
41-
topRef.isSink(source()); // flow [NOT DETECTED]
41+
topRef.isSink(source()); // flow [NOT DETECTED by AST]
4242

4343
sink(topRef.notSource1()); // no flow [FALSE POSITIVE]
4444
sink(topRef.notSource2()); // no flow [FALSE POSITIVE]

cpp/ql/test/library-tests/dataflow/dataflow-tests/test_diff.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
| clang.cpp:39:42:39:47 | clang.cpp:41:18:41:19 | IR only |
88
| dispatch.cpp:16:37:16:42 | dispatch.cpp:32:16:32:24 | IR only |
99
| dispatch.cpp:16:37:16:42 | dispatch.cpp:40:15:40:23 | IR only |
10+
| dispatch.cpp:22:37:22:42 | dispatch.cpp:31:16:31:24 | IR only |
11+
| dispatch.cpp:22:37:22:42 | dispatch.cpp:39:15:39:23 | IR only |
12+
| dispatch.cpp:33:18:33:23 | dispatch.cpp:23:38:23:38 | IR only |
13+
| dispatch.cpp:41:17:41:22 | dispatch.cpp:23:38:23:38 | IR only |
1014
| lambdas.cpp:8:10:8:15 | lambdas.cpp:14:3:14:6 | AST only |
1115
| lambdas.cpp:8:10:8:15 | lambdas.cpp:18:8:18:8 | AST only |
1216
| lambdas.cpp:8:10:8:15 | lambdas.cpp:21:3:21:6 | AST only |

cpp/ql/test/library-tests/dataflow/dataflow-tests/test_ir.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
| clang.cpp:45:17:45:18 | Load: m2 | clang.cpp:43:35:43:40 | Call: call to source |
1515
| dispatch.cpp:11:38:11:38 | Load: x | dispatch.cpp:37:19:37:24 | Call: call to source |
1616
| dispatch.cpp:11:38:11:38 | Load: x | dispatch.cpp:45:18:45:23 | Call: call to source |
17+
| dispatch.cpp:23:38:23:38 | Load: x | dispatch.cpp:33:18:33:23 | Call: call to source |
18+
| dispatch.cpp:23:38:23:38 | Load: x | dispatch.cpp:41:17:41:22 | Call: call to source |
19+
| dispatch.cpp:31:16:31:24 | Call: call to isSource1 | dispatch.cpp:22:37:22:42 | Call: call to source |
1720
| dispatch.cpp:32:16:32:24 | Call: call to isSource2 | dispatch.cpp:16:37:16:42 | Call: call to source |
1821
| dispatch.cpp:35:16:35:25 | Call: call to notSource1 | dispatch.cpp:9:37:9:42 | Call: call to source |
1922
| dispatch.cpp:36:16:36:25 | Call: call to notSource2 | dispatch.cpp:10:37:10:42 | Call: call to source |
23+
| dispatch.cpp:39:15:39:23 | Call: call to isSource1 | dispatch.cpp:22:37:22:42 | Call: call to source |
2024
| dispatch.cpp:40:15:40:23 | Call: call to isSource2 | dispatch.cpp:16:37:16:42 | Call: call to source |
2125
| dispatch.cpp:43:15:43:24 | Call: call to notSource1 | dispatch.cpp:9:37:9:42 | Call: call to source |
2226
| dispatch.cpp:44:15:44:24 | Call: call to notSource2 | dispatch.cpp:10:37:10:42 | Call: call to source |

0 commit comments

Comments
 (0)