Skip to content

Commit 6dc51ed

Browse files
committed
Swift: Assigning to tuple values.
1 parent 472ece4 commit 6dc51ed

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
513513
c.isSingleton(any(Content::TupleContent ct | ct.getIndex() = pos))
514514
)
515515
or
516+
exists(TupleElementExpr tuple, AssignExpr assign |
517+
tuple = assign.getDest() and
518+
node1.asExpr() = assign.getSource() and
519+
node2/*.(PostUpdateNode).getPreUpdateNode()*/.asExpr() = tuple.getSubExpr() and
520+
c.isSingleton(any(Content::TupleContent ct | ct.getIndex() = tuple.getIndex()))
521+
)
522+
or
516523
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1, c, node2)
517524
}
518525

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ edges
113113
| test.swift:277:18:277:25 | call to source() : | test.swift:277:14:277:26 | (...) [Tuple element at index 1] : |
114114
| test.swift:281:15:281:15 | t1 [Tuple element at index 1] : | test.swift:281:15:281:18 | .1 |
115115
| test.swift:287:15:287:15 | t1 [Tuple element at index 1] : | test.swift:287:15:287:18 | .1 |
116+
| test.swift:289:5:289:5 | t1 [Tuple element at index 0] : | test.swift:292:15:292:15 | t1 [Tuple element at index 0] : |
117+
| test.swift:289:12:289:19 | call to source() : | test.swift:289:5:289:5 | t1 [Tuple element at index 0] : |
118+
| test.swift:292:15:292:15 | t1 [Tuple element at index 0] : | test.swift:292:15:292:18 | .0 |
116119
| test.swift:293:15:293:15 | t1 [Tuple element at index 1] : | test.swift:293:15:293:18 | .1 |
117120
| test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | test.swift:302:15:302:15 | t1 [Tuple element at index 0] : |
118121
| test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | test.swift:306:15:306:15 | t2 [Tuple element at index 0] : |
@@ -250,6 +253,10 @@ nodes
250253
| test.swift:281:15:281:18 | .1 | semmle.label | .1 |
251254
| test.swift:287:15:287:15 | t1 [Tuple element at index 1] : | semmle.label | t1 [Tuple element at index 1] : |
252255
| test.swift:287:15:287:18 | .1 | semmle.label | .1 |
256+
| test.swift:289:5:289:5 | t1 [Tuple element at index 0] : | semmle.label | t1 [Tuple element at index 0] : |
257+
| test.swift:289:12:289:19 | call to source() : | semmle.label | call to source() : |
258+
| test.swift:292:15:292:15 | t1 [Tuple element at index 0] : | semmle.label | t1 [Tuple element at index 0] : |
259+
| test.swift:292:15:292:18 | .0 | semmle.label | .0 |
253260
| test.swift:293:15:293:15 | t1 [Tuple element at index 1] : | semmle.label | t1 [Tuple element at index 1] : |
254261
| test.swift:293:15:293:18 | .1 | semmle.label | .1 |
255262
| test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | semmle.label | (...) [Tuple element at index 0] : |
@@ -326,6 +333,7 @@ subpaths
326333
| test.swift:266:15:266:25 | OptionalEvaluationExpr | test.swift:259:12:259:19 | call to source() : | test.swift:266:15:266:25 | OptionalEvaluationExpr | result |
327334
| test.swift:281:15:281:18 | .1 | test.swift:277:18:277:25 | call to source() : | test.swift:281:15:281:18 | .1 | result |
328335
| test.swift:287:15:287:18 | .1 | test.swift:277:18:277:25 | call to source() : | test.swift:287:15:287:18 | .1 | result |
336+
| test.swift:292:15:292:18 | .0 | test.swift:289:12:289:19 | call to source() : | test.swift:292:15:292:18 | .0 | result |
329337
| test.swift:293:15:293:18 | .1 | test.swift:277:18:277:25 | call to source() : | test.swift:293:15:293:18 | .1 | result |
330338
| test.swift:302:15:302:18 | .0 | test.swift:297:18:297:25 | call to source() : | test.swift:302:15:302:18 | .0 | result |
331339
| test.swift:303:15:303:18 | .1 | test.swift:297:31:297:38 | call to source() : | test.swift:303:15:303:18 | .1 | result |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func testTuples() {
289289
t1.0 = source()
290290

291291
sink(arg: t1)
292-
sink(arg: t1.0) // $ MISSING: flow=289
292+
sink(arg: t1.0) // $ flow=289
293293
sink(arg: t1.1) // $ SPURIOUS: flow=277
294294
}
295295

0 commit comments

Comments
 (0)