Skip to content

Commit 23f0dd5

Browse files
committed
Swift: Support MAD tuple content flow.
1 parent b4b2338 commit 23f0dd5

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

swift/ql/lib/codeql/swift/dataflow/ExternalFlow.qll

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,25 @@ private predicate parseField(AccessPathToken c, Content::FieldContent f) {
476476
)
477477
}
478478

479-
private predicate parseEnum(AccessPathToken c, Content::EnumContent f) {
479+
private predicate parseTuple(AccessPathToken c, Content::TupleContent t) {
480+
c.getName() = "TupleElement" and
481+
t.getIndex() = c.getAnArgument().toInt()
482+
}
483+
484+
private predicate parseEnum(AccessPathToken c, Content::EnumContent e) {
480485
c.getName() = "EnumElement" and
481-
c.getAnArgument() = f.getSignature()
486+
c.getAnArgument() = e.getSignature()
482487
or
483488
c.getName() = "OptionalSome" and
484-
f.getSignature() = "some:0"
489+
e.getSignature() = "some:0"
485490
}
486491

487492
/** Holds if the specification component parses as a `Content`. */
488493
predicate parseContent(AccessPathToken component, Content content) {
489494
parseField(component, content)
490495
or
496+
parseTuple(component, content)
497+
or
491498
parseEnum(component, content)
492499
or
493500
component.getName() = "ArrayElement" and

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ private string getContentSpecific(ContentSet cs) {
110110
result = "Field[" + c.getField().getName() + "]"
111111
)
112112
or
113+
exists(Content::TupleContent c |
114+
cs.isSingleton(c) and
115+
result = "TupleElement[" + c.getIndex().toString() + "]"
116+
)
117+
or
113118
exists(Content::EnumContent c |
114119
cs.isSingleton(c) and
115120
result = "EnumElement[" + c.getSignature() + "]"

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,17 @@ edges
182182
| test.swift:369:13:369:13 | t [Tuple element at index 1] | test.swift:369:13:369:15 | .1 |
183183
| test.swift:369:13:369:15 | .1 | test.swift:369:12:369:19 | (...) [Tuple element at index 0] |
184184
| test.swift:375:14:375:26 | (...) [Tuple element at index 1] | test.swift:376:30:376:30 | t1 [Tuple element at index 1] |
185+
| test.swift:375:14:375:26 | (...) [Tuple element at index 1] | test.swift:377:30:377:30 | t1 [Tuple element at index 1] |
185186
| test.swift:375:14:375:26 | (...) [Tuple element at index 1] | test.swift:380:15:380:15 | t1 [Tuple element at index 1] |
186187
| test.swift:375:18:375:25 | call to source() | test.swift:375:14:375:26 | (...) [Tuple element at index 1] |
187188
| test.swift:376:14:376:32 | call to tupleShiftLeft1(_:) [Tuple element at index 0] | test.swift:381:15:381:15 | t2 [Tuple element at index 0] |
188189
| test.swift:376:30:376:30 | t1 [Tuple element at index 1] | test.swift:368:22:368:36 | t [Tuple element at index 1] |
189190
| test.swift:376:30:376:30 | t1 [Tuple element at index 1] | test.swift:376:14:376:32 | call to tupleShiftLeft1(_:) [Tuple element at index 0] |
191+
| test.swift:377:14:377:32 | call to tupleShiftLeft2(_:) [Tuple element at index 0] | test.swift:383:15:383:15 | t3 [Tuple element at index 0] |
192+
| test.swift:377:30:377:30 | t1 [Tuple element at index 1] | test.swift:377:14:377:32 | call to tupleShiftLeft2(_:) [Tuple element at index 0] |
190193
| test.swift:380:15:380:15 | t1 [Tuple element at index 1] | test.swift:380:15:380:18 | .1 |
191194
| test.swift:381:15:381:15 | t2 [Tuple element at index 0] | test.swift:381:15:381:18 | .0 |
195+
| test.swift:383:15:383:15 | t3 [Tuple element at index 0] | test.swift:383:15:383:18 | .0 |
192196
| test.swift:394:16:394:21 | v | test.swift:394:61:394:61 | v |
193197
| test.swift:394:61:394:61 | v | test.swift:394:45:394:62 | call to ... [mySingle:0] |
194198
| test.swift:396:18:396:23 | v | test.swift:396:59:396:59 | v |
@@ -607,10 +611,14 @@ nodes
607611
| test.swift:375:18:375:25 | call to source() | semmle.label | call to source() |
608612
| test.swift:376:14:376:32 | call to tupleShiftLeft1(_:) [Tuple element at index 0] | semmle.label | call to tupleShiftLeft1(_:) [Tuple element at index 0] |
609613
| test.swift:376:30:376:30 | t1 [Tuple element at index 1] | semmle.label | t1 [Tuple element at index 1] |
614+
| test.swift:377:14:377:32 | call to tupleShiftLeft2(_:) [Tuple element at index 0] | semmle.label | call to tupleShiftLeft2(_:) [Tuple element at index 0] |
615+
| test.swift:377:30:377:30 | t1 [Tuple element at index 1] | semmle.label | t1 [Tuple element at index 1] |
610616
| test.swift:380:15:380:15 | t1 [Tuple element at index 1] | semmle.label | t1 [Tuple element at index 1] |
611617
| test.swift:380:15:380:18 | .1 | semmle.label | .1 |
612618
| test.swift:381:15:381:15 | t2 [Tuple element at index 0] | semmle.label | t2 [Tuple element at index 0] |
613619
| test.swift:381:15:381:18 | .0 | semmle.label | .0 |
620+
| test.swift:383:15:383:15 | t3 [Tuple element at index 0] | semmle.label | t3 [Tuple element at index 0] |
621+
| test.swift:383:15:383:18 | .0 | semmle.label | .0 |
614622
| test.swift:394:16:394:21 | v | semmle.label | v |
615623
| test.swift:394:45:394:62 | call to ... [mySingle:0] | semmle.label | call to ... [mySingle:0] |
616624
| test.swift:394:61:394:61 | v | semmle.label | v |
@@ -944,6 +952,7 @@ subpaths
944952
| test.swift:364:15:364:15 | b | test.swift:351:31:351:38 | call to source() | test.swift:364:15:364:15 | b | result |
945953
| test.swift:380:15:380:18 | .1 | test.swift:375:18:375:25 | call to source() | test.swift:380:15:380:18 | .1 | result |
946954
| test.swift:381:15:381:18 | .0 | test.swift:375:18:375:25 | call to source() | test.swift:381:15:381:18 | .0 | result |
955+
| test.swift:383:15:383:18 | .0 | test.swift:375:18:375:25 | call to source() | test.swift:383:15:383:18 | .0 | result |
947956
| test.swift:428:19:428:19 | a | test.swift:422:19:422:26 | call to source() | test.swift:428:19:428:19 | a | result |
948957
| test.swift:437:19:437:19 | x | test.swift:422:19:422:26 | call to source() | test.swift:437:19:437:19 | x | result |
949958
| test.swift:453:19:453:19 | b | test.swift:444:26:444:33 | call to source() | test.swift:453:19:453:19 | b | result |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func testTuples3() {
380380
sink(arg: t1.1) // $ flow=375
381381
sink(arg: t2.0) // $ flow=375
382382
sink(arg: t2.1)
383-
sink(arg: t3.0) // $ MISSING: flow=375
383+
sink(arg: t3.0) // $ flow=375
384384
sink(arg: t3.1)
385385
}
386386

0 commit comments

Comments
 (0)