Skip to content

Commit 52b78b6

Browse files
committed
Swift: Don't assume we know the call target statically in 'TInOutUpdateNode'.
1 parent ff6b8c5 commit 52b78b6

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ private module Cached {
6565
TExprNode(CfgNode n, Expr e) { hasExprNode(n, e) } or
6666
TSsaDefinitionNode(Ssa::Definition def) or
6767
TInoutReturnNode(ParamDecl param) { param.isInout() } or
68-
TInOutUpdateNode(ParamDecl param, CallExpr call) {
69-
param.isInout() and
70-
call.getStaticTarget() = param.getDeclaringFunction()
71-
} or
68+
TInOutUpdateNode(Argument arg) { arg.getExpr() instanceof InOutExpr } or
7269
TSummaryNode(FlowSummary::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state)
7370

7471
private predicate hasExprNode(CfgNode n, Expr e) {
@@ -281,23 +278,22 @@ private module OutNodes {
281278
}
282279

283280
class InOutUpdateNode extends OutNode, TInOutUpdateNode, NodeImpl {
284-
ParamDecl param;
285-
CallExpr call;
281+
Argument arg;
286282

287-
InOutUpdateNode() { this = TInOutUpdateNode(param, call) }
283+
InOutUpdateNode() { this = TInOutUpdateNode(arg) }
288284

289285
override DataFlowCall getCall(ReturnKind kind) {
290-
result.asCall().getExpr() = call and
291-
kind.(ParamReturnKind).getIndex() = param.getIndex()
286+
result.asCall().getExpr() = arg.getApplyExpr() and
287+
kind.(ParamReturnKind).getIndex() = arg.getIndex()
292288
}
293289

294290
override DataFlowCallable getEnclosingCallable() {
295291
result = this.getCall(_).getEnclosingCallable()
296292
}
297293

298-
override Location getLocationImpl() { result = call.getLocation() }
294+
override Location getLocationImpl() { result = arg.getLocation() }
299295

300-
override string toStringImpl() { result = param.toString() }
296+
override string toStringImpl() { result = arg.toString() }
301297
}
302298
}
303299

swift/ql/lib/codeql/swift/elements/expr/Argument.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ class Argument extends ArgumentBase {
55
override string toString() { result = this.getLabel() + ": " + this.getExpr().toString() }
66

77
int getIndex() { any(ApplyExpr apply).getArgument(result) = this }
8+
9+
ApplyExpr getApplyExpr() { result.getAnArgument() = this }
810
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ edges
1212
| test.swift:29:26:29:29 | y : | test.swift:31:15:31:15 | y |
1313
| test.swift:35:12:35:19 | call to source() : | test.swift:39:15:39:29 | call to callee_source() |
1414
| test.swift:43:19:43:26 | call to source() : | test.swift:50:15:50:15 | t |
15-
| test.swift:53:1:56:1 | arg[return] : | test.swift:61:5:61:24 | arg : |
15+
| test.swift:53:1:56:1 | arg[return] : | test.swift:61:17:61:23 | arg: &... : |
1616
| test.swift:54:11:54:18 | call to source() : | test.swift:53:1:56:1 | arg[return] : |
17-
| test.swift:61:5:61:24 | arg : | test.swift:62:15:62:15 | x |
17+
| test.swift:61:17:61:23 | arg: &... : | test.swift:62:15:62:15 | x |
1818
| test.swift:65:16:65:28 | WriteDef : | test.swift:65:1:70:1 | arg2[return] : |
1919
| test.swift:65:16:65:28 | arg1 : | test.swift:65:1:70:1 | arg2[return] : |
2020
| test.swift:73:18:73:25 | call to source() : | test.swift:75:21:75:22 | &... : |
21-
| test.swift:75:5:75:33 | arg2 : | test.swift:77:15:77:15 | y |
2221
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | WriteDef : |
2322
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : |
24-
| test.swift:75:21:75:22 | &... : | test.swift:75:5:75:33 | arg2 : |
25-
| test.swift:80:1:82:1 | arg[return] : | test.swift:97:9:97:41 | arg : |
23+
| test.swift:75:21:75:22 | &... : | test.swift:75:25:75:32 | arg2: &... : |
24+
| test.swift:75:25:75:32 | arg2: &... : | test.swift:77:15:77:15 | y |
25+
| test.swift:80:1:82:1 | arg[return] : | test.swift:97:34:97:40 | arg: &... : |
2626
| test.swift:81:11:81:18 | call to source() : | test.swift:80:1:82:1 | arg[return] : |
27-
| test.swift:84:1:91:1 | arg[return] : | test.swift:104:9:104:54 | arg : |
27+
| test.swift:84:1:91:1 | arg[return] : | test.swift:104:35:104:41 | arg: &... : |
2828
| test.swift:86:15:86:22 | call to source() : | test.swift:84:1:91:1 | arg[return] : |
2929
| test.swift:89:15:89:22 | call to source() : | test.swift:84:1:91:1 | arg[return] : |
30-
| test.swift:97:9:97:41 | arg : | test.swift:98:19:98:19 | x |
31-
| test.swift:104:9:104:54 | arg : | test.swift:105:19:105:19 | x |
30+
| test.swift:97:34:97:40 | arg: &... : | test.swift:98:19:98:19 | x |
31+
| test.swift:104:35:104:41 | arg: &... : | test.swift:105:19:105:19 | x |
3232
| test.swift:109:9:109:14 | WriteDef : | test.swift:110:12:110:12 | arg : |
3333
| test.swift:109:9:109:14 | arg : | test.swift:110:12:110:12 | arg : |
3434
| test.swift:113:14:113:19 | WriteDef : | test.swift:114:19:114:19 | arg : |
@@ -88,25 +88,25 @@ nodes
8888
| test.swift:50:15:50:15 | t | semmle.label | t |
8989
| test.swift:53:1:56:1 | arg[return] : | semmle.label | arg[return] : |
9090
| test.swift:54:11:54:18 | call to source() : | semmle.label | call to source() : |
91-
| test.swift:61:5:61:24 | arg : | semmle.label | arg : |
91+
| test.swift:61:17:61:23 | arg: &... : | semmle.label | arg: &... : |
9292
| test.swift:62:15:62:15 | x | semmle.label | x |
9393
| test.swift:65:1:70:1 | arg2[return] : | semmle.label | arg2[return] : |
9494
| test.swift:65:16:65:28 | WriteDef : | semmle.label | WriteDef : |
9595
| test.swift:65:16:65:28 | WriteDef : | semmle.label | arg1 : |
9696
| test.swift:65:16:65:28 | arg1 : | semmle.label | WriteDef : |
9797
| test.swift:65:16:65:28 | arg1 : | semmle.label | arg1 : |
9898
| test.swift:73:18:73:25 | call to source() : | semmle.label | call to source() : |
99-
| test.swift:75:5:75:33 | arg2 : | semmle.label | arg2 : |
10099
| test.swift:75:21:75:22 | &... : | semmle.label | &... : |
100+
| test.swift:75:25:75:32 | arg2: &... : | semmle.label | arg2: &... : |
101101
| test.swift:77:15:77:15 | y | semmle.label | y |
102102
| test.swift:80:1:82:1 | arg[return] : | semmle.label | arg[return] : |
103103
| test.swift:81:11:81:18 | call to source() : | semmle.label | call to source() : |
104104
| test.swift:84:1:91:1 | arg[return] : | semmle.label | arg[return] : |
105105
| test.swift:86:15:86:22 | call to source() : | semmle.label | call to source() : |
106106
| test.swift:89:15:89:22 | call to source() : | semmle.label | call to source() : |
107-
| test.swift:97:9:97:41 | arg : | semmle.label | arg : |
107+
| test.swift:97:34:97:40 | arg: &... : | semmle.label | arg: &... : |
108108
| test.swift:98:19:98:19 | x | semmle.label | x |
109-
| test.swift:104:9:104:54 | arg : | semmle.label | arg : |
109+
| test.swift:104:35:104:41 | arg: &... : | semmle.label | arg: &... : |
110110
| test.swift:105:19:105:19 | x | semmle.label | x |
111111
| test.swift:109:9:109:14 | WriteDef : | semmle.label | WriteDef : |
112112
| test.swift:109:9:109:14 | WriteDef : | semmle.label | arg : |
@@ -155,8 +155,8 @@ nodes
155155
| test.swift:157:16:157:23 | call to source() : | semmle.label | call to source() : |
156156
| test.swift:159:16:159:29 | call to ... : | semmle.label | call to ... : |
157157
subpaths
158-
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | WriteDef : | test.swift:65:1:70:1 | arg2[return] : | test.swift:75:5:75:33 | arg2 : |
159-
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : | test.swift:65:1:70:1 | arg2[return] : | test.swift:75:5:75:33 | arg2 : |
158+
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | WriteDef : | test.swift:65:1:70:1 | arg2[return] : | test.swift:75:25:75:32 | arg2: &... : |
159+
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : | test.swift:65:1:70:1 | arg2[return] : | test.swift:75:25:75:32 | arg2: &... : |
160160
| test.swift:114:19:114:19 | arg : | test.swift:109:9:109:14 | WriteDef : | test.swift:110:12:110:12 | arg : | test.swift:114:12:114:22 | call to ... : |
161161
| test.swift:114:19:114:19 | arg : | test.swift:109:9:109:14 | arg : | test.swift:110:12:110:12 | arg : | test.swift:114:12:114:22 | call to ... : |
162162
| test.swift:114:19:114:19 | arg : | test.swift:123:10:123:13 | WriteDef : | test.swift:124:16:124:16 | i : | test.swift:114:12:114:22 | call to ... : |

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
| test.swift:59:18:59:18 | 0 | test.swift:59:9:59:12 | WriteDef |
3030
| test.swift:60:15:60:15 | x | test.swift:61:23:61:23 | x |
3131
| test.swift:61:5:61:24 | WriteDef | test.swift:62:15:62:15 | x |
32-
| test.swift:61:5:61:24 | arg | test.swift:61:5:61:24 | WriteDef |
32+
| test.swift:61:17:61:23 | arg: &... | test.swift:61:5:61:24 | WriteDef |
3333
| test.swift:61:23:61:23 | x | test.swift:61:22:61:23 | &... |
3434
| test.swift:65:16:65:28 | WriteDef | test.swift:66:21:66:21 | arg1 |
3535
| test.swift:65:16:65:28 | arg1 | test.swift:66:21:66:21 | arg1 |
@@ -47,9 +47,9 @@
4747
| test.swift:74:18:74:18 | 0 | test.swift:74:9:74:12 | WriteDef |
4848
| test.swift:75:5:75:33 | WriteDef | test.swift:76:15:76:15 | x |
4949
| test.swift:75:5:75:33 | WriteDef | test.swift:77:15:77:15 | y |
50-
| test.swift:75:5:75:33 | arg1 | test.swift:75:5:75:33 | WriteDef |
51-
| test.swift:75:5:75:33 | arg2 | test.swift:75:5:75:33 | WriteDef |
50+
| test.swift:75:15:75:22 | arg1: &... | test.swift:75:5:75:33 | WriteDef |
5251
| test.swift:75:22:75:22 | x | test.swift:75:21:75:22 | &... |
52+
| test.swift:75:25:75:32 | arg2: &... | test.swift:75:5:75:33 | WriteDef |
5353
| test.swift:75:32:75:32 | y | test.swift:75:31:75:32 | &... |
5454
| test.swift:81:5:81:18 | WriteDef | test.swift:80:1:82:1 | arg[return] |
5555
| test.swift:81:11:81:18 | call to source() | test.swift:81:5:81:18 | WriteDef |
@@ -66,13 +66,13 @@
6666
| test.swift:95:22:95:22 | 0 | test.swift:95:13:95:16 | WriteDef |
6767
| test.swift:96:19:96:19 | x | test.swift:97:40:97:40 | x |
6868
| test.swift:97:9:97:41 | WriteDef | test.swift:98:19:98:19 | x |
69-
| test.swift:97:9:97:41 | arg | test.swift:97:9:97:41 | WriteDef |
69+
| test.swift:97:34:97:40 | arg: &... | test.swift:97:9:97:41 | WriteDef |
7070
| test.swift:97:40:97:40 | x | test.swift:97:39:97:40 | &... |
7171
| test.swift:102:13:102:16 | WriteDef | test.swift:103:19:103:19 | x |
7272
| test.swift:102:22:102:22 | 0 | test.swift:102:13:102:16 | WriteDef |
7373
| test.swift:103:19:103:19 | x | test.swift:104:41:104:41 | x |
7474
| test.swift:104:9:104:54 | WriteDef | test.swift:105:19:105:19 | x |
75-
| test.swift:104:9:104:54 | arg | test.swift:104:9:104:54 | WriteDef |
75+
| test.swift:104:35:104:41 | arg: &... | test.swift:104:9:104:54 | WriteDef |
7676
| test.swift:104:41:104:41 | x | test.swift:104:40:104:41 | &... |
7777
| test.swift:109:9:109:14 | WriteDef | test.swift:110:12:110:12 | arg |
7878
| test.swift:109:9:109:14 | arg | test.swift:110:12:110:12 | arg |

0 commit comments

Comments
 (0)