Skip to content

Commit d1915c7

Browse files
committed
Swift: Add a test revealing the issue in pure dataflow.
1 parent 4585852 commit d1915c7

File tree

3 files changed

+164
-1
lines changed

3 files changed

+164
-1
lines changed

swift/ql/test/library-tests/dataflow/dataflow/DataFlow.expected

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,28 @@ edges
135135
| test2.swift:69:10:69:10 | key | test2.swift:70:19:70:19 | key | provenance | |
136136
| test2.swift:69:25:69:25 | call to makeIterator() [Collection element, Tuple element at index 0] | test2.swift:69:5:69:5 | $generator [Collection element, Tuple element at index 0] | provenance | |
137137
| test2.swift:69:25:69:25 | d4 [Collection element, Tuple element at index 0] | test2.swift:69:25:69:25 | call to makeIterator() [Collection element, Tuple element at index 0] | provenance | |
138+
| test2.swift:76:14:76:47 | [...] [Collection element] | test2.swift:82:19:82:19 | a1 [Collection element] | provenance | |
139+
| test2.swift:76:14:76:47 | [...] [Collection element] | test2.swift:84:20:84:20 | a1 [Collection element] | provenance | |
140+
| test2.swift:76:30:76:46 | call to source(_:) | test2.swift:76:14:76:47 | [...] [Collection element] | provenance | |
141+
| test2.swift:82:19:82:19 | a1 [Collection element] | test2.swift:82:19:82:24 | ...[...] | provenance | |
142+
| test2.swift:84:5:84:5 | $generator [Collection element, Tuple element at index 1] | test2.swift:84:5:84:5 | call to next() [some:0, Tuple element at index 1] | provenance | |
143+
| test2.swift:84:5:84:5 | call to next() [some:0, Tuple element at index 1] | test2.swift:84:9:84:15 | (...) [Tuple element at index 1] | provenance | |
144+
| test2.swift:84:9:84:15 | (...) [Tuple element at index 1] | test2.swift:84:14:84:14 | v | provenance | |
145+
| test2.swift:84:14:84:14 | v | test2.swift:86:19:86:19 | v | provenance | |
146+
| test2.swift:84:20:84:20 | a1 [Collection element] | test2.swift:84:20:84:34 | call to enumerated() [Collection element, Tuple element at index 1] | provenance | |
147+
| test2.swift:84:20:84:34 | call to enumerated() [Collection element, Tuple element at index 1] | test2.swift:84:20:84:34 | call to makeIterator() [Collection element, Tuple element at index 1] | provenance | |
148+
| test2.swift:84:20:84:34 | call to makeIterator() [Collection element, Tuple element at index 1] | test2.swift:84:5:84:5 | $generator [Collection element, Tuple element at index 1] | provenance | |
149+
| test2.swift:93:5:93:5 | [post] a2 [Collection element] | test2.swift:99:19:99:19 | a2 [Collection element] | provenance | |
150+
| test2.swift:93:5:93:5 | [post] a2 [Collection element] | test2.swift:101:20:101:20 | a2 [Collection element] | provenance | |
151+
| test2.swift:93:13:93:29 | call to source(_:) | test2.swift:93:5:93:5 | [post] a2 [Collection element] | provenance | |
152+
| test2.swift:99:19:99:19 | a2 [Collection element] | test2.swift:99:19:99:24 | ...[...] | provenance | |
153+
| test2.swift:101:5:101:5 | $generator [Collection element, Tuple element at index 1] | test2.swift:101:5:101:5 | call to next() [some:0, Tuple element at index 1] | provenance | |
154+
| test2.swift:101:5:101:5 | call to next() [some:0, Tuple element at index 1] | test2.swift:101:9:101:15 | (...) [Tuple element at index 1] | provenance | |
155+
| test2.swift:101:9:101:15 | (...) [Tuple element at index 1] | test2.swift:101:14:101:14 | v | provenance | |
156+
| test2.swift:101:14:101:14 | v | test2.swift:103:19:103:19 | v | provenance | |
157+
| test2.swift:101:20:101:20 | a2 [Collection element] | test2.swift:101:20:101:34 | call to enumerated() [Collection element, Tuple element at index 1] | provenance | |
158+
| test2.swift:101:20:101:34 | call to enumerated() [Collection element, Tuple element at index 1] | test2.swift:101:20:101:34 | call to makeIterator() [Collection element, Tuple element at index 1] | provenance | |
159+
| test2.swift:101:20:101:34 | call to makeIterator() [Collection element, Tuple element at index 1] | test2.swift:101:5:101:5 | $generator [Collection element, Tuple element at index 1] | provenance | |
138160
| test.swift:6:19:6:26 | call to source() | test.swift:7:15:7:15 | t1 | provenance | |
139161
| test.swift:6:19:6:26 | call to source() | test.swift:9:15:9:15 | t1 | provenance | |
140162
| test.swift:6:19:6:26 | call to source() | test.swift:10:15:10:15 | t2 | provenance | |
@@ -884,6 +906,30 @@ nodes
884906
| test2.swift:69:25:69:25 | call to makeIterator() [Collection element, Tuple element at index 0] | semmle.label | call to makeIterator() [Collection element, Tuple element at index 0] |
885907
| test2.swift:69:25:69:25 | d4 [Collection element, Tuple element at index 0] | semmle.label | d4 [Collection element, Tuple element at index 0] |
886908
| test2.swift:70:19:70:19 | key | semmle.label | key |
909+
| test2.swift:76:14:76:47 | [...] [Collection element] | semmle.label | [...] [Collection element] |
910+
| test2.swift:76:30:76:46 | call to source(_:) | semmle.label | call to source(_:) |
911+
| test2.swift:82:19:82:19 | a1 [Collection element] | semmle.label | a1 [Collection element] |
912+
| test2.swift:82:19:82:24 | ...[...] | semmle.label | ...[...] |
913+
| test2.swift:84:5:84:5 | $generator [Collection element, Tuple element at index 1] | semmle.label | $generator [Collection element, Tuple element at index 1] |
914+
| test2.swift:84:5:84:5 | call to next() [some:0, Tuple element at index 1] | semmle.label | call to next() [some:0, Tuple element at index 1] |
915+
| test2.swift:84:9:84:15 | (...) [Tuple element at index 1] | semmle.label | (...) [Tuple element at index 1] |
916+
| test2.swift:84:14:84:14 | v | semmle.label | v |
917+
| test2.swift:84:20:84:20 | a1 [Collection element] | semmle.label | a1 [Collection element] |
918+
| test2.swift:84:20:84:34 | call to enumerated() [Collection element, Tuple element at index 1] | semmle.label | call to enumerated() [Collection element, Tuple element at index 1] |
919+
| test2.swift:84:20:84:34 | call to makeIterator() [Collection element, Tuple element at index 1] | semmle.label | call to makeIterator() [Collection element, Tuple element at index 1] |
920+
| test2.swift:86:19:86:19 | v | semmle.label | v |
921+
| test2.swift:93:5:93:5 | [post] a2 [Collection element] | semmle.label | [post] a2 [Collection element] |
922+
| test2.swift:93:13:93:29 | call to source(_:) | semmle.label | call to source(_:) |
923+
| test2.swift:99:19:99:19 | a2 [Collection element] | semmle.label | a2 [Collection element] |
924+
| test2.swift:99:19:99:24 | ...[...] | semmle.label | ...[...] |
925+
| test2.swift:101:5:101:5 | $generator [Collection element, Tuple element at index 1] | semmle.label | $generator [Collection element, Tuple element at index 1] |
926+
| test2.swift:101:5:101:5 | call to next() [some:0, Tuple element at index 1] | semmle.label | call to next() [some:0, Tuple element at index 1] |
927+
| test2.swift:101:9:101:15 | (...) [Tuple element at index 1] | semmle.label | (...) [Tuple element at index 1] |
928+
| test2.swift:101:14:101:14 | v | semmle.label | v |
929+
| test2.swift:101:20:101:20 | a2 [Collection element] | semmle.label | a2 [Collection element] |
930+
| test2.swift:101:20:101:34 | call to enumerated() [Collection element, Tuple element at index 1] | semmle.label | call to enumerated() [Collection element, Tuple element at index 1] |
931+
| test2.swift:101:20:101:34 | call to makeIterator() [Collection element, Tuple element at index 1] | semmle.label | call to makeIterator() [Collection element, Tuple element at index 1] |
932+
| test2.swift:103:19:103:19 | v | semmle.label | v |
887933
| test.swift:6:19:6:26 | call to source() | semmle.label | call to source() |
888934
| test.swift:7:15:7:15 | t1 | semmle.label | t1 |
889935
| test.swift:9:15:9:15 | t1 | semmle.label | t1 |
@@ -1615,6 +1661,10 @@ subpaths
16151661
| test2.swift:53:15:53:28 | ... ??(_:_:) ... | test2.swift:46:17:46:33 | call to source(_:) | test2.swift:53:15:53:28 | ... ??(_:_:) ... | result |
16161662
| test2.swift:54:15:54:24 | ...! | test2.swift:46:17:46:33 | call to source(_:) | test2.swift:54:15:54:24 | ...! | result |
16171663
| test2.swift:70:19:70:19 | key | test2.swift:60:8:60:24 | call to source(_:) | test2.swift:70:19:70:19 | key | result |
1664+
| test2.swift:82:19:82:24 | ...[...] | test2.swift:76:30:76:46 | call to source(_:) | test2.swift:82:19:82:24 | ...[...] | result |
1665+
| test2.swift:86:19:86:19 | v | test2.swift:76:30:76:46 | call to source(_:) | test2.swift:86:19:86:19 | v | result |
1666+
| test2.swift:99:19:99:24 | ...[...] | test2.swift:93:13:93:29 | call to source(_:) | test2.swift:99:19:99:24 | ...[...] | result |
1667+
| test2.swift:103:19:103:19 | v | test2.swift:93:13:93:29 | call to source(_:) | test2.swift:103:19:103:19 | v | result |
16181668
| test.swift:7:15:7:15 | t1 | test.swift:6:19:6:26 | call to source() | test.swift:7:15:7:15 | t1 | result |
16191669
| test.swift:9:15:9:15 | t1 | test.swift:6:19:6:26 | call to source() | test.swift:9:15:9:15 | t1 | result |
16201670
| test.swift:10:15:10:15 | t2 | test.swift:6:19:6:26 | call to source() | test.swift:10:15:10:15 | t2 | result |

swift/ql/test/library-tests/dataflow/dataflow/LocalFlow.expected

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,87 @@
161161
| test2.swift:69:25:69:25 | $generator | test2.swift:69:25:69:25 | SSA def($generator) |
162162
| test2.swift:69:25:69:25 | SSA def($generator) | test2.swift:69:5:69:5 | $generator |
163163
| test2.swift:69:25:69:25 | call to makeIterator() | test2.swift:69:25:69:25 | $generator |
164+
| test2.swift:76:9:76:9 | SSA def(a1) | test2.swift:78:14:78:14 | a1 |
165+
| test2.swift:76:9:76:9 | a1 | test2.swift:76:9:76:9 | SSA def(a1) |
166+
| test2.swift:76:14:76:47 | [...] | test2.swift:76:9:76:9 | a1 |
167+
| test2.swift:78:5:78:5 | $v$generator | test2.swift:78:5:78:5 | &... |
168+
| test2.swift:78:5:78:5 | &... | test2.swift:78:5:78:5 | $v$generator |
169+
| test2.swift:78:5:78:5 | [post] $v$generator | test2.swift:78:5:78:5 | &... |
170+
| test2.swift:78:9:78:9 | SSA def(v) | test2.swift:79:19:79:19 | v |
171+
| test2.swift:78:9:78:9 | v | test2.swift:78:9:78:9 | SSA def(v) |
172+
| test2.swift:78:14:78:14 | $v$generator | test2.swift:78:14:78:14 | SSA def($v$generator) |
173+
| test2.swift:78:14:78:14 | SSA def($v$generator) | test2.swift:78:5:78:5 | $v$generator |
174+
| test2.swift:78:14:78:14 | [post] a1 | test2.swift:81:21:81:21 | a1 |
175+
| test2.swift:78:14:78:14 | a1 | test2.swift:81:21:81:21 | a1 |
176+
| test2.swift:78:14:78:14 | call to makeIterator() | test2.swift:78:14:78:14 | $v$generator |
177+
| test2.swift:81:5:81:5 | $ix$generator | test2.swift:81:5:81:5 | &... |
178+
| test2.swift:81:5:81:5 | &... | test2.swift:81:5:81:5 | $ix$generator |
179+
| test2.swift:81:5:81:5 | [post] $ix$generator | test2.swift:81:5:81:5 | &... |
180+
| test2.swift:81:9:81:9 | SSA def(ix) | test2.swift:82:22:82:22 | ix |
181+
| test2.swift:81:9:81:9 | ix | test2.swift:81:9:81:9 | SSA def(ix) |
182+
| test2.swift:81:15:81:15 | $ix$generator | test2.swift:81:15:81:15 | SSA def($ix$generator) |
183+
| test2.swift:81:15:81:15 | SSA def($ix$generator) | test2.swift:81:5:81:5 | $ix$generator |
184+
| test2.swift:81:15:81:24 | call to makeIterator() | test2.swift:81:15:81:15 | $ix$generator |
185+
| test2.swift:81:21:81:21 | [post] a1 | test2.swift:82:19:82:19 | a1 |
186+
| test2.swift:81:21:81:21 | [post] a1 | test2.swift:84:20:84:20 | a1 |
187+
| test2.swift:81:21:81:21 | a1 | test2.swift:82:19:82:19 | a1 |
188+
| test2.swift:81:21:81:21 | a1 | test2.swift:84:20:84:20 | a1 |
189+
| test2.swift:82:19:82:19 | &... | test2.swift:82:19:82:19 | a1 |
190+
| test2.swift:82:19:82:19 | &... | test2.swift:84:20:84:20 | a1 |
191+
| test2.swift:82:19:82:19 | [post] a1 | test2.swift:82:19:82:19 | &... |
192+
| test2.swift:82:19:82:19 | a1 | test2.swift:82:19:82:19 | &... |
193+
| test2.swift:84:5:84:5 | $generator | test2.swift:84:5:84:5 | &... |
194+
| test2.swift:84:5:84:5 | &... | test2.swift:84:5:84:5 | $generator |
195+
| test2.swift:84:5:84:5 | [post] $generator | test2.swift:84:5:84:5 | &... |
196+
| test2.swift:84:10:84:10 | SSA def(ix) | test2.swift:85:19:85:19 | ix |
197+
| test2.swift:84:10:84:10 | ix | test2.swift:84:10:84:10 | SSA def(ix) |
198+
| test2.swift:84:14:84:14 | SSA def(v) | test2.swift:86:19:86:19 | v |
199+
| test2.swift:84:14:84:14 | v | test2.swift:84:14:84:14 | SSA def(v) |
200+
| test2.swift:84:20:84:20 | $generator | test2.swift:84:20:84:20 | SSA def($generator) |
201+
| test2.swift:84:20:84:20 | SSA def($generator) | test2.swift:84:5:84:5 | $generator |
202+
| test2.swift:84:20:84:34 | call to makeIterator() | test2.swift:84:20:84:20 | $generator |
203+
| test2.swift:91:9:91:9 | SSA def(a2) | test2.swift:93:5:93:5 | a2 |
204+
| test2.swift:91:9:91:9 | a2 | test2.swift:91:9:91:9 | SSA def(a2) |
205+
| test2.swift:91:14:91:33 | [...] | test2.swift:91:9:91:9 | a2 |
206+
| test2.swift:93:5:93:5 | &... | test2.swift:95:14:95:14 | a2 |
207+
| test2.swift:93:5:93:5 | [post] a2 | test2.swift:93:5:93:5 | &... |
208+
| test2.swift:93:5:93:5 | a2 | test2.swift:93:5:93:5 | &... |
209+
| test2.swift:95:5:95:5 | $v$generator | test2.swift:95:5:95:5 | &... |
210+
| test2.swift:95:5:95:5 | &... | test2.swift:95:5:95:5 | $v$generator |
211+
| test2.swift:95:5:95:5 | [post] $v$generator | test2.swift:95:5:95:5 | &... |
212+
| test2.swift:95:9:95:9 | SSA def(v) | test2.swift:96:19:96:19 | v |
213+
| test2.swift:95:9:95:9 | v | test2.swift:95:9:95:9 | SSA def(v) |
214+
| test2.swift:95:14:95:14 | $v$generator | test2.swift:95:14:95:14 | SSA def($v$generator) |
215+
| test2.swift:95:14:95:14 | SSA def($v$generator) | test2.swift:95:5:95:5 | $v$generator |
216+
| test2.swift:95:14:95:14 | [post] a2 | test2.swift:98:21:98:21 | a2 |
217+
| test2.swift:95:14:95:14 | a2 | test2.swift:98:21:98:21 | a2 |
218+
| test2.swift:95:14:95:14 | call to makeIterator() | test2.swift:95:14:95:14 | $v$generator |
219+
| test2.swift:98:5:98:5 | $ix$generator | test2.swift:98:5:98:5 | &... |
220+
| test2.swift:98:5:98:5 | &... | test2.swift:98:5:98:5 | $ix$generator |
221+
| test2.swift:98:5:98:5 | [post] $ix$generator | test2.swift:98:5:98:5 | &... |
222+
| test2.swift:98:9:98:9 | SSA def(ix) | test2.swift:99:22:99:22 | ix |
223+
| test2.swift:98:9:98:9 | ix | test2.swift:98:9:98:9 | SSA def(ix) |
224+
| test2.swift:98:15:98:15 | $ix$generator | test2.swift:98:15:98:15 | SSA def($ix$generator) |
225+
| test2.swift:98:15:98:15 | SSA def($ix$generator) | test2.swift:98:5:98:5 | $ix$generator |
226+
| test2.swift:98:15:98:24 | call to makeIterator() | test2.swift:98:15:98:15 | $ix$generator |
227+
| test2.swift:98:21:98:21 | [post] a2 | test2.swift:99:19:99:19 | a2 |
228+
| test2.swift:98:21:98:21 | [post] a2 | test2.swift:101:20:101:20 | a2 |
229+
| test2.swift:98:21:98:21 | a2 | test2.swift:99:19:99:19 | a2 |
230+
| test2.swift:98:21:98:21 | a2 | test2.swift:101:20:101:20 | a2 |
231+
| test2.swift:99:19:99:19 | &... | test2.swift:99:19:99:19 | a2 |
232+
| test2.swift:99:19:99:19 | &... | test2.swift:101:20:101:20 | a2 |
233+
| test2.swift:99:19:99:19 | [post] a2 | test2.swift:99:19:99:19 | &... |
234+
| test2.swift:99:19:99:19 | a2 | test2.swift:99:19:99:19 | &... |
235+
| test2.swift:101:5:101:5 | $generator | test2.swift:101:5:101:5 | &... |
236+
| test2.swift:101:5:101:5 | &... | test2.swift:101:5:101:5 | $generator |
237+
| test2.swift:101:5:101:5 | [post] $generator | test2.swift:101:5:101:5 | &... |
238+
| test2.swift:101:10:101:10 | SSA def(ix) | test2.swift:102:19:102:19 | ix |
239+
| test2.swift:101:10:101:10 | ix | test2.swift:101:10:101:10 | SSA def(ix) |
240+
| test2.swift:101:14:101:14 | SSA def(v) | test2.swift:103:19:103:19 | v |
241+
| test2.swift:101:14:101:14 | v | test2.swift:101:14:101:14 | SSA def(v) |
242+
| test2.swift:101:20:101:20 | $generator | test2.swift:101:20:101:20 | SSA def($generator) |
243+
| test2.swift:101:20:101:20 | SSA def($generator) | test2.swift:101:5:101:5 | $generator |
244+
| test2.swift:101:20:101:34 | call to makeIterator() | test2.swift:101:20:101:20 | $generator |
164245
| test.swift:5:9:5:13 | ... as ... | test.swift:5:9:5:9 | t2 |
165246
| test.swift:6:9:6:9 | SSA def(t1) | test.swift:7:15:7:15 | t1 |
166247
| test.swift:6:9:6:9 | t1 | test.swift:6:9:6:9 | SSA def(t1) |

swift/ql/test/library-tests/dataflow/dataflow/test2.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
func source(_ label: String) -> String { return ""; }
2-
func sink(arg: String) {}
2+
func sink<T>(arg: T) {}
33

44
func testDicts() {
55
let d1 = ["a": "apple", "b": "banana", "c": source("source1")]
@@ -71,3 +71,35 @@ func testDicts4() {
7171
sink(arg: value)
7272
}
7373
}
74+
75+
func testArrays1() {
76+
var a1 = ["a", "b", "c", source("source5")]
77+
78+
for v in a1 {
79+
sink(arg: v) // $ MISSING: flow=source5
80+
}
81+
for ix in 0 ..< a1.count {
82+
sink(arg: a1[ix]) // $ flow=source5
83+
}
84+
for (ix, v) in a1.enumerated() {
85+
sink(arg: ix)
86+
sink(arg: v) // $ flow=source5
87+
}
88+
}
89+
90+
func testArrays2() {
91+
var a2 = ["a", "b", "c", "d"]
92+
93+
a2[1] = source("source6")
94+
95+
for v in a2 {
96+
sink(arg: v) // $ MISSING: flow=source6
97+
}
98+
for ix in 0 ..< a2.count {
99+
sink(arg: a2[ix]) // $ flow=source6
100+
}
101+
for (ix, v) in a2.enumerated() {
102+
sink(arg: ix)
103+
sink(arg: v) // $ flow=source6
104+
}
105+
}

0 commit comments

Comments
 (0)