Skip to content

Commit 1082b1d

Browse files
committed
Swift: use PostUpdateNodeImpl for more postupdate nodes
1 parent 0d79158 commit 1082b1d

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private class KeyPathComponentNodeImpl extends TKeyPathComponentNode, NodeImpl {
5757
KeyPathComponent getComponent() { result = component }
5858
}
5959

60-
private class KeyPathComponentPostUpdateNode extends TKeyPathComponentPostUpdateNode, NodeImpl {
60+
private class KeyPathComponentPostUpdateNode extends TKeyPathComponentPostUpdateNode, NodeImpl, PostUpdateNodeImpl {
6161
KeyPathComponent component;
6262

6363
KeyPathComponentPostUpdateNode() { this = TKeyPathComponentPostUpdateNode(component) }
@@ -70,6 +70,10 @@ private class KeyPathComponentPostUpdateNode extends TKeyPathComponentPostUpdate
7070
result.asSourceCallable() = component.getKeyPathExpr()
7171
}
7272

73+
override KeyPathComponentNodeImpl getPreUpdateNode() {
74+
result.getComponent() = this.getComponent()
75+
}
76+
7377
KeyPathComponent getComponent() { result = component }
7478
}
7579

@@ -448,7 +452,7 @@ class KeyPathReturnPostUpdateNode extends NodeImpl, ParameterNodeImpl, PostUpdat
448452

449453
KeyPathReturnPostUpdateNode() { this = TKeyPathReturnPostUpdateNode(exit) }
450454

451-
override KeyPathParameterNode getPreUpdateNode() {
455+
override KeyPathReturnNodeImpl getPreUpdateNode() {
452456
result.getKeyPathExpr() = this.getKeyPathExpr()
453457
}
454458

@@ -831,24 +835,6 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
831835
c instanceof OptionalSomeContentSet
832836
)
833837
or
834-
// store through a component in a key-path expression chain
835-
exists(KeyPathComponent component |
836-
component = node2.(KeyPathComponentPostUpdateNode).getComponent() and
837-
(
838-
c.isSingleton(any(Content::FieldContent ct | ct.getField() = component.getDeclRef()))
839-
or
840-
c.isSingleton(any(Content::ArrayContent ac)) and
841-
component.isSubscript()
842-
)
843-
|
844-
// the previous node is either the next element in the chain
845-
node1.(KeyPathComponentPostUpdateNode).getComponent() = component.getNextComponent()
846-
or
847-
// or the return node, if this is the last component in the chain
848-
not exists(component.getNextComponent()) and
849-
node1.(KeyPathReturnPostUpdateNode).getKeyPathExpr() = component.getKeyPathExpr()
850-
)
851-
or
852838
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1.(FlowSummaryNode).getSummaryNode(), c,
853839
node2.(FlowSummaryNode).getSummaryNode())
854840
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ subpaths
10011001
| test.swift:765:29:765:29 | s [some:0, x] | test.swift:655:8:655:12 | s [some:0, x] | test.swift:655:3:657:3 | self[return] [s, some:0, x] | test.swift:765:14:765:30 | call to S2_Optional.init(s:) [s, some:0, x] |
10021002
| test.swift:767:15:767:15 | s2 [s, some:0, x] | test.swift:766:13:766:29 | enter #keyPath(...) [s, some:0, x] | test.swift:766:13:766:29 | exit #keyPath(...) | test.swift:767:15:767:28 | \\...[...] |
10031003
| test.swift:774:3:774:16 | \\...[...] | test.swift:773:11:773:17 | [post] exit #keyPath(...) | test.swift:773:11:773:17 | [post] enter #keyPath(...) [s, x] | test.swift:774:3:774:3 | [post] s2 [s, x] |
1004+
| test.swift:774:3:774:16 | \\...[...] | test.swift:773:11:773:17 | [post] exit #keyPath(...) | test.swift:773:15:773:15 | [post] KeyPathComponent [s, x] | test.swift:774:3:774:3 | [post] s2 [s, x] |
10041005
| test.swift:775:13:775:13 | s2 [s, x] | test.swift:632:7:632:7 | self [s, x] | file://:0:0:0:0 | .s [x] | test.swift:775:13:775:16 | .s [x] |
10051006
| test.swift:775:13:775:16 | .s [x] | test.swift:615:7:615:7 | self [x] | file://:0:0:0:0 | .x | test.swift:775:13:775:18 | .x |
10061007
#select

0 commit comments

Comments
 (0)