Skip to content

Commit a6902bd

Browse files
committed
CPP: Test dataflow through lambdas.
1 parent 1bd4aee commit a6902bd

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
int source();
2+
void sink(...) {};
3+
4+
// --- lambdas ---
5+
6+
void test_lambdas()
7+
{
8+
int t = source();
9+
int u = 0;
10+
int v = 0;
11+
int w = 0;
12+
13+
auto a = [t, u]() -> int {
14+
sink(t); // flow from source() [NOT DETECTED]
15+
sink(u);
16+
return t;
17+
};
18+
sink(a()); // flow from source() [NOT DETECTED]
19+
20+
auto b = [&] {
21+
sink(t); // flow from source() [NOT DETECTED]
22+
sink(u);
23+
v = source(); // (v is reference captured)
24+
};
25+
b();
26+
sink(v); // flow from source() [NOT DETECTED]
27+
28+
auto c = [=] {
29+
sink(t); // flow from source() [NOT DETECTED]
30+
sink(u);
31+
};
32+
c();
33+
34+
auto d = [](int a, int b) {
35+
sink(a); // flow from source()
36+
sink(b);
37+
};
38+
d(t, u);
39+
40+
auto e = [](int &a, int &b, int &c) {
41+
sink(a); // flow from source()
42+
sink(b);
43+
c = source();
44+
};
45+
e(t, u, w);
46+
sink(w); // flow from source() [NOT DETECTED]
47+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
| acrossLinkTargets.cpp:12:8:12:8 | x | acrossLinkTargets.cpp:19:27:19:32 | call to source |
2+
| lambdas.cpp:35:8:35:8 | a | lambdas.cpp:8:10:8:15 | call to source |
3+
| lambdas.cpp:41:8:41:8 | a | lambdas.cpp:8:10:8:15 | call to source |
24
| test.cpp:7:8:7:9 | t1 | test.cpp:6:12:6:17 | call to source |
35
| test.cpp:9:8:9:9 | t1 | test.cpp:6:12:6:17 | call to source |
46
| 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
| lambdas.cpp:8:10:8:15 | lambdas.cpp:35:8:35:8 | AST only |
2+
| lambdas.cpp:8:10:8:15 | lambdas.cpp:41:8:41:8 | AST only |
13
| test.cpp:89:28:89:34 | test.cpp:92:8:92:14 | IR only |
24
| test.cpp:100:13:100:18 | test.cpp:103:10:103:12 | AST only |
35
| test.cpp:109:9:109:14 | test.cpp:110:10:110:12 | IR only |

0 commit comments

Comments
 (0)