Skip to content

Commit 507fdef

Browse files
authored
Swift: add more data flow tests
1 parent 81ac648 commit 507fdef

File tree

3 files changed

+66
-18
lines changed

3 files changed

+66
-18
lines changed

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,39 @@ edges
22
| test.swift:6:19:6:26 | CallExpr : | test.swift:7:15:7:15 | DeclRefExpr |
33
| test.swift:6:19:6:26 | CallExpr : | test.swift:9:15:9:15 | DeclRefExpr |
44
| test.swift:6:19:6:26 | CallExpr : | test.swift:10:15:10:15 | DeclRefExpr |
5-
| test.swift:25:20:25:27 | CallExpr : | test.swift:28:18:28:21 | ParamDecl : |
6-
| test.swift:25:20:25:27 | CallExpr : | test.swift:28:18:28:21 | WriteDef : |
7-
| test.swift:28:18:28:21 | ParamDecl : | test.swift:29:15:29:15 | DeclRefExpr |
8-
| 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 |
5+
| test.swift:25:20:25:27 | CallExpr : | test.swift:29:18:29:21 | ParamDecl : |
6+
| test.swift:25:20:25:27 | CallExpr : | test.swift:29:18:29:21 | WriteDef : |
7+
| test.swift:26:26:26:33 | CallExpr : | test.swift:29:26:29:29 | ParamDecl : |
8+
| test.swift:26:26:26:33 | CallExpr : | test.swift:29:26:29:29 | WriteDef : |
9+
| test.swift:29:18:29:21 | ParamDecl : | test.swift:30:15:30:15 | DeclRefExpr |
10+
| test.swift:29:18:29:21 | WriteDef : | test.swift:30:15:30:15 | DeclRefExpr |
11+
| test.swift:29:26:29:29 | ParamDecl : | test.swift:31:15:31:15 | DeclRefExpr |
12+
| test.swift:29:26:29:29 | WriteDef : | test.swift:31:15:31:15 | DeclRefExpr |
13+
| test.swift:35:12:35:19 | CallExpr : | test.swift:39:15:39:29 | CallExpr |
1014
nodes
1115
| test.swift:6:19:6:26 | CallExpr : | semmle.label | CallExpr : |
1216
| test.swift:7:15:7:15 | DeclRefExpr | semmle.label | DeclRefExpr |
1317
| test.swift:9:15:9:15 | DeclRefExpr | semmle.label | DeclRefExpr |
1418
| test.swift:10:15:10:15 | DeclRefExpr | semmle.label | DeclRefExpr |
1519
| test.swift:25:20:25:27 | CallExpr : | semmle.label | CallExpr : |
16-
| test.swift:28:18:28:21 | ParamDecl : | semmle.label | ParamDecl : |
17-
| test.swift:28:18:28:21 | ParamDecl : | semmle.label | WriteDef : |
18-
| test.swift:28:18:28:21 | WriteDef : | semmle.label | ParamDecl : |
19-
| test.swift:28:18:28:21 | WriteDef : | semmle.label | WriteDef : |
20-
| 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 |
20+
| test.swift:26:26:26:33 | CallExpr : | semmle.label | CallExpr : |
21+
| test.swift:29:18:29:21 | ParamDecl : | semmle.label | ParamDecl : |
22+
| test.swift:29:18:29:21 | ParamDecl : | semmle.label | WriteDef : |
23+
| test.swift:29:18:29:21 | WriteDef : | semmle.label | ParamDecl : |
24+
| test.swift:29:18:29:21 | WriteDef : | semmle.label | WriteDef : |
25+
| test.swift:29:26:29:29 | ParamDecl : | semmle.label | ParamDecl : |
26+
| test.swift:29:26:29:29 | ParamDecl : | semmle.label | WriteDef : |
27+
| test.swift:29:26:29:29 | WriteDef : | semmle.label | ParamDecl : |
28+
| test.swift:29:26:29:29 | WriteDef : | semmle.label | WriteDef : |
29+
| test.swift:30:15:30:15 | DeclRefExpr | semmle.label | DeclRefExpr |
30+
| test.swift:31:15:31:15 | DeclRefExpr | semmle.label | DeclRefExpr |
31+
| test.swift:35:12:35:19 | CallExpr : | semmle.label | CallExpr : |
32+
| test.swift:39:15:39:29 | CallExpr | semmle.label | CallExpr |
2333
subpaths
2434
#select
2535
| test.swift:6:19:6:26 | CallExpr : | test.swift:7:15:7:15 | DeclRefExpr |
2636
| test.swift:6:19:6:26 | CallExpr : | test.swift:9:15:9:15 | DeclRefExpr |
2737
| test.swift:6:19:6:26 | CallExpr : | test.swift:10:15:10:15 | DeclRefExpr |
28-
| 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 |
38+
| test.swift:25:20:25:27 | CallExpr : | test.swift:30:15:30:15 | DeclRefExpr |
39+
| test.swift:26:26:26:33 | CallExpr : | test.swift:31:15:31:15 | DeclRefExpr |
40+
| test.swift:35:12:35:19 | CallExpr : | test.swift:39:15:39:29 | CallExpr |

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| file://:0:0:0:0 | Phi | test.swift:15:15:15:15 | DeclRefExpr |
22
| file://:0:0:0:0 | Phi | test.swift:21:15:21:15 | DeclRefExpr |
3+
| file://:0:0:0:0 | Phi | test.swift:50:15:50:15 | DeclRefExpr |
34
| test.swift:6:9:6:13 | WriteDef | test.swift:7:15:7:15 | DeclRefExpr |
45
| test.swift:6:19:6:26 | CallExpr | test.swift:6:9:6:13 | WriteDef |
56
| test.swift:7:15:7:15 | DeclRefExpr | test.swift:8:10:8:10 | DeclRefExpr |
@@ -13,5 +14,17 @@
1314
| test.swift:17:10:17:10 | IntegerLiteralExpr | test.swift:17:5:17:10 | WriteDef |
1415
| test.swift:19:14:19:14 | DeclRefExpr | test.swift:19:9:19:14 | WriteDef |
1516
| test.swift:19:14:19:14 | DeclRefExpr | test.swift:19:14:19:14 | DeclRefExpr |
16-
| test.swift:28:18:28:21 | ParamDecl | test.swift:29:15:29:15 | DeclRefExpr |
17-
| test.swift:28:18:28:21 | WriteDef | test.swift:29:15:29:15 | DeclRefExpr |
17+
| test.swift:29:18:29:21 | ParamDecl | test.swift:30:15:30:15 | DeclRefExpr |
18+
| test.swift:29:18:29:21 | WriteDef | test.swift:30:15:30:15 | DeclRefExpr |
19+
| test.swift:29:26:29:29 | ParamDecl | test.swift:31:15:31:15 | DeclRefExpr |
20+
| test.swift:29:26:29:29 | WriteDef | test.swift:31:15:31:15 | DeclRefExpr |
21+
| test.swift:42:16:42:19 | ParamDecl | test.swift:45:8:45:8 | DeclRefExpr |
22+
| test.swift:42:16:42:19 | WriteDef | test.swift:45:8:45:8 | DeclRefExpr |
23+
| test.swift:43:9:43:13 | WriteDef | test.swift:46:13:46:13 | DeclRefExpr |
24+
| test.swift:43:19:43:26 | CallExpr | test.swift:43:9:43:13 | WriteDef |
25+
| test.swift:46:13:46:13 | DeclRefExpr | test.swift:46:9:46:13 | WriteDef |
26+
| test.swift:48:13:48:13 | IntegerLiteralExpr | test.swift:48:9:48:13 | WriteDef |
27+
| test.swift:58:9:58:12 | WriteDef | test.swift:59:15:59:15 | DeclRefExpr |
28+
| test.swift:58:18:58:18 | IntegerLiteralExpr | test.swift:58:9:58:12 | WriteDef |
29+
| test.swift:59:15:59:15 | DeclRefExpr | test.swift:60:23:60:23 | DeclRefExpr |
30+
| test.swift:60:23:60:23 | DeclRefExpr | test.swift:61:15:61:15 | DeclRefExpr |

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ func intraprocedural_with_local_flow() -> Void {
2222
}
2323

2424
func caller_source() -> Void {
25-
callee_sink(x: source())
25+
callee_sink(x: source(), y: 1)
26+
callee_sink(x: 1, y: source())
2627
}
2728

28-
func callee_sink(x: Int) -> Void {
29+
func callee_sink(x: Int, y: Int) -> Void {
2930
sink(arg: x)
31+
sink(arg: y)
3032
}
3133

3234
func callee_source() -> Int {
@@ -36,3 +38,25 @@ func callee_source() -> Int {
3638
func caller_sink() -> Void {
3739
sink(arg: callee_source())
3840
}
41+
42+
func branching(b: Bool) -> Void {
43+
var t1: Int = source()
44+
var t: Int = 0
45+
if(b) {
46+
t = t1;
47+
} else {
48+
t = 1;
49+
}
50+
sink(arg: t)
51+
}
52+
53+
func inoutSource(arg: inout Int) -> Void {
54+
arg = source()
55+
}
56+
57+
func inoutUser() {
58+
var x: Int = 0
59+
sink(arg: x)
60+
inoutSource(arg: &x)
61+
sink(arg: x)
62+
}

0 commit comments

Comments
 (0)