Skip to content

Commit 24f0eeb

Browse files
committed
Swift: Better assigning to tuple values.
1 parent 6dc51ed commit 24f0eeb

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private module Cached {
8686
hasExprNode(n,
8787
[
8888
any(Argument arg | modifiable(arg)).getExpr(), any(MemberRefExpr ref).getBase(),
89-
any(ApplyExpr apply).getQualifier()
89+
any(ApplyExpr apply).getQualifier(), any(TupleElementExpr te).getSubExpr()
9090
])
9191
}
9292

@@ -516,7 +516,7 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
516516
exists(TupleElementExpr tuple, AssignExpr assign |
517517
tuple = assign.getDest() and
518518
node1.asExpr() = assign.getSource() and
519-
node2/*.(PostUpdateNode).getPreUpdateNode()*/.asExpr() = tuple.getSubExpr() and
519+
node2.(PostUpdateNode).getPreUpdateNode().asExpr() = tuple.getSubExpr() and
520520
c.isSingleton(any(Content::TupleContent ct | ct.getIndex() = tuple.getIndex()))
521521
)
522522
or

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,11 @@ edges
108108
| test.swift:266:15:266:16 | ...? : | test.swift:266:15:266:25 | call to signum() : |
109109
| test.swift:266:15:266:25 | call to signum() : | test.swift:266:15:266:25 | OptionalEvaluationExpr |
110110
| test.swift:277:14:277:26 | (...) [Tuple element at index 1] : | test.swift:281:15:281:15 | t1 [Tuple element at index 1] : |
111-
| test.swift:277:14:277:26 | (...) [Tuple element at index 1] : | test.swift:287:15:287:15 | t1 [Tuple element at index 1] : |
112-
| test.swift:277:14:277:26 | (...) [Tuple element at index 1] : | test.swift:293:15:293:15 | t1 [Tuple element at index 1] : |
113111
| test.swift:277:18:277:25 | call to source() : | test.swift:277:14:277:26 | (...) [Tuple element at index 1] : |
114112
| test.swift:281:15:281:15 | t1 [Tuple element at index 1] : | test.swift:281:15:281:18 | .1 |
115-
| 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] : |
113+
| test.swift:289:5:289:5 | [post] t1 [Tuple element at index 0] : | test.swift:292:15:292:15 | t1 [Tuple element at index 0] : |
114+
| test.swift:289:12:289:19 | call to source() : | test.swift:289:5:289:5 | [post] t1 [Tuple element at index 0] : |
118115
| test.swift:292:15:292:15 | t1 [Tuple element at index 0] : | test.swift:292:15:292:18 | .0 |
119-
| test.swift:293:15:293:15 | t1 [Tuple element at index 1] : | test.swift:293:15:293:18 | .1 |
120116
| test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | test.swift:302:15:302:15 | t1 [Tuple element at index 0] : |
121117
| test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | test.swift:306:15:306:15 | t2 [Tuple element at index 0] : |
122118
| test.swift:297:14:297:45 | (...) [Tuple element at index 1] : | test.swift:303:15:303:15 | t1 [Tuple element at index 1] : |
@@ -251,14 +247,10 @@ nodes
251247
| test.swift:277:18:277:25 | call to source() : | semmle.label | call to source() : |
252248
| test.swift:281:15:281:15 | t1 [Tuple element at index 1] : | semmle.label | t1 [Tuple element at index 1] : |
253249
| test.swift:281:15:281:18 | .1 | semmle.label | .1 |
254-
| test.swift:287:15:287:15 | t1 [Tuple element at index 1] : | semmle.label | t1 [Tuple element at index 1] : |
255-
| 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] : |
250+
| test.swift:289:5:289:5 | [post] t1 [Tuple element at index 0] : | semmle.label | [post] t1 [Tuple element at index 0] : |
257251
| test.swift:289:12:289:19 | call to source() : | semmle.label | call to source() : |
258252
| test.swift:292:15:292:15 | t1 [Tuple element at index 0] : | semmle.label | t1 [Tuple element at index 0] : |
259253
| test.swift:292:15:292:18 | .0 | semmle.label | .0 |
260-
| test.swift:293:15:293:15 | t1 [Tuple element at index 1] : | semmle.label | t1 [Tuple element at index 1] : |
261-
| test.swift:293:15:293:18 | .1 | semmle.label | .1 |
262254
| test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | semmle.label | (...) [Tuple element at index 0] : |
263255
| test.swift:297:14:297:45 | (...) [Tuple element at index 1] : | semmle.label | (...) [Tuple element at index 1] : |
264256
| test.swift:297:18:297:25 | call to source() : | semmle.label | call to source() : |
@@ -332,9 +324,7 @@ subpaths
332324
| test.swift:265:15:265:31 | call to signum() | test.swift:265:15:265:22 | call to source() : | test.swift:265:15:265:31 | call to signum() | result |
333325
| test.swift:266:15:266:25 | OptionalEvaluationExpr | test.swift:259:12:259:19 | call to source() : | test.swift:266:15:266:25 | OptionalEvaluationExpr | result |
334326
| test.swift:281:15:281:18 | .1 | test.swift:277:18:277:25 | call to source() : | test.swift:281:15:281:18 | .1 | result |
335-
| test.swift:287:15:287:18 | .1 | test.swift:277:18:277:25 | call to source() : | test.swift:287:15:287:18 | .1 | result |
336327
| test.swift:292:15:292:18 | .0 | test.swift:289:12:289:19 | call to source() : | test.swift:292:15:292:18 | .0 | result |
337-
| test.swift:293:15:293:18 | .1 | test.swift:277:18:277:25 | call to source() : | test.swift:293:15:293:18 | .1 | result |
338328
| test.swift:302:15:302:18 | .0 | test.swift:297:18:297:25 | call to source() : | test.swift:302:15:302:18 | .0 | result |
339329
| test.swift:303:15:303:18 | .1 | test.swift:297:31:297:38 | call to source() : | test.swift:303:15:303:18 | .1 | result |
340330
| test.swift:306:15:306:18 | .0 | test.swift:297:18:297:25 | call to source() : | test.swift:306:15:306:18 | .0 | result |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.swift:287:21:288:1 | // $ flow=277\n | Missing result:flow=277 |
2+
| test.swift:293:21:294:1 | // $ flow=277\n | Missing result:flow=277 |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,21 @@
195195
| test.swift:277:9:277:9 | WriteDef | test.swift:279:15:279:15 | t1 |
196196
| test.swift:277:14:277:26 | (...) | test.swift:277:9:277:9 | WriteDef |
197197
| test.swift:279:15:279:15 | t1 | test.swift:280:15:280:15 | t1 |
198+
| test.swift:280:15:280:15 | [post] t1 | test.swift:281:15:281:15 | t1 |
198199
| test.swift:280:15:280:15 | t1 | test.swift:281:15:281:15 | t1 |
200+
| test.swift:281:15:281:15 | [post] t1 | test.swift:283:5:283:5 | t1 |
199201
| test.swift:281:15:281:15 | t1 | test.swift:283:5:283:5 | t1 |
202+
| test.swift:283:5:283:5 | [post] t1 | test.swift:285:15:285:15 | t1 |
200203
| test.swift:283:5:283:5 | t1 | test.swift:285:15:285:15 | t1 |
201204
| test.swift:285:15:285:15 | t1 | test.swift:286:15:286:15 | t1 |
205+
| test.swift:286:15:286:15 | [post] t1 | test.swift:287:15:287:15 | t1 |
202206
| test.swift:286:15:286:15 | t1 | test.swift:287:15:287:15 | t1 |
207+
| test.swift:287:15:287:15 | [post] t1 | test.swift:289:5:289:5 | t1 |
203208
| test.swift:287:15:287:15 | t1 | test.swift:289:5:289:5 | t1 |
209+
| test.swift:289:5:289:5 | [post] t1 | test.swift:291:15:291:15 | t1 |
204210
| test.swift:289:5:289:5 | t1 | test.swift:291:15:291:15 | t1 |
205211
| test.swift:291:15:291:15 | t1 | test.swift:292:15:292:15 | t1 |
212+
| test.swift:292:15:292:15 | [post] t1 | test.swift:293:15:293:15 | t1 |
206213
| test.swift:292:15:292:15 | t1 | test.swift:293:15:293:15 | t1 |
207214
| test.swift:297:9:297:9 | WriteDef | test.swift:298:14:298:14 | t1 |
208215
| test.swift:297:14:297:45 | (...) | test.swift:297:9:297:9 | WriteDef |
@@ -217,8 +224,12 @@
217224
| test.swift:299:21:299:21 | t1 | test.swift:299:9:299:17 | WriteDef |
218225
| test.swift:299:21:299:21 | t1 | test.swift:301:15:301:15 | t1 |
219226
| test.swift:301:15:301:15 | t1 | test.swift:302:15:302:15 | t1 |
227+
| test.swift:302:15:302:15 | [post] t1 | test.swift:303:15:303:15 | t1 |
220228
| test.swift:302:15:302:15 | t1 | test.swift:303:15:303:15 | t1 |
229+
| test.swift:303:15:303:15 | [post] t1 | test.swift:304:15:304:15 | t1 |
221230
| test.swift:303:15:303:15 | t1 | test.swift:304:15:304:15 | t1 |
222231
| test.swift:305:15:305:15 | t2 | test.swift:306:15:306:15 | t2 |
232+
| test.swift:306:15:306:15 | [post] t2 | test.swift:307:15:307:15 | t2 |
223233
| test.swift:306:15:306:15 | t2 | test.swift:307:15:307:15 | t2 |
234+
| test.swift:307:15:307:15 | [post] t2 | test.swift:308:15:308:15 | t2 |
224235
| test.swift:307:15:307:15 | t2 | test.swift:308:15:308:15 | t2 |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,13 @@ func testTuples() {
284284

285285
sink(arg: t1)
286286
sink(arg: t1.0)
287-
sink(arg: t1.1) // $ SPURIOUS: flow=277
287+
sink(arg: t1.1) // $ flow=277
288288

289289
t1.0 = source()
290290

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

296296
func testTuples2() {

0 commit comments

Comments
 (0)