Skip to content

Commit 26490bd

Browse files
authored
Merge pull request #1885 from jbj/dataflow-D.cpp
C++: Add D.cpp, ported from D.java
2 parents 57afde0 + ea3d066 commit 26490bd

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
void sink(void *o);
2+
3+
class D {
4+
public:
5+
struct Elem { };
6+
7+
struct Box1 {
8+
Elem *elem;
9+
Box1(Elem *e) { elem = e; }
10+
Elem* getElem() { return elem; }
11+
void setElem(Elem *e) { elem = e; }
12+
};
13+
14+
struct Box2 {
15+
Box1* box;
16+
Box2(Box1* b) { box = b; }
17+
Box1* getBox1() { return box; }
18+
void setBox1(Box1* b) { box = b; }
19+
};
20+
21+
static void sinkWrap(Box2* b2) {
22+
sink(b2->getBox1()->getElem());
23+
}
24+
25+
Box2* boxfield;
26+
27+
void f1() {
28+
Elem* e = new Elem(); // source of flow to sinkWrap
29+
Box2* b = new Box2(new Box1(nullptr));
30+
b->box->elem = e;
31+
sinkWrap(b);
32+
}
33+
34+
void f2() {
35+
Elem* e = new Elem(); // source of flow to sinkWrap
36+
Box2* b = new Box2(new Box1(nullptr));
37+
b->box->setElem(e);
38+
sinkWrap(b);
39+
}
40+
41+
void f3() {
42+
Elem* e = new Elem(); // source of flow to sinkWrap
43+
Box2* b = new Box2(new Box1(nullptr));
44+
b->getBox1()->elem = e;
45+
sinkWrap(b);
46+
}
47+
48+
void f4() {
49+
Elem* e = new Elem(); // source of flow to sinkWrap
50+
Box2* b = new Box2(new Box1(nullptr));
51+
b->getBox1()->setElem(e);
52+
sinkWrap(b);
53+
}
54+
55+
void f5a() {
56+
Elem* e = new Elem(); // source of flow to f5b
57+
boxfield = new Box2(new Box1(nullptr));
58+
boxfield->box->elem = e;
59+
f5b();
60+
}
61+
62+
private:
63+
void f5b() {
64+
sink(boxfield->box->elem);
65+
}
66+
};

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,39 @@ edges
8989
| C.cpp:27:8:27:11 | `this` parameter in func [s3] | C.cpp:31:10:31:11 | this [s3] |
9090
| C.cpp:29:10:29:11 | this [s1] | C.cpp:29:10:29:11 | s1 |
9191
| C.cpp:31:10:31:11 | this [s3] | C.cpp:31:10:31:11 | s3 |
92+
| D.cpp:21:30:21:31 | b2 [box, elem] | D.cpp:22:10:22:11 | b2 [box, elem] |
93+
| D.cpp:22:10:22:11 | b2 [box, elem] | D.cpp:22:14:22:20 | call to getBox1 [elem] |
94+
| D.cpp:22:14:22:20 | call to getBox1 [elem] | D.cpp:22:25:22:31 | call to getElem |
95+
| D.cpp:28:15:28:24 | new | D.cpp:30:5:30:20 | ... = ... |
96+
| D.cpp:30:5:30:5 | b [post update] [box, elem] | D.cpp:31:14:31:14 | b [box, elem] |
97+
| D.cpp:30:5:30:20 | ... = ... | D.cpp:30:8:30:10 | box [post update] [elem] |
98+
| D.cpp:30:8:30:10 | box [post update] [elem] | D.cpp:30:5:30:5 | b [post update] [box, elem] |
99+
| D.cpp:31:14:31:14 | b [box, elem] | D.cpp:21:30:21:31 | b2 [box, elem] |
100+
| D.cpp:35:15:35:24 | new | D.cpp:37:21:37:21 | e |
101+
| D.cpp:37:5:37:5 | b [post update] [box, elem] | D.cpp:38:14:38:14 | b [box, elem] |
102+
| D.cpp:37:8:37:10 | box [post update] [elem] | D.cpp:37:5:37:5 | b [post update] [box, elem] |
103+
| D.cpp:37:21:37:21 | e | D.cpp:37:8:37:10 | box [post update] [elem] |
104+
| D.cpp:38:14:38:14 | b [box, elem] | D.cpp:21:30:21:31 | b2 [box, elem] |
105+
| D.cpp:42:15:42:24 | new | D.cpp:44:5:44:26 | ... = ... |
106+
| D.cpp:44:5:44:5 | b [post update] [box, elem] | D.cpp:45:14:45:14 | b [box, elem] |
107+
| D.cpp:44:5:44:26 | ... = ... | D.cpp:44:8:44:14 | call to getBox1 [post update] [elem] |
108+
| D.cpp:44:8:44:14 | call to getBox1 [post update] [elem] | D.cpp:44:5:44:5 | b [post update] [box, elem] |
109+
| D.cpp:45:14:45:14 | b [box, elem] | D.cpp:21:30:21:31 | b2 [box, elem] |
110+
| D.cpp:49:15:49:24 | new | D.cpp:51:27:51:27 | e |
111+
| D.cpp:51:5:51:5 | b [post update] [box, elem] | D.cpp:52:14:52:14 | b [box, elem] |
112+
| D.cpp:51:8:51:14 | call to getBox1 [post update] [elem] | D.cpp:51:5:51:5 | b [post update] [box, elem] |
113+
| D.cpp:51:27:51:27 | e | D.cpp:51:8:51:14 | call to getBox1 [post update] [elem] |
114+
| D.cpp:52:14:52:14 | b [box, elem] | D.cpp:21:30:21:31 | b2 [box, elem] |
115+
| D.cpp:56:15:56:24 | new | D.cpp:58:5:58:27 | ... = ... |
116+
| D.cpp:58:5:58:12 | boxfield [post update] [box, elem] | D.cpp:58:5:58:12 | this [post update] [boxfield, box, ... (3)] |
117+
| D.cpp:58:5:58:12 | this [post update] [boxfield, box, ... (3)] | D.cpp:59:5:59:7 | this [boxfield, box, ... (3)] |
118+
| D.cpp:58:5:58:27 | ... = ... | D.cpp:58:15:58:17 | box [post update] [elem] |
119+
| D.cpp:58:15:58:17 | box [post update] [elem] | D.cpp:58:5:58:12 | boxfield [post update] [box, elem] |
120+
| D.cpp:59:5:59:7 | this [boxfield, box, ... (3)] | D.cpp:63:8:63:10 | `this` parameter in f5b [boxfield, box, ... (3)] |
121+
| D.cpp:63:8:63:10 | `this` parameter in f5b [boxfield, box, ... (3)] | D.cpp:64:10:64:17 | this [boxfield, box, ... (3)] |
122+
| D.cpp:64:10:64:17 | boxfield [box, elem] | D.cpp:64:20:64:22 | box [elem] |
123+
| D.cpp:64:10:64:17 | this [boxfield, box, ... (3)] | D.cpp:64:10:64:17 | boxfield [box, elem] |
124+
| D.cpp:64:20:64:22 | box [elem] | D.cpp:64:25:64:28 | elem |
92125
| aliasing.cpp:9:3:9:3 | s [post update] [m1] | aliasing.cpp:25:17:25:19 | ref arg & ... [m1] |
93126
| aliasing.cpp:9:3:9:22 | ... = ... | aliasing.cpp:9:3:9:3 | s [post update] [m1] |
94127
| aliasing.cpp:9:11:9:20 | call to user_input | aliasing.cpp:9:3:9:22 | ... = ... |
@@ -191,6 +224,11 @@ edges
191224
| B.cpp:19:20:19:24 | elem2 | B.cpp:15:15:15:27 | new | B.cpp:19:20:19:24 | elem2 | elem2 flows from $@ | B.cpp:15:15:15:27 | new | new |
192225
| C.cpp:29:10:29:11 | s1 | C.cpp:22:12:22:21 | new | C.cpp:29:10:29:11 | s1 | s1 flows from $@ | C.cpp:22:12:22:21 | new | new |
193226
| C.cpp:31:10:31:11 | s3 | C.cpp:24:16:24:25 | new | C.cpp:31:10:31:11 | s3 | s3 flows from $@ | C.cpp:24:16:24:25 | new | new |
227+
| D.cpp:22:25:22:31 | call to getElem | D.cpp:28:15:28:24 | new | D.cpp:22:25:22:31 | call to getElem | call to getElem flows from $@ | D.cpp:28:15:28:24 | new | new |
228+
| D.cpp:22:25:22:31 | call to getElem | D.cpp:35:15:35:24 | new | D.cpp:22:25:22:31 | call to getElem | call to getElem flows from $@ | D.cpp:35:15:35:24 | new | new |
229+
| D.cpp:22:25:22:31 | call to getElem | D.cpp:42:15:42:24 | new | D.cpp:22:25:22:31 | call to getElem | call to getElem flows from $@ | D.cpp:42:15:42:24 | new | new |
230+
| D.cpp:22:25:22:31 | call to getElem | D.cpp:49:15:49:24 | new | D.cpp:22:25:22:31 | call to getElem | call to getElem flows from $@ | D.cpp:49:15:49:24 | new | new |
231+
| D.cpp:64:25:64:28 | elem | D.cpp:56:15:56:24 | new | D.cpp:64:25:64:28 | elem | elem flows from $@ | D.cpp:56:15:56:24 | new | new |
194232
| aliasing.cpp:29:11:29:12 | m1 | aliasing.cpp:9:11:9:20 | call to user_input | aliasing.cpp:29:11:29:12 | m1 | m1 flows from $@ | aliasing.cpp:9:11:9:20 | call to user_input | call to user_input |
195233
| aliasing.cpp:30:11:30:12 | m1 | aliasing.cpp:13:10:13:19 | call to user_input | aliasing.cpp:30:11:30:12 | m1 | m1 flows from $@ | aliasing.cpp:13:10:13:19 | call to user_input | call to user_input |
196234
| aliasing.cpp:62:14:62:15 | m1 | aliasing.cpp:60:11:60:20 | call to user_input | aliasing.cpp:62:14:62:15 | m1 | m1 flows from $@ | aliasing.cpp:60:11:60:20 | call to user_input | call to user_input |

0 commit comments

Comments
 (0)