Skip to content

Commit 33bc7ea

Browse files
committed
Swift: Fix CFG for key-path expressions.
1 parent 859b305 commit 33bc7ea

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module CfgScope {
5858
}
5959

6060
private class KeyPathScope extends Range_ instanceof KeyPathExpr {
61-
AstControlFlowTree tree;
61+
KeyPathControlFlowTree tree;
6262

6363
KeyPathScope() { tree.getAst() = this }
6464

@@ -76,6 +76,12 @@ module CfgScope {
7676

7777
final override predicate exit(ControlFlowElement last, Completion c) { last(tree, last, c) }
7878
}
79+
80+
private class KeyPathControlFlowTree extends StandardPostOrderTree, KeyPathElement {
81+
final override ControlFlowElement getChildElement(int i) {
82+
result.asAstNode() = expr.getComponent(i)
83+
}
84+
}
7985
}
8086

8187
/** Holds if `first` is first executed when entering `scope`. */
@@ -88,6 +94,14 @@ predicate succExit(CfgScope::Range_ scope, ControlFlowElement last, Completion c
8894
scope.exit(last, c)
8995
}
9096

97+
private class KeyPathComponentTree extends AstStandardPostOrderTree {
98+
override KeyPathComponent ast;
99+
100+
final override ControlFlowElement getChildElement(int i) {
101+
result.asAstNode() = ast.getSubscriptArgument(i).getExpr().getFullyConverted()
102+
}
103+
}
104+
91105
/**
92106
* Control-flow for statements.
93107
*/

0 commit comments

Comments
 (0)