Skip to content

Commit fca1afa

Browse files
authored
Swift: fix inout parameter conflation at return
1 parent 8d4830c commit fca1afa

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ private module Cached {
7373
}
7474

7575
private predicate localSsaFlowStepUseUse(Ssa::Definition def, Node nodeFrom, Node nodeTo) {
76-
def.adjacentReadPair(nodeFrom.getCfgNode(), nodeTo.getCfgNode())
76+
def.adjacentReadPair(nodeFrom.getCfgNode(), nodeTo.getCfgNode()) and
77+
(
78+
nodeTo instanceof InoutReturnNode
79+
implies
80+
nodeTo.(InoutReturnNode).getParameter() = def.getSourceVariable()
81+
)
7782
}
7883

7984
private predicate localFlowStepCommon(Node nodeFrom, Node nodeTo) {
@@ -84,7 +89,12 @@ private module Cached {
8489
or
8590
// step from def to first read
8691
nodeFrom.asDefinition() = def and
87-
nodeTo.getCfgNode() = def.getAFirstRead()
92+
nodeTo.getCfgNode() = def.getAFirstRead() and
93+
(
94+
nodeTo instanceof InoutReturnNode
95+
implies
96+
nodeTo.(InoutReturnNode).getParameter() = def.getSourceVariable()
97+
)
8898
or
8999
// use-use flow
90100
localSsaFlowStepUseUse(def, nodeFrom, nodeTo)

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ edges
1515
| test.swift:54:11:54:18 | call to source : | test.swift:55:5:55:5 | arg[return] : |
1616
| test.swift:55:5:55:5 | arg[return] : | test.swift:61:5:61:24 | arg : |
1717
| test.swift:61:5:61:24 | arg : | test.swift:62:15:62:15 | x |
18-
| test.swift:65:16:65:28 | WriteDef : | test.swift:69:5:69:5 | arg1[return] : |
1918
| test.swift:65:16:65:28 | WriteDef : | test.swift:69:5:69:5 | arg2[return] : |
20-
| test.swift:65:16:65:28 | arg1 : | test.swift:69:5:69:5 | arg1[return] : |
2119
| test.swift:65:16:65:28 | arg1 : | test.swift:69:5:69:5 | arg2[return] : |
2220
| test.swift:73:18:73:25 | call to source : | test.swift:75:21:75:22 | &... : |
23-
| test.swift:75:5:75:33 | arg1 : | test.swift:76:15:76:15 | x |
2421
| test.swift:75:5:75:33 | arg2 : | test.swift:77:15:77:15 | y |
2522
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | WriteDef : |
2623
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : |
27-
| test.swift:75:21:75:22 | &... : | test.swift:75:5:75:33 | arg1 : |
2824
| test.swift:75:21:75:22 | &... : | test.swift:75:5:75:33 | arg2 : |
2925
nodes
3026
| test.swift:6:19:6:26 | call to source : | semmle.label | call to source : |
@@ -55,18 +51,13 @@ nodes
5551
| test.swift:65:16:65:28 | WriteDef : | semmle.label | arg1 : |
5652
| test.swift:65:16:65:28 | arg1 : | semmle.label | WriteDef : |
5753
| test.swift:65:16:65:28 | arg1 : | semmle.label | arg1 : |
58-
| test.swift:69:5:69:5 | arg1[return] : | semmle.label | arg1[return] : |
5954
| test.swift:69:5:69:5 | arg2[return] : | semmle.label | arg2[return] : |
6055
| test.swift:73:18:73:25 | call to source : | semmle.label | call to source : |
61-
| test.swift:75:5:75:33 | arg1 : | semmle.label | arg1 : |
6256
| test.swift:75:5:75:33 | arg2 : | semmle.label | arg2 : |
6357
| test.swift:75:21:75:22 | &... : | semmle.label | &... : |
64-
| test.swift:76:15:76:15 | x | semmle.label | x |
6558
| test.swift:77:15:77:15 | y | semmle.label | y |
6659
subpaths
67-
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | WriteDef : | test.swift:69:5:69:5 | arg1[return] : | test.swift:75:5:75:33 | arg1 : |
6860
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | WriteDef : | test.swift:69:5:69:5 | arg2[return] : | test.swift:75:5:75:33 | arg2 : |
69-
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : | test.swift:69:5:69:5 | arg1[return] : | test.swift:75:5:75:33 | arg1 : |
7061
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : | test.swift:69:5:69:5 | arg2[return] : | test.swift:75:5:75:33 | arg2 : |
7162
#select
7263
| test.swift:7:15:7:15 | t1 | test.swift:6:19:6:26 | call to source : | test.swift:7:15:7:15 | t1 | result |
@@ -77,5 +68,4 @@ subpaths
7768
| test.swift:39:15:39:29 | call to callee_source | test.swift:35:12:35:19 | call to source : | test.swift:39:15:39:29 | call to callee_source | result |
7869
| test.swift:50:15:50:15 | t | test.swift:43:19:43:26 | call to source : | test.swift:50:15:50:15 | t | result |
7970
| test.swift:62:15:62:15 | x | test.swift:54:11:54:18 | call to source : | test.swift:62:15:62:15 | x | result |
80-
| test.swift:76:15:76:15 | x | test.swift:73:18:73:25 | call to source : | test.swift:76:15:76:15 | x | result |
8171
| test.swift:77:15:77:15 | y | test.swift:73:18:73:25 | call to source : | test.swift:77:15:77:15 | y | result |

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
| test.swift:66:9:66:15 | WriteDef | test.swift:68:12:68:12 | temp |
3939
| test.swift:66:21:66:21 | arg1 | test.swift:66:9:66:15 | WriteDef |
4040
| test.swift:67:5:67:12 | WriteDef | test.swift:69:5:69:5 | arg1[return] |
41-
| test.swift:67:5:67:12 | WriteDef | test.swift:69:5:69:5 | arg2[return] |
4241
| test.swift:67:12:67:12 | arg2 | test.swift:67:5:67:12 | WriteDef |
43-
| test.swift:68:5:68:12 | WriteDef | test.swift:69:5:69:5 | arg1[return] |
4442
| test.swift:68:5:68:12 | WriteDef | test.swift:69:5:69:5 | arg2[return] |
4543
| test.swift:68:12:68:12 | temp | test.swift:68:5:68:12 | WriteDef |
4644
| test.swift:73:9:73:12 | WriteDef | test.swift:75:22:75:22 | x |

0 commit comments

Comments
 (0)