Skip to content

Commit 4e54837

Browse files
committed
Swift: Add a test case we're discussing.
1 parent bb50a99 commit 4e54837

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ edges
100100
| test.swift:225:14:225:21 | call to source() : | test.swift:235:13:235:15 | .source_value |
101101
| test.swift:225:14:225:21 | call to source() : | test.swift:238:13:238:15 | .source_value |
102102
| test.swift:259:12:259:19 | call to source() : | test.swift:263:13:263:28 | call to optionalSource() : |
103-
| test.swift:259:12:259:19 | call to source() : | test.swift:437:13:437:28 | call to optionalSource() : |
103+
| test.swift:259:12:259:19 | call to source() : | test.swift:439:13:439:28 | call to optionalSource() : |
104104
| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:265:15:265:15 | x |
105105
| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:267:15:267:16 | ...! |
106106
| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:271:15:271:16 | ...? : |
@@ -141,7 +141,9 @@ edges
141141
| test.swift:357:15:357:15 | t1 [Tuple element at index 1] : | test.swift:357:15:357:18 | .1 |
142142
| test.swift:360:15:360:15 | t2 [Tuple element at index 0] : | test.swift:360:15:360:18 | .0 |
143143
| test.swift:361:15:361:15 | t2 [Tuple element at index 1] : | test.swift:361:15:361:18 | .1 |
144-
| test.swift:437:13:437:28 | call to optionalSource() : | test.swift:440:19:440:19 | a |
144+
| test.swift:439:13:439:28 | call to optionalSource() : | test.swift:442:19:442:19 | a |
145+
| test.swift:455:21:455:29 | call to source2() : | test.swift:456:19:456:19 | x |
146+
| test.swift:455:21:455:29 | call to source2() : | test.swift:457:19:457:19 | y |
145147
nodes
146148
| file://:0:0:0:0 | .a [x] : | semmle.label | .a [x] : |
147149
| file://:0:0:0:0 | .x : | semmle.label | .x : |
@@ -298,8 +300,11 @@ nodes
298300
| test.swift:360:15:360:18 | .0 | semmle.label | .0 |
299301
| test.swift:361:15:361:15 | t2 [Tuple element at index 1] : | semmle.label | t2 [Tuple element at index 1] : |
300302
| test.swift:361:15:361:18 | .1 | semmle.label | .1 |
301-
| test.swift:437:13:437:28 | call to optionalSource() : | semmle.label | call to optionalSource() : |
302-
| test.swift:440:19:440:19 | a | semmle.label | a |
303+
| test.swift:439:13:439:28 | call to optionalSource() : | semmle.label | call to optionalSource() : |
304+
| test.swift:442:19:442:19 | a | semmle.label | a |
305+
| test.swift:455:21:455:29 | call to source2() : | semmle.label | call to source2() : |
306+
| test.swift:456:19:456:19 | x | semmle.label | x |
307+
| test.swift:457:19:457:19 | y | semmle.label | y |
303308
subpaths
304309
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : | test.swift:65:1:70:1 | arg2[return] : | test.swift:75:31:75:32 | [post] &... : |
305310
| test.swift:114:19:114:19 | arg : | test.swift:109:9:109:14 | arg : | test.swift:110:12:110:12 | arg : | test.swift:114:12:114:22 | call to ... : |
@@ -380,4 +385,6 @@ subpaths
380385
| test.swift:357:15:357:18 | .1 | test.swift:351:31:351:38 | call to source() : | test.swift:357:15:357:18 | .1 | result |
381386
| test.swift:360:15:360:18 | .0 | test.swift:351:18:351:25 | call to source() : | test.swift:360:15:360:18 | .0 | result |
382387
| test.swift:361:15:361:18 | .1 | test.swift:351:31:351:38 | call to source() : | test.swift:361:15:361:18 | .1 | result |
383-
| test.swift:440:19:440:19 | a | test.swift:259:12:259:19 | call to source() : | test.swift:440:19:440:19 | a | result |
388+
| test.swift:442:19:442:19 | a | test.swift:259:12:259:19 | call to source() : | test.swift:442:19:442:19 | a | result |
389+
| test.swift:456:19:456:19 | x | test.swift:455:21:455:29 | call to source2() : | test.swift:456:19:456:19 | x | result |
390+
| test.swift:457:19:457:19 | y | test.swift:455:21:455:29 | call to source2() : | test.swift:457:19:457:19 | y | result |

swift/ql/test/library-tests/dataflow/dataflow/FlowConfig.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TestConfiguration extends DataFlow::Configuration {
1010
TestConfiguration() { this = "TestConfiguration" }
1111

1212
override predicate isSource(DataFlow::Node src) {
13-
src.asExpr().(CallExpr).getStaticTarget().getName() = "source()"
13+
src.asExpr().(CallExpr).getStaticTarget().getName().matches("source%()")
1414
}
1515

1616
override predicate isSink(DataFlow::Node sink) {

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,22 @@
355355
| test.swift:430:13:430:33 | SSA def(y) | test.swift:432:19:432:19 | y |
356356
| test.swift:430:37:430:37 | a | test.swift:430:13:430:33 | SSA def(x) |
357357
| test.swift:430:37:430:37 | a | test.swift:430:13:430:33 | SSA def(y) |
358-
| test.swift:436:21:436:27 | SSA def(y) | test.swift:439:27:439:27 | y |
359-
| test.swift:436:21:436:27 | SSA def(y) | test.swift:444:22:444:22 | y |
360-
| test.swift:436:21:436:27 | y | test.swift:436:21:436:27 | SSA def(y) |
361-
| test.swift:437:9:437:9 | SSA def(x) | test.swift:439:16:439:16 | x |
362-
| test.swift:437:13:437:28 | call to optionalSource() | test.swift:437:9:437:9 | SSA def(x) |
363-
| test.swift:439:8:439:12 | SSA def(a) | test.swift:440:19:440:19 | a |
364-
| test.swift:439:16:439:16 | x | test.swift:439:8:439:12 | SSA def(a) |
365-
| test.swift:439:16:439:16 | x | test.swift:444:19:444:19 | x |
366-
| test.swift:439:19:439:23 | SSA def(b) | test.swift:441:19:441:19 | b |
367-
| test.swift:439:27:439:27 | y | test.swift:439:19:439:23 | SSA def(b) |
368-
| test.swift:439:27:439:27 | y | test.swift:444:22:444:22 | y |
369-
| test.swift:444:9:444:9 | SSA def(tuple1) | test.swift:445:12:445:12 | tuple1 |
370-
| test.swift:444:18:444:23 | (...) | test.swift:444:9:444:9 | SSA def(tuple1) |
371-
| test.swift:446:10:446:37 | SSA def(a) | test.swift:447:19:447:19 | a |
372-
| test.swift:446:10:446:37 | SSA def(b) | test.swift:448:19:448:19 | b |
358+
| test.swift:438:21:438:27 | SSA def(y) | test.swift:441:27:441:27 | y |
359+
| test.swift:438:21:438:27 | SSA def(y) | test.swift:446:22:446:22 | y |
360+
| test.swift:438:21:438:27 | y | test.swift:438:21:438:27 | SSA def(y) |
361+
| test.swift:439:9:439:9 | SSA def(x) | test.swift:441:16:441:16 | x |
362+
| test.swift:439:13:439:28 | call to optionalSource() | test.swift:439:9:439:9 | SSA def(x) |
363+
| test.swift:441:8:441:12 | SSA def(a) | test.swift:442:19:442:19 | a |
364+
| test.swift:441:16:441:16 | x | test.swift:441:8:441:12 | SSA def(a) |
365+
| test.swift:441:16:441:16 | x | test.swift:446:19:446:19 | x |
366+
| test.swift:441:19:441:23 | SSA def(b) | test.swift:443:19:443:19 | b |
367+
| test.swift:441:27:441:27 | y | test.swift:441:19:441:23 | SSA def(b) |
368+
| test.swift:441:27:441:27 | y | test.swift:446:22:446:22 | y |
369+
| test.swift:446:9:446:9 | SSA def(tuple1) | test.swift:447:12:447:12 | tuple1 |
370+
| test.swift:446:18:446:23 | (...) | test.swift:446:9:446:9 | SSA def(tuple1) |
371+
| test.swift:448:10:448:37 | SSA def(a) | test.swift:449:19:449:19 | a |
372+
| test.swift:448:10:448:37 | SSA def(b) | test.swift:450:19:450:19 | b |
373+
| test.swift:455:8:455:17 | SSA def(x) | test.swift:456:19:456:19 | x |
374+
| test.swift:455:8:455:17 | SSA def(y) | test.swift:457:19:457:19 | y |
375+
| test.swift:455:21:455:29 | call to source2() | test.swift:455:8:455:17 | SSA def(x) |
376+
| test.swift:455:21:455:29 | call to source2() | test.swift:455:8:455:17 | SSA def(y) |

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ func testEnums() {
433433
}
434434
}
435435

436+
func source2() -> (Int, Int)? { return nil }
437+
436438
func testOptionals2(y: Int?) {
437439
let x = optionalSource()
438440

@@ -449,4 +451,9 @@ func testOptionals2(y: Int?) {
449451
default:
450452
()
451453
}
454+
455+
if let (x, y) = source2() {
456+
sink(arg: x) // $ flow=455
457+
sink(arg: y) // $ flow=455
458+
}
452459
}

0 commit comments

Comments
 (0)