Skip to content

Commit df81626

Browse files
committed
Swift: Model swap.
1 parent 1551225 commit df81626

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Provides models for Swift "Manual Memory Management" functions.
3+
*/
4+
5+
import swift
6+
private import codeql.swift.dataflow.ExternalFlow
7+
8+
private class ManualMemoryManagementSummaries extends SummaryModelCsv {
9+
override predicate row(string row) {
10+
row =
11+
[
12+
";;false;swap(_:_:);;;Argument[0];Argument[1];value",
13+
";;false;swap(_:_:);;;Argument[1];Argument[0];value",
14+
]
15+
}
16+
}

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/StandardLibrary.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ private import Data
88
private import FileManager
99
private import FilePath
1010
private import InputStream
11+
private import ManualMemoryManagement
1112
private import NsData
1213
private import NsObject
1314
private import NsString

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ edges
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 | \\...[...] |
272272
| 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:630:10:630:11 | &... |
273274
| test.swift:628:9:628:16 | call to source() | test.swift:631:15:631:15 | x |
275+
| test.swift:630:10:630:11 | &... | test.swift:630:14:630:15 | [post] &... |
276+
| test.swift:630:14:630:15 | [post] &... | test.swift:632:15:632:15 | y |
274277
nodes
275278
| file://:0:0:0:0 | .a [x] | semmle.label | .a [x] |
276279
| file://:0:0:0:0 | .str | semmle.label | .str |
@@ -567,7 +570,10 @@ nodes
567570
| test.swift:618:13:618:20 | call to source() | semmle.label | call to source() |
568571
| test.swift:626:15:626:15 | y | semmle.label | y |
569572
| test.swift:628:9:628:16 | call to source() | semmle.label | call to source() |
573+
| test.swift:630:10:630:11 | &... | semmle.label | &... |
574+
| test.swift:630:14:630:15 | [post] &... | semmle.label | [post] &... |
570575
| test.swift:631:15:631:15 | x | semmle.label | x |
576+
| test.swift:632:15:632:15 | y | semmle.label | y |
571577
subpaths
572578
| 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] &... |
573579
| 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 ... |
@@ -681,3 +687,4 @@ subpaths
681687
| test.swift:593:13:593:26 | \\...[...] | test.swift:590:16:590:23 | call to source() | test.swift:593:13:593:26 | \\...[...] | result |
682688
| test.swift:626:15:626:15 | y | test.swift:618:13:618:20 | call to source() | test.swift:626:15:626:15 | y | result |
683689
| test.swift:631:15:631:15 | x | test.swift:628:9:628:16 | call to source() | test.swift:631:15:631:15 | x | result |
690+
| test.swift:632:15:632:15 | y | test.swift:628:9:628:16 | call to source() | test.swift:632:15:632:15 | y | result |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,5 +629,5 @@ func testSwap() {
629629
y = 0
630630
swap(&x, &y)
631631
sink(arg: x) // $ SPURIOUS: flow=628
632-
sink(arg: y) // $ MISSING: flow=628
632+
sink(arg: y) // $ flow=628
633633
}

0 commit comments

Comments
 (0)