Skip to content

Commit 27b8dc2

Browse files
committed
C++: Add tests for flow through arrays
1 parent 951e309 commit 27b8dc2

File tree

9 files changed

+158
-5
lines changed

9 files changed

+158
-5
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
void sink(void *o);
2+
void *user_input(void);
3+
4+
void local_array() {
5+
void *arr[10] = { 0 };
6+
arr[0] = user_input();
7+
sink(arr[0]); // $ir $f-:ast
8+
sink(arr[1]);
9+
sink(*arr); // $ir $f-:ast
10+
sink(*&arr[0]); // $ir $f-:ast
11+
}
12+
13+
void local_array_convoluted_assign() {
14+
void *arr[10] = { 0 };
15+
*&arr[0] = user_input();
16+
sink(arr[0]); // $ir $f-:ast
17+
sink(arr[1]);
18+
}
19+
20+
struct inner {
21+
void *data;
22+
int unrelated;
23+
};
24+
25+
struct middle {
26+
inner arr[10];
27+
inner *ptr;
28+
};
29+
30+
struct outer {
31+
middle nested;
32+
middle *indirect;
33+
};
34+
35+
void nested_array_1(outer o) {
36+
o.nested.arr[1].data = user_input();
37+
sink(o.nested.arr[1].data); // $ir $f-:ast
38+
sink(o.nested.arr[0].data);
39+
}
40+
41+
void nested_array_2(outer o) {
42+
o.indirect->arr[1].data = user_input();
43+
sink(o.indirect->arr[1].data); // $f-:ast,ir
44+
sink(o.indirect->arr[0].data);
45+
}
46+
47+
void nested_array_3(outer o) {
48+
o.indirect->ptr[1].data = user_input();
49+
sink(o.indirect->ptr[1].data); // $f-:ast,ir
50+
sink(o.indirect->ptr[0].data);
51+
}

cpp/ql/test/library-tests/dataflow/fields/by_reference.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ void test_outer_with_ptr(Outer *pouter) {
109109

110110
sink(outer.inner_nested.a); // $ast,ir
111111
sink(outer.inner_ptr->a); // $ast $f-:ir
112-
sink(outer.a); // $f-:ast $f-:ir
112+
sink(outer.a); // $f-:ast,ir
113113

114114
sink(pouter->inner_nested.a); // $ast,ir
115115
sink(pouter->inner_ptr->a); // $ast $f-:ir
116-
sink(pouter->a); // $f-:ast $f-:ir
116+
sink(pouter->a); // $f-:ast,ir
117117
}
118118

119119
void test_outer_with_ref(Outer *pouter) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ argHasPostUpdate
3030
| D.cpp:43:24:43:40 | new | ArgumentNode is missing PostUpdateNode. |
3131
| D.cpp:50:24:50:40 | new | ArgumentNode is missing PostUpdateNode. |
3232
| D.cpp:57:25:57:41 | new | ArgumentNode is missing PostUpdateNode. |
33+
| arrays.cpp:7:8:7:13 | access to array | ArgumentNode is missing PostUpdateNode. |
34+
| arrays.cpp:8:8:8:13 | access to array | ArgumentNode is missing PostUpdateNode. |
35+
| arrays.cpp:9:8:9:11 | * ... | ArgumentNode is missing PostUpdateNode. |
36+
| arrays.cpp:10:8:10:15 | * ... | ArgumentNode is missing PostUpdateNode. |
37+
| arrays.cpp:16:8:16:13 | access to array | ArgumentNode is missing PostUpdateNode. |
38+
| arrays.cpp:17:8:17:13 | access to array | ArgumentNode is missing PostUpdateNode. |
3339
| by_reference.cpp:51:8:51:8 | s | ArgumentNode is missing PostUpdateNode. |
3440
| by_reference.cpp:57:8:57:8 | s | ArgumentNode is missing PostUpdateNode. |
3541
| by_reference.cpp:63:8:63:8 | s | ArgumentNode is missing PostUpdateNode. |

cpp/ql/test/library-tests/dataflow/fields/dataflow-ir-consistency.expected

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
uniqueEnclosingCallable
22
uniqueType
33
uniqueNodeLocation
4-
| D.cpp:1:17:1:17 | o | Node should have one location but has 3. |
5-
| by_reference.cpp:1:17:1:17 | o | Node should have one location but has 3. |
4+
| D.cpp:1:17:1:17 | o | Node should have one location but has 4. |
5+
| arrays.cpp:1:17:1:17 | o | Node should have one location but has 4. |
6+
| by_reference.cpp:1:17:1:17 | o | Node should have one location but has 4. |
67
| file://:0:0:0:0 | p#0 | Node should have one location but has 0. |
78
| file://:0:0:0:0 | p#0 | Node should have one location but has 0. |
89
| file://:0:0:0:0 | p#0 | Node should have one location but has 0. |
910
| file://:0:0:0:0 | p#0 | Node should have one location but has 0. |
10-
| qualifiers.cpp:1:17:1:17 | o | Node should have one location but has 3. |
11+
| qualifiers.cpp:1:17:1:17 | o | Node should have one location but has 4. |
1112
missingLocation
1213
| Nodes without location: 4 |
1314
uniqueNodeToString

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
| aliasing.cpp:79:11:79:20 | call to user_input | aliasing.cpp:80:12:80:13 | m1 | IR only |
2222
| aliasing.cpp:86:10:86:19 | call to user_input | aliasing.cpp:87:12:87:13 | m1 | IR only |
2323
| aliasing.cpp:98:10:98:19 | call to user_input | aliasing.cpp:102:8:102:10 | * ... | IR only |
24+
| arrays.cpp:6:12:6:21 | call to user_input | arrays.cpp:7:8:7:13 | access to array | IR only |
25+
| arrays.cpp:6:12:6:21 | call to user_input | arrays.cpp:9:8:9:11 | * ... | IR only |
26+
| arrays.cpp:6:12:6:21 | call to user_input | arrays.cpp:10:8:10:15 | * ... | IR only |
27+
| arrays.cpp:15:14:15:23 | call to user_input | arrays.cpp:16:8:16:13 | access to array | IR only |
28+
| arrays.cpp:36:26:36:35 | call to user_input | arrays.cpp:37:24:37:27 | data | IR only |
2429
| by_reference.cpp:84:14:84:23 | call to user_input | by_reference.cpp:111:25:111:25 | a | AST only |
2530
| by_reference.cpp:84:14:84:23 | call to user_input | by_reference.cpp:115:27:115:27 | a | AST only |
2631
| by_reference.cpp:88:13:88:22 | call to user_input | by_reference.cpp:131:25:131:25 | a | AST only |

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ edges
6464
| aliasing.cpp:98:3:98:21 | Store | aliasing.cpp:98:3:98:21 | Chi [m1] |
6565
| aliasing.cpp:98:10:98:19 | call to user_input | aliasing.cpp:98:3:98:21 | Store |
6666
| aliasing.cpp:100:14:100:14 | Store [m1] | aliasing.cpp:102:8:102:10 | * ... |
67+
| arrays.cpp:6:12:6:21 | call to user_input | arrays.cpp:7:8:7:13 | access to array |
68+
| arrays.cpp:6:12:6:21 | call to user_input | arrays.cpp:9:8:9:11 | * ... |
69+
| arrays.cpp:6:12:6:21 | call to user_input | arrays.cpp:10:8:10:15 | * ... |
70+
| arrays.cpp:15:14:15:23 | call to user_input | arrays.cpp:16:8:16:13 | access to array |
71+
| arrays.cpp:36:26:36:35 | call to user_input | arrays.cpp:37:24:37:27 | data |
6772
| by_reference.cpp:50:3:50:3 | setDirectly output argument [a] | by_reference.cpp:51:8:51:8 | Argument -1 indirection [a] |
6873
| by_reference.cpp:50:17:50:26 | call to user_input | by_reference.cpp:50:3:50:3 | setDirectly output argument [a] |
6974
| by_reference.cpp:51:8:51:8 | Argument -1 indirection [a] | by_reference.cpp:51:10:51:20 | call to getDirectly |
@@ -256,6 +261,14 @@ nodes
256261
| aliasing.cpp:98:10:98:19 | call to user_input | semmle.label | call to user_input |
257262
| aliasing.cpp:100:14:100:14 | Store [m1] | semmle.label | Store [m1] |
258263
| aliasing.cpp:102:8:102:10 | * ... | semmle.label | * ... |
264+
| arrays.cpp:6:12:6:21 | call to user_input | semmle.label | call to user_input |
265+
| arrays.cpp:7:8:7:13 | access to array | semmle.label | access to array |
266+
| arrays.cpp:9:8:9:11 | * ... | semmle.label | * ... |
267+
| arrays.cpp:10:8:10:15 | * ... | semmle.label | * ... |
268+
| arrays.cpp:15:14:15:23 | call to user_input | semmle.label | call to user_input |
269+
| arrays.cpp:16:8:16:13 | access to array | semmle.label | access to array |
270+
| arrays.cpp:36:26:36:35 | call to user_input | semmle.label | call to user_input |
271+
| arrays.cpp:37:24:37:27 | data | semmle.label | data |
259272
| by_reference.cpp:50:3:50:3 | setDirectly output argument [a] | semmle.label | setDirectly output argument [a] |
260273
| by_reference.cpp:50:17:50:26 | call to user_input | semmle.label | call to user_input |
261274
| by_reference.cpp:51:8:51:8 | Argument -1 indirection [a] | semmle.label | Argument -1 indirection [a] |
@@ -395,6 +408,11 @@ nodes
395408
| aliasing.cpp:87:12:87:13 | m1 | aliasing.cpp:86:10:86:19 | call to user_input | aliasing.cpp:87:12:87:13 | m1 | m1 flows from $@ | aliasing.cpp:86:10:86:19 | call to user_input | call to user_input |
396409
| aliasing.cpp:93:12:93:13 | m1 | aliasing.cpp:92:12:92:21 | call to user_input | aliasing.cpp:93:12:93:13 | m1 | m1 flows from $@ | aliasing.cpp:92:12:92:21 | call to user_input | call to user_input |
397410
| aliasing.cpp:102:8:102:10 | * ... | aliasing.cpp:98:10:98:19 | call to user_input | aliasing.cpp:102:8:102:10 | * ... | * ... flows from $@ | aliasing.cpp:98:10:98:19 | call to user_input | call to user_input |
411+
| arrays.cpp:7:8:7:13 | access to array | arrays.cpp:6:12:6:21 | call to user_input | arrays.cpp:7:8:7:13 | access to array | access to array flows from $@ | arrays.cpp:6:12:6:21 | call to user_input | call to user_input |
412+
| arrays.cpp:9:8:9:11 | * ... | arrays.cpp:6:12:6:21 | call to user_input | arrays.cpp:9:8:9:11 | * ... | * ... flows from $@ | arrays.cpp:6:12:6:21 | call to user_input | call to user_input |
413+
| arrays.cpp:10:8:10:15 | * ... | arrays.cpp:6:12:6:21 | call to user_input | arrays.cpp:10:8:10:15 | * ... | * ... flows from $@ | arrays.cpp:6:12:6:21 | call to user_input | call to user_input |
414+
| arrays.cpp:16:8:16:13 | access to array | arrays.cpp:15:14:15:23 | call to user_input | arrays.cpp:16:8:16:13 | access to array | access to array flows from $@ | arrays.cpp:15:14:15:23 | call to user_input | call to user_input |
415+
| arrays.cpp:37:24:37:27 | data | arrays.cpp:36:26:36:35 | call to user_input | arrays.cpp:37:24:37:27 | data | data flows from $@ | arrays.cpp:36:26:36:35 | call to user_input | call to user_input |
398416
| by_reference.cpp:51:10:51:20 | call to getDirectly | by_reference.cpp:50:17:50:26 | call to user_input | by_reference.cpp:51:10:51:20 | call to getDirectly | call to getDirectly flows from $@ | by_reference.cpp:50:17:50:26 | call to user_input | call to user_input |
399417
| by_reference.cpp:57:10:57:22 | call to getIndirectly | by_reference.cpp:56:19:56:28 | call to user_input | by_reference.cpp:57:10:57:22 | call to getIndirectly | call to getIndirectly flows from $@ | by_reference.cpp:56:19:56:28 | call to user_input | call to user_input |
400418
| by_reference.cpp:63:10:63:28 | call to getThroughNonMember | by_reference.cpp:62:25:62:34 | call to user_input | by_reference.cpp:63:10:63:28 | call to getThroughNonMember | call to getThroughNonMember flows from $@ | by_reference.cpp:62:25:62:34 | call to user_input | call to user_input |

cpp/ql/test/library-tests/dataflow/fields/partial-definition-diff.expected

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,41 @@
158158
| aliasing.cpp:92:3:92:3 | w | AST only |
159159
| aliasing.cpp:92:7:92:8 | m1 | AST only |
160160
| aliasing.cpp:98:5:98:6 | m1 | AST only |
161+
| arrays.cpp:36:3:36:3 | o | AST only |
162+
| arrays.cpp:36:5:36:10 | nested | AST only |
163+
| arrays.cpp:36:19:36:22 | data | AST only |
164+
| arrays.cpp:37:8:37:8 | o | AST only |
165+
| arrays.cpp:37:8:37:22 | access to array | AST only |
166+
| arrays.cpp:37:10:37:15 | nested | AST only |
167+
| arrays.cpp:37:24:37:27 | data | AST only |
168+
| arrays.cpp:38:8:38:8 | o | AST only |
169+
| arrays.cpp:38:8:38:22 | access to array | AST only |
170+
| arrays.cpp:38:10:38:15 | nested | AST only |
171+
| arrays.cpp:38:24:38:27 | data | AST only |
172+
| arrays.cpp:42:3:42:3 | o | AST only |
173+
| arrays.cpp:42:3:42:20 | access to array | AST only |
174+
| arrays.cpp:42:5:42:12 | indirect | AST only |
175+
| arrays.cpp:42:22:42:25 | data | AST only |
176+
| arrays.cpp:43:8:43:8 | o | AST only |
177+
| arrays.cpp:43:8:43:25 | access to array | AST only |
178+
| arrays.cpp:43:10:43:17 | indirect | AST only |
179+
| arrays.cpp:43:27:43:30 | data | AST only |
180+
| arrays.cpp:44:8:44:8 | o | AST only |
181+
| arrays.cpp:44:8:44:25 | access to array | AST only |
182+
| arrays.cpp:44:10:44:17 | indirect | AST only |
183+
| arrays.cpp:44:27:44:30 | data | AST only |
184+
| arrays.cpp:48:3:48:3 | o | AST only |
185+
| arrays.cpp:48:3:48:20 | access to array | AST only |
186+
| arrays.cpp:48:5:48:12 | indirect | AST only |
187+
| arrays.cpp:48:22:48:25 | data | AST only |
188+
| arrays.cpp:49:8:49:8 | o | AST only |
189+
| arrays.cpp:49:8:49:25 | access to array | AST only |
190+
| arrays.cpp:49:10:49:17 | indirect | AST only |
191+
| arrays.cpp:49:27:49:30 | data | AST only |
192+
| arrays.cpp:50:8:50:8 | o | AST only |
193+
| arrays.cpp:50:8:50:25 | access to array | AST only |
194+
| arrays.cpp:50:10:50:17 | indirect | AST only |
195+
| arrays.cpp:50:27:50:30 | data | AST only |
161196
| by_reference.cpp:12:8:12:8 | a | AST only |
162197
| by_reference.cpp:16:11:16:11 | a | AST only |
163198
| by_reference.cpp:20:5:20:8 | this | AST only |

cpp/ql/test/library-tests/dataflow/fields/partial-definition-ir.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
| aliasing.cpp:86:3:86:3 | s |
2828
| aliasing.cpp:92:5:92:5 | s |
2929
| aliasing.cpp:98:3:98:3 | s |
30+
| arrays.cpp:36:3:36:17 | access to array |
3031
| by_reference.cpp:12:5:12:5 | s |
3132
| by_reference.cpp:16:5:16:8 | this |
3233
| by_reference.cpp:84:3:84:7 | inner |

cpp/ql/test/library-tests/dataflow/fields/partial-definition.expected

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,42 @@
187187
| aliasing.cpp:92:7:92:8 | m1 |
188188
| aliasing.cpp:98:3:98:3 | s |
189189
| aliasing.cpp:98:5:98:6 | m1 |
190+
| arrays.cpp:36:3:36:3 | o |
191+
| arrays.cpp:36:3:36:17 | access to array |
192+
| arrays.cpp:36:5:36:10 | nested |
193+
| arrays.cpp:36:19:36:22 | data |
194+
| arrays.cpp:37:8:37:8 | o |
195+
| arrays.cpp:37:8:37:22 | access to array |
196+
| arrays.cpp:37:10:37:15 | nested |
197+
| arrays.cpp:37:24:37:27 | data |
198+
| arrays.cpp:38:8:38:8 | o |
199+
| arrays.cpp:38:8:38:22 | access to array |
200+
| arrays.cpp:38:10:38:15 | nested |
201+
| arrays.cpp:38:24:38:27 | data |
202+
| arrays.cpp:42:3:42:3 | o |
203+
| arrays.cpp:42:3:42:20 | access to array |
204+
| arrays.cpp:42:5:42:12 | indirect |
205+
| arrays.cpp:42:22:42:25 | data |
206+
| arrays.cpp:43:8:43:8 | o |
207+
| arrays.cpp:43:8:43:25 | access to array |
208+
| arrays.cpp:43:10:43:17 | indirect |
209+
| arrays.cpp:43:27:43:30 | data |
210+
| arrays.cpp:44:8:44:8 | o |
211+
| arrays.cpp:44:8:44:25 | access to array |
212+
| arrays.cpp:44:10:44:17 | indirect |
213+
| arrays.cpp:44:27:44:30 | data |
214+
| arrays.cpp:48:3:48:3 | o |
215+
| arrays.cpp:48:3:48:20 | access to array |
216+
| arrays.cpp:48:5:48:12 | indirect |
217+
| arrays.cpp:48:22:48:25 | data |
218+
| arrays.cpp:49:8:49:8 | o |
219+
| arrays.cpp:49:8:49:25 | access to array |
220+
| arrays.cpp:49:10:49:17 | indirect |
221+
| arrays.cpp:49:27:49:30 | data |
222+
| arrays.cpp:50:8:50:8 | o |
223+
| arrays.cpp:50:8:50:25 | access to array |
224+
| arrays.cpp:50:10:50:17 | indirect |
225+
| arrays.cpp:50:27:50:30 | data |
190226
| by_reference.cpp:12:5:12:5 | s |
191227
| by_reference.cpp:12:8:12:8 | a |
192228
| by_reference.cpp:16:5:16:8 | this |

0 commit comments

Comments
 (0)