Skip to content

Commit 3fe8655

Browse files
committed
Swift: Test data flow through varargs.
1 parent b4595d8 commit 3fe8655

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ edges
404404
| test.swift:756:15:756:19 | .v2 [some:0] | test.swift:756:15:756:21 | ...! |
405405
| test.swift:757:15:757:15 | mo1 [v3] | test.swift:732:9:732:9 | self [v3] |
406406
| test.swift:757:15:757:15 | mo1 [v3] | test.swift:757:15:757:19 | .v3 |
407+
| test.swift:768:19:768:24 | v | test.swift:769:15:769:15 | v |
408+
| test.swift:791:18:791:25 | call to source() | test.swift:768:19:768:24 | v |
407409
nodes
408410
| file://:0:0:0:0 | .a [x] | semmle.label | .a [x] |
409411
| file://:0:0:0:0 | .str | semmle.label | .str |
@@ -849,6 +851,9 @@ nodes
849851
| test.swift:756:15:756:21 | ...! | semmle.label | ...! |
850852
| test.swift:757:15:757:15 | mo1 [v3] | semmle.label | mo1 [v3] |
851853
| test.swift:757:15:757:19 | .v3 | semmle.label | .v3 |
854+
| test.swift:768:19:768:24 | v | semmle.label | v |
855+
| test.swift:769:15:769:15 | v | semmle.label | v |
856+
| test.swift:791:18:791:25 | call to source() | semmle.label | call to source() |
852857
subpaths
853858
| test.swift:75:22:75:22 | x | test.swift:65:16:65:28 | arg1 | test.swift:65:1:70:1 | arg2[return] | test.swift:75:32:75:32 | [post] y |
854859
| 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 ... |
@@ -996,3 +1001,4 @@ subpaths
9961001
| test.swift:754:15:754:15 | v3 | test.swift:744:10:744:17 | call to source() | test.swift:754:15:754:15 | v3 | result |
9971002
| test.swift:756:15:756:21 | ...! | test.swift:746:14:746:21 | call to source() | test.swift:756:15:756:21 | ...! | result |
9981003
| test.swift:757:15:757:19 | .v3 | test.swift:747:14:747:21 | call to source() | test.swift:757:15:757:19 | .v3 | result |
1004+
| test.swift:769:15:769:15 | v | test.swift:791:18:791:25 | call to source() | test.swift:769:15:769:15 | v | result |

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,3 +913,29 @@
913913
| test.swift:759:15:759:15 | mo2 | test.swift:760:15:760:15 | mo2 |
914914
| test.swift:759:15:759:20 | .v2 | test.swift:759:15:759:22 | ...! |
915915
| test.swift:760:15:760:15 | mo2 | test.swift:760:15:760:18 | ...! |
916+
| test.swift:763:19:763:28 | SSA def(args) | test.swift:764:15:764:15 | args |
917+
| test.swift:763:19:763:28 | args | test.swift:763:19:763:28 | SSA def(args) |
918+
| test.swift:764:15:764:15 | args | test.swift:765:15:765:15 | args |
919+
| test.swift:768:19:768:24 | SSA def(v) | test.swift:769:15:769:15 | v |
920+
| test.swift:768:19:768:24 | v | test.swift:768:19:768:24 | SSA def(v) |
921+
| test.swift:768:29:768:40 | SSA def(args) | test.swift:770:15:770:15 | args |
922+
| test.swift:768:29:768:40 | args | test.swift:768:29:768:40 | SSA def(args) |
923+
| test.swift:770:15:770:15 | args | test.swift:771:15:771:15 | args |
924+
| test.swift:771:15:771:15 | [post] args | test.swift:772:15:772:15 | args |
925+
| test.swift:771:15:771:15 | args | test.swift:772:15:772:15 | args |
926+
| test.swift:775:19:775:24 | SSA def(v) | test.swift:776:15:776:15 | v |
927+
| test.swift:775:19:775:24 | v | test.swift:775:19:775:24 | SSA def(v) |
928+
| test.swift:775:29:775:40 | SSA def(args) | test.swift:777:15:777:15 | args |
929+
| test.swift:775:29:775:40 | args | test.swift:775:29:775:40 | SSA def(args) |
930+
| test.swift:777:15:777:15 | args | test.swift:778:15:778:15 | args |
931+
| test.swift:778:15:778:15 | [post] args | test.swift:779:15:779:15 | args |
932+
| test.swift:778:15:778:15 | args | test.swift:779:15:779:15 | args |
933+
| test.swift:779:15:779:15 | [post] args | test.swift:781:16:781:16 | args |
934+
| test.swift:779:15:779:15 | args | test.swift:781:16:781:16 | args |
935+
| test.swift:781:9:781:9 | SSA def(arg) | test.swift:782:19:782:19 | arg |
936+
| test.swift:781:9:781:9 | arg | test.swift:781:9:781:9 | SSA def(arg) |
937+
| test.swift:781:16:781:16 | args | test.swift:786:15:786:15 | args |
938+
| test.swift:785:9:785:9 | SSA def(myKeyPath) | test.swift:786:29:786:29 | myKeyPath |
939+
| test.swift:785:9:785:9 | myKeyPath | test.swift:785:9:785:9 | SSA def(myKeyPath) |
940+
| test.swift:785:21:785:29 | #keyPath(...) | test.swift:785:9:785:9 | myKeyPath |
941+
| test.swift:785:21:785:29 | enter #keyPath(...) | test.swift:785:27:785:29 | KeyPathComponent |

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,3 +759,35 @@ func testWriteOptional() {
759759
sink(arg: mo2!.v2!) // $ MISSING:flow=749
760760
sink(arg: mo2!.v3) // $ MISSING:flow=750
761761
}
762+
763+
func testVarargs1(args: Int...) {
764+
sink(arg: args)
765+
sink(arg: args[0]) // $ MISSING: flow=790
766+
}
767+
768+
func testVarargs2(_ v: Int, _ args: Int...) {
769+
sink(arg: v) // $ flow=791
770+
sink(arg: args)
771+
sink(arg: args[0])
772+
sink(arg: args[1])
773+
}
774+
775+
func testVarargs3(_ v: Int, _ args: Int...) {
776+
sink(arg: v)
777+
sink(arg: args)
778+
sink(arg: args[0])
779+
sink(arg: args[1]) // $ MISSING: flow=792
780+
781+
for arg in args {
782+
sink(arg: arg) // $ MISSING: flow=792
783+
}
784+
785+
let myKeyPath = \[Int][1]
786+
sink(arg: args[keyPath: myKeyPath]) // $ MISSING: flow=792
787+
}
788+
789+
func testVarargsCaller() {
790+
testVarargs1(args: source())
791+
testVarargs2(source(), 2, 3)
792+
testVarargs3(1, 2, source())
793+
}

0 commit comments

Comments
 (0)