mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
CPP: Test dataflow through lambdas.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
int source();
|
||||
void sink(...) {};
|
||||
|
||||
// --- lambdas ---
|
||||
|
||||
void test_lambdas()
|
||||
{
|
||||
int t = source();
|
||||
int u = 0;
|
||||
int v = 0;
|
||||
int w = 0;
|
||||
|
||||
auto a = [t, u]() -> int {
|
||||
sink(t); // flow from source() [NOT DETECTED]
|
||||
sink(u);
|
||||
return t;
|
||||
};
|
||||
sink(a()); // flow from source() [NOT DETECTED]
|
||||
|
||||
auto b = [&] {
|
||||
sink(t); // flow from source() [NOT DETECTED]
|
||||
sink(u);
|
||||
v = source(); // (v is reference captured)
|
||||
};
|
||||
b();
|
||||
sink(v); // flow from source() [NOT DETECTED]
|
||||
|
||||
auto c = [=] {
|
||||
sink(t); // flow from source() [NOT DETECTED]
|
||||
sink(u);
|
||||
};
|
||||
c();
|
||||
|
||||
auto d = [](int a, int b) {
|
||||
sink(a); // flow from source()
|
||||
sink(b);
|
||||
};
|
||||
d(t, u);
|
||||
|
||||
auto e = [](int &a, int &b, int &c) {
|
||||
sink(a); // flow from source()
|
||||
sink(b);
|
||||
c = source();
|
||||
};
|
||||
e(t, u, w);
|
||||
sink(w); // flow from source() [NOT DETECTED]
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
| acrossLinkTargets.cpp:12:8:12:8 | x | acrossLinkTargets.cpp:19:27:19:32 | call to source |
|
||||
| lambdas.cpp:35:8:35:8 | a | lambdas.cpp:8:10:8:15 | call to source |
|
||||
| lambdas.cpp:41:8:41:8 | a | lambdas.cpp:8:10:8:15 | call to source |
|
||||
| test.cpp:7:8:7:9 | t1 | test.cpp:6:12:6:17 | call to source |
|
||||
| test.cpp:9:8:9:9 | t1 | test.cpp:6:12:6:17 | call to source |
|
||||
| test.cpp:10:8:10:9 | t2 | test.cpp:6:12:6:17 | call to source |
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
| lambdas.cpp:8:10:8:15 | lambdas.cpp:35:8:35:8 | AST only |
|
||||
| lambdas.cpp:8:10:8:15 | lambdas.cpp:41:8:41:8 | AST only |
|
||||
| test.cpp:89:28:89:34 | test.cpp:92:8:92:14 | IR only |
|
||||
| test.cpp:100:13:100:18 | test.cpp:103:10:103:12 | AST only |
|
||||
| test.cpp:109:9:109:14 | test.cpp:110:10:110:12 | IR only |
|
||||
|
||||
Reference in New Issue
Block a user