Skip to content

Commit 81ac648

Browse files
authored
Swift: flow out of calls via return statements
1 parent ae6d16a commit 81ac648

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,19 @@ abstract class ReturnNode extends Node {
155155
abstract ReturnKind getKind();
156156
}
157157

158-
private module ReturnNodes { }
158+
private module ReturnNodes {
159+
class ReturnReturnNode extends ReturnNode, ExprNode {
160+
ReturnReturnNode() {
161+
exists(ReturnStmt stmt |
162+
stmt.getResult() = this.asExpr()
163+
)
164+
}
165+
166+
override ReturnKind getKind() {
167+
result instanceof NormalReturnKind
168+
}
169+
}
170+
}
159171

160172
import ReturnNodes
161173

@@ -165,7 +177,13 @@ abstract class OutNode extends Node {
165177
abstract DataFlowCall getCall(ReturnKind kind);
166178
}
167179

168-
private module OutNodes { }
180+
private module OutNodes {
181+
class CallOutNode extends OutNode, DataFlowCall {
182+
override DataFlowCall getCall(ReturnKind kind) {
183+
result = this and kind instanceof NormalReturnKind
184+
}
185+
}
186+
}
169187

170188
import OutNodes
171189

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edges
66
| test.swift:25:20:25:27 | CallExpr : | test.swift:28:18:28:21 | WriteDef : |
77
| test.swift:28:18:28:21 | ParamDecl : | test.swift:29:15:29:15 | DeclRefExpr |
88
| test.swift:28:18:28:21 | WriteDef : | test.swift:29:15:29:15 | DeclRefExpr |
9+
| test.swift:33:12:33:19 | CallExpr : | test.swift:37:15:37:29 | CallExpr |
910
nodes
1011
| test.swift:6:19:6:26 | CallExpr : | semmle.label | CallExpr : |
1112
| test.swift:7:15:7:15 | DeclRefExpr | semmle.label | DeclRefExpr |
@@ -17,9 +18,12 @@ nodes
1718
| test.swift:28:18:28:21 | WriteDef : | semmle.label | ParamDecl : |
1819
| test.swift:28:18:28:21 | WriteDef : | semmle.label | WriteDef : |
1920
| test.swift:29:15:29:15 | DeclRefExpr | semmle.label | DeclRefExpr |
21+
| test.swift:33:12:33:19 | CallExpr : | semmle.label | CallExpr : |
22+
| test.swift:37:15:37:29 | CallExpr | semmle.label | CallExpr |
2023
subpaths
2124
#select
2225
| test.swift:6:19:6:26 | CallExpr : | test.swift:7:15:7:15 | DeclRefExpr |
2326
| test.swift:6:19:6:26 | CallExpr : | test.swift:9:15:9:15 | DeclRefExpr |
2427
| test.swift:6:19:6:26 | CallExpr : | test.swift:10:15:10:15 | DeclRefExpr |
2528
| test.swift:25:20:25:27 | CallExpr : | test.swift:29:15:29:15 | DeclRefExpr |
29+
| test.swift:33:12:33:19 | CallExpr : | test.swift:37:15:37:29 | CallExpr |

0 commit comments

Comments
 (0)