Skip to content

Commit a9f5471

Browse files
committed
Swift: add tests for broken dictionary flow case
1 parent 3f0a249 commit a9f5471

File tree

3 files changed

+79
-59
lines changed

3 files changed

+79
-59
lines changed

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

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -408,23 +408,28 @@ edges
408408
| test.swift:767:16:767:23 | call to source() | test.swift:767:5:767:5 | [post] dict1 [Array element] |
409409
| test.swift:769:15:769:15 | dict1 [Array element] | test.swift:769:15:769:22 | ...[...] |
410410
| test.swift:779:17:779:29 | [...] [Collection element, Tuple element at index 1] | test.swift:780:15:780:15 | dict3 [Collection element, Tuple element at index 1] |
411+
| test.swift:779:17:779:29 | [...] [Collection element, Tuple element at index 1] | test.swift:782:5:782:5 | dict3 [Collection element, Tuple element at index 1] |
411412
| test.swift:779:18:779:28 | (...) [Tuple element at index 1] | test.swift:779:17:779:29 | [...] [Collection element, Tuple element at index 1] |
412413
| test.swift:779:21:779:28 | call to source() | test.swift:779:18:779:28 | (...) [Tuple element at index 1] |
413414
| test.swift:780:15:780:15 | dict3 [Collection element, Tuple element at index 1] | test.swift:780:15:780:22 | DictionarySubscriptNode [Tuple element at index 1] |
414415
| test.swift:780:15:780:22 | DictionarySubscriptNode [Tuple element at index 1] | test.swift:780:15:780:22 | ...[...] |
415-
| test.swift:789:17:789:28 | [...] [Collection element, Tuple element at index 1] | test.swift:793:15:793:15 | dict4 [Collection element, Tuple element at index 1] |
416-
| test.swift:789:18:789:27 | (...) [Tuple element at index 1] | test.swift:789:17:789:28 | [...] [Collection element, Tuple element at index 1] |
417-
| test.swift:789:20:789:27 | call to source() | test.swift:789:18:789:27 | (...) [Tuple element at index 1] |
418-
| test.swift:790:15:790:15 | [post] dict4 [Collection element, Tuple element at index 0] | test.swift:792:15:792:15 | dict4 [Collection element, Tuple element at index 0] |
419-
| test.swift:790:44:790:51 | call to source() | test.swift:790:15:790:15 | [post] dict4 [Collection element, Tuple element at index 0] |
420-
| test.swift:791:15:791:15 | [post] dict4 [Collection element, Tuple element at index 1] | test.swift:793:15:793:15 | dict4 [Collection element, Tuple element at index 1] |
421-
| test.swift:791:33:791:40 | call to source() | test.swift:791:15:791:15 | [post] dict4 [Collection element, Tuple element at index 1] |
422-
| test.swift:792:15:792:15 | dict4 [Collection element, Tuple element at index 0] | test.swift:792:15:792:35 | call to randomElement() [some:0, Tuple element at index 0] |
423-
| test.swift:792:15:792:35 | call to randomElement() [some:0, Tuple element at index 0] | test.swift:792:15:792:36 | ...! [Tuple element at index 0] |
424-
| test.swift:792:15:792:36 | ...! [Tuple element at index 0] | test.swift:792:15:792:38 | .0 |
425-
| test.swift:793:15:793:15 | dict4 [Collection element, Tuple element at index 1] | test.swift:793:15:793:35 | call to randomElement() [some:0, Tuple element at index 1] |
426-
| test.swift:793:15:793:35 | call to randomElement() [some:0, Tuple element at index 1] | test.swift:793:15:793:36 | ...! [Tuple element at index 1] |
427-
| test.swift:793:15:793:36 | ...! [Tuple element at index 1] | test.swift:793:15:793:38 | .1 |
416+
| test.swift:782:5:782:5 | dict3 [Collection element, Tuple element at index 1] | test.swift:785:15:785:15 | dict3 [Collection element, Tuple element at index 1] |
417+
| test.swift:785:15:785:15 | dict3 [Collection element, Tuple element at index 1] | test.swift:785:15:785:35 | call to randomElement() [some:0, Tuple element at index 1] |
418+
| test.swift:785:15:785:35 | call to randomElement() [some:0, Tuple element at index 1] | test.swift:785:15:785:36 | ...! [Tuple element at index 1] |
419+
| test.swift:785:15:785:36 | ...! [Tuple element at index 1] | test.swift:785:15:785:38 | .1 |
420+
| test.swift:792:17:792:28 | [...] [Collection element, Tuple element at index 1] | test.swift:796:15:796:15 | dict4 [Collection element, Tuple element at index 1] |
421+
| test.swift:792:18:792:27 | (...) [Tuple element at index 1] | test.swift:792:17:792:28 | [...] [Collection element, Tuple element at index 1] |
422+
| test.swift:792:20:792:27 | call to source() | test.swift:792:18:792:27 | (...) [Tuple element at index 1] |
423+
| test.swift:793:15:793:15 | [post] dict4 [Collection element, Tuple element at index 0] | test.swift:795:15:795:15 | dict4 [Collection element, Tuple element at index 0] |
424+
| test.swift:793:44:793:51 | call to source() | test.swift:793:15:793:15 | [post] dict4 [Collection element, Tuple element at index 0] |
425+
| test.swift:794:15:794:15 | [post] dict4 [Collection element, Tuple element at index 1] | test.swift:796:15:796:15 | dict4 [Collection element, Tuple element at index 1] |
426+
| test.swift:794:33:794:40 | call to source() | test.swift:794:15:794:15 | [post] dict4 [Collection element, Tuple element at index 1] |
427+
| test.swift:795:15:795:15 | dict4 [Collection element, Tuple element at index 0] | test.swift:795:15:795:35 | call to randomElement() [some:0, Tuple element at index 0] |
428+
| test.swift:795:15:795:35 | call to randomElement() [some:0, Tuple element at index 0] | test.swift:795:15:795:36 | ...! [Tuple element at index 0] |
429+
| test.swift:795:15:795:36 | ...! [Tuple element at index 0] | test.swift:795:15:795:38 | .0 |
430+
| test.swift:796:15:796:15 | dict4 [Collection element, Tuple element at index 1] | test.swift:796:15:796:35 | call to randomElement() [some:0, Tuple element at index 1] |
431+
| test.swift:796:15:796:35 | call to randomElement() [some:0, Tuple element at index 1] | test.swift:796:15:796:36 | ...! [Tuple element at index 1] |
432+
| test.swift:796:15:796:36 | ...! [Tuple element at index 1] | test.swift:796:15:796:38 | .1 |
428433
nodes
429434
| file://:0:0:0:0 | .a [x] | semmle.label | .a [x] |
430435
| file://:0:0:0:0 | .str | semmle.label | .str |
@@ -880,21 +885,26 @@ nodes
880885
| test.swift:780:15:780:15 | dict3 [Collection element, Tuple element at index 1] | semmle.label | dict3 [Collection element, Tuple element at index 1] |
881886
| test.swift:780:15:780:22 | ...[...] | semmle.label | ...[...] |
882887
| test.swift:780:15:780:22 | DictionarySubscriptNode [Tuple element at index 1] | semmle.label | DictionarySubscriptNode [Tuple element at index 1] |
883-
| test.swift:789:17:789:28 | [...] [Collection element, Tuple element at index 1] | semmle.label | [...] [Collection element, Tuple element at index 1] |
884-
| test.swift:789:18:789:27 | (...) [Tuple element at index 1] | semmle.label | (...) [Tuple element at index 1] |
885-
| test.swift:789:20:789:27 | call to source() | semmle.label | call to source() |
886-
| test.swift:790:15:790:15 | [post] dict4 [Collection element, Tuple element at index 0] | semmle.label | [post] dict4 [Collection element, Tuple element at index 0] |
887-
| test.swift:790:44:790:51 | call to source() | semmle.label | call to source() |
888-
| test.swift:791:15:791:15 | [post] dict4 [Collection element, Tuple element at index 1] | semmle.label | [post] dict4 [Collection element, Tuple element at index 1] |
889-
| test.swift:791:33:791:40 | call to source() | semmle.label | call to source() |
890-
| test.swift:792:15:792:15 | dict4 [Collection element, Tuple element at index 0] | semmle.label | dict4 [Collection element, Tuple element at index 0] |
891-
| test.swift:792:15:792:35 | call to randomElement() [some:0, Tuple element at index 0] | semmle.label | call to randomElement() [some:0, Tuple element at index 0] |
892-
| test.swift:792:15:792:36 | ...! [Tuple element at index 0] | semmle.label | ...! [Tuple element at index 0] |
893-
| test.swift:792:15:792:38 | .0 | semmle.label | .0 |
894-
| test.swift:793:15:793:15 | dict4 [Collection element, Tuple element at index 1] | semmle.label | dict4 [Collection element, Tuple element at index 1] |
895-
| test.swift:793:15:793:35 | call to randomElement() [some:0, Tuple element at index 1] | semmle.label | call to randomElement() [some:0, Tuple element at index 1] |
896-
| test.swift:793:15:793:36 | ...! [Tuple element at index 1] | semmle.label | ...! [Tuple element at index 1] |
897-
| test.swift:793:15:793:38 | .1 | semmle.label | .1 |
888+
| test.swift:782:5:782:5 | dict3 [Collection element, Tuple element at index 1] | semmle.label | dict3 [Collection element, Tuple element at index 1] |
889+
| test.swift:785:15:785:15 | dict3 [Collection element, Tuple element at index 1] | semmle.label | dict3 [Collection element, Tuple element at index 1] |
890+
| test.swift:785:15:785:35 | call to randomElement() [some:0, Tuple element at index 1] | semmle.label | call to randomElement() [some:0, Tuple element at index 1] |
891+
| test.swift:785:15:785:36 | ...! [Tuple element at index 1] | semmle.label | ...! [Tuple element at index 1] |
892+
| test.swift:785:15:785:38 | .1 | semmle.label | .1 |
893+
| test.swift:792:17:792:28 | [...] [Collection element, Tuple element at index 1] | semmle.label | [...] [Collection element, Tuple element at index 1] |
894+
| test.swift:792:18:792:27 | (...) [Tuple element at index 1] | semmle.label | (...) [Tuple element at index 1] |
895+
| test.swift:792:20:792:27 | call to source() | semmle.label | call to source() |
896+
| test.swift:793:15:793:15 | [post] dict4 [Collection element, Tuple element at index 0] | semmle.label | [post] dict4 [Collection element, Tuple element at index 0] |
897+
| test.swift:793:44:793:51 | call to source() | semmle.label | call to source() |
898+
| test.swift:794:15:794:15 | [post] dict4 [Collection element, Tuple element at index 1] | semmle.label | [post] dict4 [Collection element, Tuple element at index 1] |
899+
| test.swift:794:33:794:40 | call to source() | semmle.label | call to source() |
900+
| test.swift:795:15:795:15 | dict4 [Collection element, Tuple element at index 0] | semmle.label | dict4 [Collection element, Tuple element at index 0] |
901+
| test.swift:795:15:795:35 | call to randomElement() [some:0, Tuple element at index 0] | semmle.label | call to randomElement() [some:0, Tuple element at index 0] |
902+
| test.swift:795:15:795:36 | ...! [Tuple element at index 0] | semmle.label | ...! [Tuple element at index 0] |
903+
| test.swift:795:15:795:38 | .0 | semmle.label | .0 |
904+
| test.swift:796:15:796:15 | dict4 [Collection element, Tuple element at index 1] | semmle.label | dict4 [Collection element, Tuple element at index 1] |
905+
| test.swift:796:15:796:35 | call to randomElement() [some:0, Tuple element at index 1] | semmle.label | call to randomElement() [some:0, Tuple element at index 1] |
906+
| test.swift:796:15:796:36 | ...! [Tuple element at index 1] | semmle.label | ...! [Tuple element at index 1] |
907+
| test.swift:796:15:796:38 | .1 | semmle.label | .1 |
898908
subpaths
899909
| 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 |
900910
| 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 ... |
@@ -1044,6 +1054,7 @@ subpaths
10441054
| test.swift:757:15:757:19 | .v3 | test.swift:747:14:747:21 | call to source() | test.swift:757:15:757:19 | .v3 | result |
10451055
| test.swift:769:15:769:22 | ...[...] | test.swift:767:16:767:23 | call to source() | test.swift:769:15:769:22 | ...[...] | result |
10461056
| test.swift:780:15:780:22 | ...[...] | test.swift:779:21:779:28 | call to source() | test.swift:780:15:780:22 | ...[...] | result |
1047-
| test.swift:792:15:792:38 | .0 | test.swift:790:44:790:51 | call to source() | test.swift:792:15:792:38 | .0 | result |
1048-
| test.swift:793:15:793:38 | .1 | test.swift:789:20:789:27 | call to source() | test.swift:793:15:793:38 | .1 | result |
1049-
| test.swift:793:15:793:38 | .1 | test.swift:791:33:791:40 | call to source() | test.swift:793:15:793:38 | .1 | result |
1057+
| test.swift:785:15:785:38 | .1 | test.swift:779:21:779:28 | call to source() | test.swift:785:15:785:38 | .1 | result |
1058+
| test.swift:795:15:795:38 | .0 | test.swift:793:44:793:51 | call to source() | test.swift:795:15:795:38 | .0 | result |
1059+
| test.swift:796:15:796:38 | .1 | test.swift:792:20:792:27 | call to source() | test.swift:796:15:796:38 | .1 | result |
1060+
| test.swift:796:15:796:38 | .1 | test.swift:794:33:794:40 | call to source() | test.swift:796:15:796:38 | .1 | result |

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

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -940,29 +940,35 @@
940940
| test.swift:780:15:780:15 | &... | test.swift:782:5:782:5 | dict3 |
941941
| test.swift:780:15:780:15 | [post] dict3 | test.swift:780:15:780:15 | &... |
942942
| test.swift:780:15:780:15 | dict3 | test.swift:780:15:780:15 | &... |
943-
| test.swift:782:5:782:5 | &... | test.swift:784:25:784:25 | dict3 |
943+
| test.swift:782:5:782:5 | &... | test.swift:784:15:784:15 | dict3 |
944944
| test.swift:782:5:782:5 | [post] dict3 | test.swift:782:5:782:5 | &... |
945945
| test.swift:782:5:782:5 | dict3 | test.swift:782:5:782:5 | &... |
946-
| test.swift:784:10:784:10 | SSA def(key) | test.swift:785:19:785:19 | key |
947-
| test.swift:784:10:784:10 | key | test.swift:784:10:784:10 | SSA def(key) |
948-
| test.swift:784:15:784:15 | SSA def(value) | test.swift:786:19:786:19 | value |
949-
| test.swift:784:15:784:15 | value | test.swift:784:15:784:15 | SSA def(value) |
950-
| test.swift:789:9:789:9 | SSA def(dict4) | test.swift:790:15:790:15 | dict4 |
951-
| test.swift:789:9:789:9 | dict4 | test.swift:789:9:789:9 | SSA def(dict4) |
952-
| test.swift:789:17:789:28 | [...] | test.swift:789:9:789:9 | dict4 |
953-
| test.swift:790:15:790:15 | &... | test.swift:791:15:791:15 | dict4 |
954-
| test.swift:790:15:790:15 | [post] dict4 | test.swift:790:15:790:15 | &... |
955-
| test.swift:790:15:790:15 | dict4 | test.swift:790:15:790:15 | &... |
956-
| test.swift:790:15:790:52 | call to updateValue(_:forKey:) | test.swift:790:15:790:53 | ...! |
957-
| test.swift:791:15:791:15 | &... | test.swift:792:15:792:15 | dict4 |
958-
| test.swift:791:15:791:15 | [post] dict4 | test.swift:791:15:791:15 | &... |
959-
| test.swift:791:15:791:15 | dict4 | test.swift:791:15:791:15 | &... |
960-
| test.swift:791:15:791:52 | call to updateValue(_:forKey:) | test.swift:791:15:791:53 | ...! |
961-
| test.swift:792:15:792:15 | [post] dict4 | test.swift:793:15:793:15 | dict4 |
962-
| test.swift:792:15:792:15 | dict4 | test.swift:793:15:793:15 | dict4 |
963-
| test.swift:792:15:792:35 | call to randomElement() | test.swift:792:15:792:36 | ...! |
964-
| test.swift:793:15:793:15 | [post] dict4 | test.swift:794:15:794:15 | dict4 |
965-
| test.swift:793:15:793:15 | dict4 | test.swift:794:15:794:15 | dict4 |
966-
| test.swift:793:15:793:35 | call to randomElement() | test.swift:793:15:793:36 | ...! |
967-
| test.swift:794:15:794:15 | [post] dict4 | test.swift:795:15:795:15 | dict4 |
968-
| test.swift:794:15:794:15 | dict4 | test.swift:795:15:795:15 | dict4 |
946+
| test.swift:784:15:784:15 | [post] dict3 | test.swift:785:15:785:15 | dict3 |
947+
| test.swift:784:15:784:15 | dict3 | test.swift:785:15:785:15 | dict3 |
948+
| test.swift:784:15:784:35 | call to randomElement() | test.swift:784:15:784:36 | ...! |
949+
| test.swift:785:15:785:15 | [post] dict3 | test.swift:787:25:787:25 | dict3 |
950+
| test.swift:785:15:785:15 | dict3 | test.swift:787:25:787:25 | dict3 |
951+
| test.swift:785:15:785:35 | call to randomElement() | test.swift:785:15:785:36 | ...! |
952+
| test.swift:787:10:787:10 | SSA def(key) | test.swift:788:19:788:19 | key |
953+
| test.swift:787:10:787:10 | key | test.swift:787:10:787:10 | SSA def(key) |
954+
| test.swift:787:15:787:15 | SSA def(value) | test.swift:789:19:789:19 | value |
955+
| test.swift:787:15:787:15 | value | test.swift:787:15:787:15 | SSA def(value) |
956+
| test.swift:792:9:792:9 | SSA def(dict4) | test.swift:793:15:793:15 | dict4 |
957+
| test.swift:792:9:792:9 | dict4 | test.swift:792:9:792:9 | SSA def(dict4) |
958+
| test.swift:792:17:792:28 | [...] | test.swift:792:9:792:9 | dict4 |
959+
| test.swift:793:15:793:15 | &... | test.swift:794:15:794:15 | dict4 |
960+
| test.swift:793:15:793:15 | [post] dict4 | test.swift:793:15:793:15 | &... |
961+
| test.swift:793:15:793:15 | dict4 | test.swift:793:15:793:15 | &... |
962+
| test.swift:793:15:793:52 | call to updateValue(_:forKey:) | test.swift:793:15:793:53 | ...! |
963+
| test.swift:794:15:794:15 | &... | test.swift:795:15:795:15 | dict4 |
964+
| test.swift:794:15:794:15 | [post] dict4 | test.swift:794:15:794:15 | &... |
965+
| test.swift:794:15:794:15 | dict4 | test.swift:794:15:794:15 | &... |
966+
| test.swift:794:15:794:52 | call to updateValue(_:forKey:) | test.swift:794:15:794:53 | ...! |
967+
| test.swift:795:15:795:15 | [post] dict4 | test.swift:796:15:796:15 | dict4 |
968+
| test.swift:795:15:795:15 | dict4 | test.swift:796:15:796:15 | dict4 |
969+
| test.swift:795:15:795:35 | call to randomElement() | test.swift:795:15:795:36 | ...! |
970+
| test.swift:796:15:796:15 | [post] dict4 | test.swift:797:15:797:15 | dict4 |
971+
| test.swift:796:15:796:15 | dict4 | test.swift:797:15:797:15 | dict4 |
972+
| test.swift:796:15:796:35 | call to randomElement() | test.swift:796:15:796:36 | ...! |
973+
| test.swift:797:15:797:15 | [post] dict4 | test.swift:798:15:798:15 | dict4 |
974+
| test.swift:797:15:797:15 | dict4 | test.swift:798:15:798:15 | dict4 |

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,9 @@ func testDictionary() {
781781

782782
dict3[source()] = 2
783783

784+
sink(arg: dict3.randomElement()!.0) // $ MISSING: flow=779
785+
sink(arg: dict3.randomElement()!.1) // $ SPURIOUS: flow=779 MISSING: flow=782
786+
784787
for (key, value) in dict3 {
785788
sink(arg: key) // $ MISSING: flow=782
786789
sink(arg: value) // $ MISSING: flow=779
@@ -789,8 +792,8 @@ func testDictionary() {
789792
var dict4 = [1:source()]
790793
sink(arg: dict4.updateValue(1, forKey: source())!)
791794
sink(arg: dict4.updateValue(source(), forKey: 2)!)
792-
sink(arg: dict4.randomElement()!.0) // $ flow=790
793-
sink(arg: dict4.randomElement()!.1) // $ flow=789 flow=791
794-
sink(arg: dict4.keys.randomElement()) // $ MISSING: flow=790
795-
sink(arg: dict4.values.randomElement()) // $ MISSING: flow=789 flow=791
795+
sink(arg: dict4.randomElement()!.0) // $ flow=793
796+
sink(arg: dict4.randomElement()!.1) // $ flow=792 flow=794
797+
sink(arg: dict4.keys.randomElement()) // $ MISSING: flow=793
798+
sink(arg: dict4.values.randomElement()) // $ MISSING: flow=792 flow=794
796799
}

0 commit comments

Comments
 (0)