Skip to content

Commit 9f64622

Browse files
authored
Swift: data flow configurations working
1 parent d326b3a commit 9f64622

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ module Ssa {
6767
or
6868
exists(VarDecl var, BasicBlock bb, int blockIndex, PatternBindingDecl pbd |
6969
this.definesAt(var, bb, blockIndex) and
70-
pbd.getAPattern() = bb.getNode(blockIndex).getNode() and
71-
value.getNode() = var.getParentInitializer()
70+
pbd.getAPattern() = bb.getNode(blockIndex).getNode().asAstNode() and
71+
value.getNode().asAstNode() = var.getParentInitializer()
7272
)
7373
}
7474
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ class DataFlowType extends TDataFlowType {
188188
}
189189

190190
/** Gets the type of `n` used for type pruning. */
191-
DataFlowType getNodeType(NodeImpl n) { none() }
191+
DataFlowType getNodeType(NodeImpl n) {
192+
any() // return the singleton DataFlowType until we support type pruning for Swift
193+
}
192194

193195
/** Gets a string representation of a `DataFlowType`. */
194196
string ppReprType(DataFlowType t) { result = t.toString() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class PostUpdateNode extends Node instanceof PostUpdateNodeImpl {
9898
}
9999

100100
/** Gets a node corresponding to expression `e`. */
101-
ExprNode exprNode(DataFlowExpr e) { none() }
101+
ExprNode exprNode(DataFlowExpr e) { result.asExpr() = e }
102102

103103
/**
104104
* Gets the node corresponding to the value of parameter `p` at function entry.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
edges
2+
| test.swift:6:19:6:26 | CallExpr : | test.swift:7:15:7:15 | DeclRefExpr |
3+
| test.swift:6:19:6:26 | CallExpr : | test.swift:9:15:9:15 | DeclRefExpr |
4+
| test.swift:6:19:6:26 | CallExpr : | test.swift:10:15:10:15 | DeclRefExpr |
5+
nodes
6+
| test.swift:6:19:6:26 | CallExpr : | semmle.label | CallExpr : |
7+
| test.swift:7:15:7:15 | DeclRefExpr | semmle.label | DeclRefExpr |
8+
| test.swift:9:15:9:15 | DeclRefExpr | semmle.label | DeclRefExpr |
9+
| test.swift:10:15:10:15 | DeclRefExpr | semmle.label | DeclRefExpr |
10+
subpaths
11+
#select
12+
| test.swift:6:19:6:26 | CallExpr : | test.swift:7:15:7:15 | DeclRefExpr |
13+
| test.swift:6:19:6:26 | CallExpr : | test.swift:9:15:9:15 | DeclRefExpr |
14+
| test.swift:6:19:6:26 | CallExpr : | test.swift:10:15:10:15 | DeclRefExpr |

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ class TestConfiguration extends DataFlow::Configuration {
1212
override predicate isSink(DataFlow::Node sink) {
1313
exists(CallExpr sinkCall |
1414
sinkCall.getStaticTarget().getName() = "sink" and
15-
sinkCall.getAnArgument() = sink.asExpr()
15+
sinkCall.getAnArgument().getExpr() = sink.asExpr()
1616
)
1717
}
1818

1919
override int explorationLimit() { result = 100 }
2020
}
2121

22-
from DataFlow::PartialPathNode src, DataFlow::PartialPathNode sink, TestConfiguration test
22+
from DataFlow::PathNode src, DataFlow::PathNode sink, TestConfiguration test
2323
where
24-
//test.isSource(src) and
25-
// test.isSink(sink) and
26-
//DataFlow::localFlow(src, sink)
27-
test.hasPartialFlow(src, sink, _)
24+
test.hasFlowPath(src, sink)
2825
select src, sink

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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 |
33
| test.swift:6:9:6:13 | WriteDef | test.swift:7:15:7:15 | DeclRefExpr |
4+
| test.swift:6:19:6:26 | CallExpr | test.swift:6:9:6:13 | WriteDef |
45
| test.swift:7:15:7:15 | DeclRefExpr | test.swift:8:10:8:10 | DeclRefExpr |
56
| test.swift:8:5:8:10 | WriteDef | test.swift:10:15:10:15 | DeclRefExpr |
67
| test.swift:8:10:8:10 | DeclRefExpr | test.swift:8:5:8:10 | WriteDef |

0 commit comments

Comments
 (0)