Skip to content

Commit 9e96d61

Browse files
authored
Merge pull request #12096 from MathiasVP/recognize-more-iterators
C++: Teach iterator flow about `std::back_inserter`
2 parents 77250af + 316eecc commit 9e96d61

File tree

3 files changed

+18
-73
lines changed

3 files changed

+18
-73
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternalsCommon.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ cached
463463
private module Cached {
464464
private import semmle.code.cpp.models.interfaces.Iterator as Interfaces
465465
private import semmle.code.cpp.models.implementations.Iterator as Iterator
466+
private import semmle.code.cpp.models.interfaces.FunctionInputsAndOutputs as IO
466467

467468
/**
468469
* Holds if `next` is a instruction with a memory result that potentially
@@ -593,11 +594,16 @@ private module Cached {
593594
private predicate isChiAfterBegin(
594595
BaseSourceVariableInstruction containerBase, StoreInstruction iterator
595596
) {
596-
exists(CallInstruction getIterator |
597+
exists(
598+
CallInstruction getIterator, Iterator::GetIteratorFunction getIteratorFunction,
599+
IO::FunctionInput input, int i
600+
|
597601
getIterator = iterator.getSourceValue() and
598-
getIterator.getStaticCallTarget() instanceof Iterator::GetIteratorFunction and
602+
getIteratorFunction = getIterator.getStaticCallTarget() and
603+
getIteratorFunction.getsIterator(input, _) and
599604
isDef(_, any(Node0Impl n | n.asInstruction() = iterator), _, _, 1, 0) and
600-
isUse(_, getIterator.getThisArgumentOperand(), containerBase, 0, 0)
605+
input.isParameterDerefOrQualifierObject(i) and
606+
isUse(_, getIterator.getArgumentOperand(i), containerBase, 0, 0)
601607
)
602608
}
603609

cpp/ql/test/library-tests/dataflow/taint-tests/vector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,14 @@ void test_vector_inserter(char *source_string) {
426426
std::vector<std::string> out;
427427
auto it = std::back_inserter(out);
428428
*it++ = std::string(source_string);
429-
sink(out); // $ ast MISSING: ir
429+
sink(out); // $ ast,ir
430430
}
431431

432432
{
433433
std::vector<int> out;
434434
auto it = std::back_inserter(out);
435435
*it++ = source();
436-
sink(out); // $ ast MISSING: ir
436+
sink(out); // $ ast,ir
437437
}
438438

439439
{

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

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,13 @@ uniqueNodeLocation
1717
| break_labels.c:2:11:2:11 | i | Node should have one location but has 4. |
1818
| break_labels.c:2:11:2:11 | i | Node should have one location but has 4. |
1919
| break_labels.c:2:11:2:11 | i | Node should have one location but has 4. |
20-
| break_labels.c:2:11:2:11 | i | Node should have one location but has 4. |
2120
| break_labels.c:2:11:2:11 | i indirection | Node should have one location but has 4. |
2221
| break_labels.c:2:11:2:11 | i indirection | Node should have one location but has 4. |
2322
| break_labels.c:2:11:2:11 | x | Node should have one location but has 4. |
2423
| break_labels.c:2:11:2:11 | x | Node should have one location but has 4. |
2524
| break_labels.c:2:11:2:11 | x | Node should have one location but has 4. |
26-
| break_labels.c:2:11:2:11 | x | Node should have one location but has 4. |
2725
| break_labels.c:2:11:2:11 | x indirection | Node should have one location but has 4. |
2826
| break_labels.c:2:11:2:11 | x indirection | Node should have one location but has 4. |
29-
| constmemberaccess.cpp:3:7:3:7 | x | Node should have one location but has 2. |
30-
| constructorinitializer.cpp:3:9:3:9 | i | Node should have one location but has 2. |
31-
| constructorinitializer.cpp:3:9:3:9 | x | Node should have one location but has 2. |
32-
| constructorinitializer.cpp:3:16:3:16 | j | Node should have one location but has 2. |
33-
| constructorinitializer.cpp:3:16:3:16 | y | Node should have one location but has 2. |
34-
| duff.c:2:12:2:12 | i | Node should have one location but has 4. |
3527
| duff.c:2:12:2:12 | i | Node should have one location but has 4. |
3628
| duff.c:2:12:2:12 | i | Node should have one location but has 4. |
3729
| duff.c:2:12:2:12 | i | Node should have one location but has 4. |
@@ -40,32 +32,8 @@ uniqueNodeLocation
4032
| duff.c:2:12:2:12 | x | Node should have one location but has 4. |
4133
| duff.c:2:12:2:12 | x | Node should have one location but has 4. |
4234
| duff.c:2:12:2:12 | x | Node should have one location but has 4. |
43-
| duff.c:2:12:2:12 | x | Node should have one location but has 4. |
4435
| duff.c:2:12:2:12 | x indirection | Node should have one location but has 4. |
4536
| duff.c:2:12:2:12 | x indirection | Node should have one location but has 4. |
46-
| fieldaccess.cpp:3:7:3:7 | x | Node should have one location but has 2. |
47-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
48-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
49-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
50-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
51-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
52-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
53-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
54-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
55-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
56-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
57-
| file://:0:0:0:0 | (unnamed parameter 0) | Node should have one location but has 0. |
58-
| file://:0:0:0:0 | (unnamed parameter 1) | Node should have one location but has 0. |
59-
| file://:0:0:0:0 | (unnamed parameter 1) | Node should have one location but has 0. |
60-
| file://:0:0:0:0 | (unnamed parameter 1) | Node should have one location but has 0. |
61-
| file://:0:0:0:0 | (unnamed parameter 1) | Node should have one location but has 0. |
62-
| file://:0:0:0:0 | (unnamed parameter 1) | Node should have one location but has 0. |
63-
| file://:0:0:0:0 | (unnamed parameter 1) | Node should have one location but has 0. |
64-
| file://:0:0:0:0 | (unnamed parameter 1) | Node should have one location but has 0. |
65-
| file://:0:0:0:0 | (unnamed parameter 1) | Node should have one location but has 0. |
66-
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
67-
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
68-
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
6937
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
7038
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
7139
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
@@ -78,8 +46,6 @@ uniqueNodeLocation
7846
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
7947
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
8048
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
81-
| file://:0:0:0:0 | (unnamed parameter 3) | Node should have one location but has 0. |
82-
| ifelsestmt.c:37:17:37:17 | x | Node should have one location but has 2. |
8349
| ifelsestmt.c:37:17:37:17 | x | Node should have one location but has 2. |
8450
| ifelsestmt.c:37:17:37:17 | x | Node should have one location but has 2. |
8551
| ifelsestmt.c:37:17:37:17 | x | Node should have one location but has 2. |
@@ -88,28 +54,18 @@ uniqueNodeLocation
8854
| ifelsestmt.c:37:24:37:24 | y | Node should have one location but has 2. |
8955
| ifelsestmt.c:37:24:37:24 | y | Node should have one location but has 2. |
9056
| ifelsestmt.c:37:24:37:24 | y | Node should have one location but has 2. |
91-
| ifelsestmt.c:37:24:37:24 | y | Node should have one location but has 2. |
9257
| ifelsestmt.c:37:24:37:24 | y indirection | Node should have one location but has 2. |
9358
| ifelsestmt.c:37:24:37:24 | y indirection | Node should have one location but has 2. |
9459
| ifstmt.c:27:17:27:17 | x | Node should have one location but has 2. |
9560
| ifstmt.c:27:17:27:17 | x | Node should have one location but has 2. |
9661
| ifstmt.c:27:17:27:17 | x | Node should have one location but has 2. |
97-
| ifstmt.c:27:17:27:17 | x | Node should have one location but has 2. |
9862
| ifstmt.c:27:17:27:17 | x indirection | Node should have one location but has 2. |
9963
| ifstmt.c:27:17:27:17 | x indirection | Node should have one location but has 2. |
10064
| ifstmt.c:27:24:27:24 | y | Node should have one location but has 2. |
10165
| ifstmt.c:27:24:27:24 | y | Node should have one location but has 2. |
10266
| ifstmt.c:27:24:27:24 | y | Node should have one location but has 2. |
103-
| ifstmt.c:27:24:27:24 | y | Node should have one location but has 2. |
10467
| ifstmt.c:27:24:27:24 | y indirection | Node should have one location but has 2. |
10568
| ifstmt.c:27:24:27:24 | y indirection | Node should have one location but has 2. |
106-
| membercallexpr_args.cpp:3:6:3:6 | d | Node should have one location but has 2. |
107-
| membercallexpr_args.cpp:4:14:4:14 | x | Node should have one location but has 2. |
108-
| membercallexpr_args.cpp:4:21:4:21 | y | Node should have one location but has 2. |
109-
| newexpr.cpp:3:9:3:9 | i | Node should have one location but has 2. |
110-
| newexpr.cpp:3:9:3:9 | x | Node should have one location but has 2. |
111-
| newexpr.cpp:3:16:3:16 | j | Node should have one location but has 2. |
112-
| newexpr.cpp:3:16:3:16 | y | Node should have one location but has 2. |
11369
| no_dynamic_init.cpp:9:5:9:8 | Phi | Node should have one location but has 4. |
11470
| no_dynamic_init.cpp:9:5:9:8 | main | Node should have one location but has 4. |
11571
| no_dynamic_init.cpp:9:5:9:8 | main | Node should have one location but has 4. |
@@ -118,23 +74,18 @@ uniqueNodeLocation
11874
| nodefaultswitchstmt.c:1:12:1:12 | i | Node should have one location but has 4. |
11975
| nodefaultswitchstmt.c:1:12:1:12 | i | Node should have one location but has 4. |
12076
| nodefaultswitchstmt.c:1:12:1:12 | i | Node should have one location but has 4. |
121-
| nodefaultswitchstmt.c:1:12:1:12 | i | Node should have one location but has 4. |
12277
| nodefaultswitchstmt.c:1:12:1:12 | i indirection | Node should have one location but has 4. |
12378
| nodefaultswitchstmt.c:1:12:1:12 | i indirection | Node should have one location but has 4. |
12479
| nodefaultswitchstmt.c:1:12:1:12 | x | Node should have one location but has 4. |
12580
| nodefaultswitchstmt.c:1:12:1:12 | x | Node should have one location but has 4. |
12681
| nodefaultswitchstmt.c:1:12:1:12 | x | Node should have one location but has 4. |
127-
| nodefaultswitchstmt.c:1:12:1:12 | x | Node should have one location but has 4. |
12882
| nodefaultswitchstmt.c:1:12:1:12 | x indirection | Node should have one location but has 4. |
12983
| nodefaultswitchstmt.c:1:12:1:12 | x indirection | Node should have one location but has 4. |
13084
| parameterinitializer.cpp:18:5:18:8 | Phi | Node should have one location but has 4. |
13185
| parameterinitializer.cpp:18:5:18:8 | main | Node should have one location but has 4. |
13286
| parameterinitializer.cpp:18:5:18:8 | main | Node should have one location but has 4. |
13387
| parameterinitializer.cpp:18:5:18:8 | main indirection | Node should have one location but has 4. |
13488
| parameterinitializer.cpp:18:5:18:8 | main indirection | Node should have one location but has 4. |
135-
| staticmembercallexpr_args.cpp:3:6:3:6 | d | Node should have one location but has 2. |
136-
| staticmembercallexpr_args.cpp:4:21:4:21 | x | Node should have one location but has 2. |
137-
| staticmembercallexpr_args.cpp:4:28:4:28 | y | Node should have one location but has 2. |
13889
| stream_it.cpp:16:5:16:8 | Phi | Node should have one location but has 4. |
13990
| stream_it.cpp:16:5:16:8 | main | Node should have one location but has 4. |
14091
| stream_it.cpp:16:5:16:8 | main | Node should have one location but has 4. |
@@ -143,28 +94,24 @@ uniqueNodeLocation
14394
| switchstmt.c:1:12:1:12 | i | Node should have one location but has 4. |
14495
| switchstmt.c:1:12:1:12 | i | Node should have one location but has 4. |
14596
| switchstmt.c:1:12:1:12 | i | Node should have one location but has 4. |
146-
| switchstmt.c:1:12:1:12 | i | Node should have one location but has 4. |
14797
| switchstmt.c:1:12:1:12 | i indirection | Node should have one location but has 4. |
14898
| switchstmt.c:1:12:1:12 | i indirection | Node should have one location but has 4. |
14999
| switchstmt.c:1:12:1:12 | x | Node should have one location but has 4. |
150100
| switchstmt.c:1:12:1:12 | x | Node should have one location but has 4. |
151101
| switchstmt.c:1:12:1:12 | x | Node should have one location but has 4. |
152-
| switchstmt.c:1:12:1:12 | x | Node should have one location but has 4. |
153102
| switchstmt.c:1:12:1:12 | x indirection | Node should have one location but has 4. |
154103
| switchstmt.c:1:12:1:12 | x indirection | Node should have one location but has 4. |
155104
missingLocation
156-
| Nodes without location: 35 |
105+
| Nodes without location: 12 |
157106
uniqueNodeToString
158107
| break_labels.c:2:11:2:11 | i | Node should have one toString but has 2. |
159108
| break_labels.c:2:11:2:11 | i | Node should have one toString but has 2. |
160109
| break_labels.c:2:11:2:11 | i | Node should have one toString but has 2. |
161-
| break_labels.c:2:11:2:11 | i | Node should have one toString but has 2. |
162110
| break_labels.c:2:11:2:11 | i indirection | Node should have one toString but has 2. |
163111
| break_labels.c:2:11:2:11 | i indirection | Node should have one toString but has 2. |
164112
| break_labels.c:2:11:2:11 | x | Node should have one toString but has 2. |
165113
| break_labels.c:2:11:2:11 | x | Node should have one toString but has 2. |
166114
| break_labels.c:2:11:2:11 | x | Node should have one toString but has 2. |
167-
| break_labels.c:2:11:2:11 | x | Node should have one toString but has 2. |
168115
| break_labels.c:2:11:2:11 | x indirection | Node should have one toString but has 2. |
169116
| break_labels.c:2:11:2:11 | x indirection | Node should have one toString but has 2. |
170117
| break_labels.c:4:9:4:9 | i | Node should have one toString but has 2. |
@@ -199,11 +146,6 @@ uniqueNodeToString
199146
| break_labels.c:7:17:7:17 | x | Node should have one toString but has 2. |
200147
| break_labels.c:7:17:7:17 | x indirection | Node should have one toString but has 2. |
201148
| break_labels.c:7:17:7:17 | x indirection | Node should have one toString but has 2. |
202-
| constructorinitializer.cpp:3:9:3:9 | i | Node should have one toString but has 2. |
203-
| constructorinitializer.cpp:3:9:3:9 | x | Node should have one toString but has 2. |
204-
| constructorinitializer.cpp:3:16:3:16 | j | Node should have one toString but has 2. |
205-
| constructorinitializer.cpp:3:16:3:16 | y | Node should have one toString but has 2. |
206-
| duff.c:2:12:2:12 | i | Node should have one toString but has 2. |
207149
| duff.c:2:12:2:12 | i | Node should have one toString but has 2. |
208150
| duff.c:2:12:2:12 | i | Node should have one toString but has 2. |
209151
| duff.c:2:12:2:12 | i | Node should have one toString but has 2. |
@@ -212,7 +154,6 @@ uniqueNodeToString
212154
| duff.c:2:12:2:12 | x | Node should have one toString but has 2. |
213155
| duff.c:2:12:2:12 | x | Node should have one toString but has 2. |
214156
| duff.c:2:12:2:12 | x | Node should have one toString but has 2. |
215-
| duff.c:2:12:2:12 | x | Node should have one toString but has 2. |
216157
| duff.c:2:12:2:12 | x indirection | Node should have one toString but has 2. |
217158
| duff.c:2:12:2:12 | x indirection | Node should have one toString but has 2. |
218159
| duff.c:3:14:3:14 | i | Node should have one toString but has 2. |
@@ -231,11 +172,12 @@ uniqueNodeToString
231172
| duff.c:4:13:4:13 | x | Node should have one toString but has 2. |
232173
| duff.c:4:13:4:13 | x | Node should have one toString but has 2. |
233174
| duff.c:4:13:4:13 | x | Node should have one toString but has 2. |
234-
| newexpr.cpp:3:9:3:9 | i | Node should have one toString but has 2. |
235-
| newexpr.cpp:3:9:3:9 | x | Node should have one toString but has 2. |
236-
| newexpr.cpp:3:16:3:16 | j | Node should have one toString but has 2. |
237-
| newexpr.cpp:3:16:3:16 | y | Node should have one toString but has 2. |
238-
| nodefaultswitchstmt.c:1:12:1:12 | i | Node should have one toString but has 2. |
175+
| file://:0:0:0:0 | i | Node should have one toString but has 2. |
176+
| file://:0:0:0:0 | i | Node should have one toString but has 2. |
177+
| file://:0:0:0:0 | j | Node should have one toString but has 2. |
178+
| file://:0:0:0:0 | x | Node should have one toString but has 2. |
179+
| file://:0:0:0:0 | x | Node should have one toString but has 2. |
180+
| file://:0:0:0:0 | y | Node should have one toString but has 2. |
239181
| nodefaultswitchstmt.c:1:12:1:12 | i | Node should have one toString but has 2. |
240182
| nodefaultswitchstmt.c:1:12:1:12 | i | Node should have one toString but has 2. |
241183
| nodefaultswitchstmt.c:1:12:1:12 | i | Node should have one toString but has 2. |
@@ -244,7 +186,6 @@ uniqueNodeToString
244186
| nodefaultswitchstmt.c:1:12:1:12 | x | Node should have one toString but has 2. |
245187
| nodefaultswitchstmt.c:1:12:1:12 | x | Node should have one toString but has 2. |
246188
| nodefaultswitchstmt.c:1:12:1:12 | x | Node should have one toString but has 2. |
247-
| nodefaultswitchstmt.c:1:12:1:12 | x | Node should have one toString but has 2. |
248189
| nodefaultswitchstmt.c:1:12:1:12 | x indirection | Node should have one toString but has 2. |
249190
| nodefaultswitchstmt.c:1:12:1:12 | x indirection | Node should have one toString but has 2. |
250191
| nodefaultswitchstmt.c:2:14:2:14 | i | Node should have one toString but has 2. |
@@ -258,13 +199,11 @@ uniqueNodeToString
258199
| switchstmt.c:1:12:1:12 | i | Node should have one toString but has 2. |
259200
| switchstmt.c:1:12:1:12 | i | Node should have one toString but has 2. |
260201
| switchstmt.c:1:12:1:12 | i | Node should have one toString but has 2. |
261-
| switchstmt.c:1:12:1:12 | i | Node should have one toString but has 2. |
262202
| switchstmt.c:1:12:1:12 | i indirection | Node should have one toString but has 2. |
263203
| switchstmt.c:1:12:1:12 | i indirection | Node should have one toString but has 2. |
264204
| switchstmt.c:1:12:1:12 | x | Node should have one toString but has 2. |
265205
| switchstmt.c:1:12:1:12 | x | Node should have one toString but has 2. |
266206
| switchstmt.c:1:12:1:12 | x | Node should have one toString but has 2. |
267-
| switchstmt.c:1:12:1:12 | x | Node should have one toString but has 2. |
268207
| switchstmt.c:1:12:1:12 | x indirection | Node should have one toString but has 2. |
269208
| switchstmt.c:1:12:1:12 | x indirection | Node should have one toString but has 2. |
270209
| switchstmt.c:2:14:2:14 | i | Node should have one toString but has 2. |

0 commit comments

Comments
 (0)