Skip to content

Commit 1551225

Browse files
committed
Swift: Add a dataflow test for swap.
1 parent d90ddf1 commit 1551225

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ edges
269269
| test.swift:592:17:592:17 | KeyPathComponent [x] | test.swift:592:11:592:17 | exit #keyPath(...) |
270270
| test.swift:593:13:593:13 | s2 [s, x] | test.swift:592:11:592:17 | enter #keyPath(...) [s, x] |
271271
| test.swift:593:13:593:13 | s2 [s, x] | test.swift:593:13:593:26 | \\...[...] |
272+
| test.swift:618:13:618:20 | call to source() | test.swift:626:15:626:15 | y |
273+
| test.swift:628:9:628:16 | call to source() | test.swift:631:15:631:15 | x |
272274
nodes
273275
| file://:0:0:0:0 | .a [x] | semmle.label | .a [x] |
274276
| file://:0:0:0:0 | .str | semmle.label | .str |
@@ -562,6 +564,10 @@ nodes
562564
| test.swift:592:17:592:17 | KeyPathComponent [x] | semmle.label | KeyPathComponent [x] |
563565
| test.swift:593:13:593:13 | s2 [s, x] | semmle.label | s2 [s, x] |
564566
| test.swift:593:13:593:26 | \\...[...] | semmle.label | \\...[...] |
567+
| test.swift:618:13:618:20 | call to source() | semmle.label | call to source() |
568+
| test.swift:626:15:626:15 | y | semmle.label | y |
569+
| test.swift:628:9:628:16 | call to source() | semmle.label | call to source() |
570+
| test.swift:631:15:631:15 | x | semmle.label | x |
565571
subpaths
566572
| 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] &... |
567573
| 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 ... |
@@ -673,3 +679,5 @@ subpaths
673679
| test.swift:575:13:575:25 | \\...[...] | test.swift:573:16:573:23 | call to source() | test.swift:575:13:575:25 | \\...[...] | result |
674680
| test.swift:578:13:578:32 | \\...[...] | test.swift:573:16:573:23 | call to source() | test.swift:578:13:578:32 | \\...[...] | result |
675681
| test.swift:593:13:593:26 | \\...[...] | test.swift:590:16:590:23 | call to source() | test.swift:593:13:593:26 | \\...[...] | result |
682+
| test.swift:626:15:626:15 | y | test.swift:618:13:618:20 | call to source() | test.swift:626:15:626:15 | y | result |
683+
| test.swift:631:15:631:15 | x | test.swift:628:9:628:16 | call to source() | test.swift:631:15:631:15 | x | result |

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,26 @@
662662
| test.swift:613:9:613:9 | f | test.swift:613:9:613:9 | SSA def(f) |
663663
| test.swift:613:13:613:29 | #keyPath(...) | test.swift:613:9:613:9 | f |
664664
| test.swift:613:13:613:29 | enter #keyPath(...) | test.swift:613:26:613:26 | KeyPathComponent |
665+
| test.swift:618:9:618:9 | SSA def(x) | test.swift:622:9:622:9 | x |
666+
| test.swift:618:9:618:9 | x | test.swift:618:9:618:9 | SSA def(x) |
667+
| test.swift:618:13:618:20 | call to source() | test.swift:618:9:618:9 | x |
668+
| test.swift:619:9:619:9 | SSA def(y) | test.swift:623:9:623:9 | y |
669+
| test.swift:619:9:619:9 | y | test.swift:619:9:619:9 | SSA def(y) |
670+
| test.swift:619:13:619:13 | 0 | test.swift:619:9:619:9 | y |
671+
| test.swift:620:9:620:12 | ... as ... | test.swift:620:9:620:9 | t |
672+
| test.swift:622:5:622:9 | SSA def(t) | test.swift:624:9:624:9 | t |
673+
| test.swift:622:9:622:9 | x | test.swift:622:5:622:9 | SSA def(t) |
674+
| test.swift:623:5:623:9 | SSA def(x) | test.swift:625:15:625:15 | x |
675+
| test.swift:623:9:623:9 | y | test.swift:623:5:623:9 | SSA def(x) |
676+
| test.swift:624:5:624:9 | SSA def(y) | test.swift:626:15:626:15 | y |
677+
| test.swift:624:9:624:9 | t | test.swift:624:5:624:9 | SSA def(y) |
678+
| test.swift:628:5:628:16 | SSA def(x) | test.swift:630:11:630:11 | x |
679+
| test.swift:628:9:628:16 | call to source() | test.swift:628:5:628:16 | SSA def(x) |
680+
| test.swift:629:5:629:9 | SSA def(y) | test.swift:630:15:630:15 | y |
681+
| test.swift:629:9:629:9 | 0 | test.swift:629:5:629:9 | SSA def(y) |
682+
| test.swift:630:10:630:11 | &... | test.swift:631:15:631:15 | x |
683+
| test.swift:630:10:630:11 | [post] &... | test.swift:631:15:631:15 | x |
684+
| test.swift:630:11:630:11 | x | test.swift:630:10:630:11 | &... |
685+
| test.swift:630:14:630:15 | &... | test.swift:632:15:632:15 | y |
686+
| test.swift:630:14:630:15 | [post] &... | test.swift:632:15:632:15 | y |
687+
| test.swift:630:15:630:15 | y | test.swift:630:14:630:15 | &... |

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,4 +612,22 @@ func testOptionalKeyPath() {
612612
let s2 = S2_Optional(s: s)
613613
let f = \S2_Optional.s?.x
614614
sink(opt: s2[keyPath: f]) // $ MISSING: flow=611
615-
}
615+
}
616+
617+
func testSwap() {
618+
var x = source()
619+
var y = 0
620+
var t: Int
621+
622+
t = x
623+
x = y
624+
y = t
625+
sink(arg: x)
626+
sink(arg: y) // $ flow=618
627+
628+
x = source()
629+
y = 0
630+
swap(&x, &y)
631+
sink(arg: x) // $ SPURIOUS: flow=628
632+
sink(arg: y) // $ MISSING: flow=628
633+
}

0 commit comments

Comments
 (0)