Skip to content

Commit 4e1b44a

Browse files
d10cMathiasVP
authored andcommitted
Swift: port simpleAstFlowStep/hasAliasedAccess
1 parent 21a369d commit 4e1b44a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,21 @@ private module OutNodes {
798798

799799
import OutNodes
800800

801+
/**
802+
* Holds if there is a data flow step from `e1` to `e2` that only steps from
803+
* child to parent in the AST.
804+
*/
805+
private predicate simpleAstFlowStep(Expr e1, Expr e2) {
806+
e2.(IfExpr).getBranch(_) = e1
807+
or
808+
e2.(AssignExpr).getSource() = e1
809+
or
810+
e2.(ArrayExpr).getAnElement() = e1
811+
}
812+
801813
private predicate closureFlowStep(Expr e1, Expr e2) {
802-
// simpleLocalFlowStep(exprNode(e1), exprNode(e2)) // TODO: find out why the java version uses simpleAstFlowStep... probably due to non-monotonic recursion
803-
// or
814+
simpleAstFlowStep(e1, e2)
815+
or
804816
exists(Ssa::WriteDefinition def |
805817
def.getARead().getNode().asAstNode() = e2 and
806818
def.assigns(any(CfgNode cfg | cfg.getNode().asAstNode() = e1))
@@ -892,9 +904,7 @@ private module CaptureInput implements VariableCapture::InputSig {
892904

893905
predicate hasBody(Callable body) { this = body }
894906

895-
predicate hasAliasedAccess(Expr f) {
896-
closureFlowStep+(this, f) and not closureFlowStep(f, _)
897-
/* TODO: understand why this is intra-procedural */ }
907+
predicate hasAliasedAccess(Expr f) { closureFlowStep+(this, f) and not closureFlowStep(f, _) }
898908
}
899909

900910
class Callable extends S::Callable {

0 commit comments

Comments
 (0)