Skip to content

Commit 10ce13d

Browse files
committed
C++: Tests for cross-target dispatch
1 parent 14f1ecb commit 10ce13d

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
int source();
2+
void sink(int);
3+
4+
// For the purpose of this test, this function acts like it's defined in a
5+
// different link target such that we get two different functions named
6+
// `calleeAcrossLinkTargets` and no link from the caller to this one. The test
7+
// is getting that effect because the library can't distinguish the two
8+
// overloaded functions that differ only on `int` vs. `long`, so we might lose
9+
// this result and be forced to write a better test if the function signature
10+
// detection should improve.
11+
void calleeAcrossLinkTargets(long x) {
12+
sink(x);
13+
}
14+
15+
void calleeAcrossLinkTargets(int x); // no body
16+
17+
18+
void callerAcrossLinkTargets() {
19+
calleeAcrossLinkTargets(source());
20+
}
21+
22+
///////////////////////////////////////////////////////////////////////////////
23+
24+
25+
// No flow into this function as its signature is not unique (in the limited
26+
// model of the library).
27+
void ambiguousCallee(long x) {
28+
sink(x);
29+
}
30+
31+
// No flow into this function as its signature is not unique (in the limited
32+
// model of the library).
33+
void ambiguousCallee(short x) {
34+
sink(x);
35+
}
36+
37+
void ambiguousCallee(int x); // no body
38+
39+
40+
void ambiguousCaller() {
41+
ambiguousCallee(source());
42+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| acrossLinkTargets.cpp:12:8:12:8 | x | acrossLinkTargets.cpp:19:27:19:32 | call to source |
12
| test.cpp:7:8:7:9 | t1 | test.cpp:6:12:6:17 | call to source |
23
| test.cpp:9:8:9:9 | t1 | test.cpp:6:12:6:17 | call to source |
34
| test.cpp:10:8:10:9 | t2 | test.cpp:6:12:6:17 | call to source |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| acrossLinkTargets.cpp:19:27:19:32 | acrossLinkTargets.cpp:12:8:12:8 | AST only |
12
| test.cpp:66:30:66:36 | test.cpp:71:8:71:9 | AST only |
23
| test.cpp:89:28:89:34 | test.cpp:92:8:92:14 | IR only |
34
| test.cpp:100:13:100:18 | test.cpp:103:10:103:12 | AST only |

0 commit comments

Comments
 (0)