diff --git a/swift/codegen/schema.yml b/swift/codegen/schema.yml index 40ab0a5f29f..05299ea5dbb 100644 --- a/swift/codegen/schema.yml +++ b/swift/codegen/schema.yml @@ -471,6 +471,7 @@ OptionalEvaluationExpr: sub_expr: Expr OtherConstructorDeclRefExpr: + constructor_decl: ConstructorDecl _extends: Expr OverloadSetRefExpr: diff --git a/swift/extractor/visitors/ExprVisitor.h b/swift/extractor/visitors/ExprVisitor.h index 1719b646018..7a28165eb3b 100644 --- a/swift/extractor/visitors/ExprVisitor.h +++ b/swift/extractor/visitors/ExprVisitor.h @@ -518,13 +518,21 @@ class ExprVisitor : public AstVisitorBase { auto label = dispatcher_.assignNewLabel(expr); assert(expr->getBase() && "KeyPathApplicationExpr has getBase()"); assert(expr->getKeyPath() && "KeyPathApplicationExpr has getKeyPath()"); - + auto baseLabel = dispatcher_.fetchLabel(expr->getBase()); auto keyPathLabel = dispatcher_.fetchLabel(expr->getKeyPath()); dispatcher_.emit(KeyPathApplicationExprsTrap{label, baseLabel, keyPathLabel}); } + void visitOtherConstructorDeclRefExpr(swift::OtherConstructorDeclRefExpr* expr) { + auto label = dispatcher_.assignNewLabel(expr); + assert(expr->getDecl() && "OtherConstructorDeclRefExpr has getDecl()"); + + auto ctorLabel = dispatcher_.fetchLabel(expr->getDecl()); + dispatcher_.emit(OtherConstructorDeclRefExprsTrap{label, ctorLabel}); + } + private: TrapLabel emitArgument(const swift::Argument& arg) { auto argLabel = dispatcher_.createLabel(); diff --git a/swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll b/swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll index 41bf5e75b9c..d426b707561 100644 --- a/swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll +++ b/swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll @@ -1292,6 +1292,10 @@ module Exprs { DeclRefExprLValueTree() { isLValue(ast) } } + class OtherConstructorDeclRefTree extends AstLeafTree { + override OtherConstructorDeclRefExpr ast; + } + abstract class DeclRefExprRValueTree extends AstControlFlowTree { override DeclRefExpr ast; diff --git a/swift/ql/lib/codeql/swift/generated/expr/OtherConstructorDeclRefExpr.qll b/swift/ql/lib/codeql/swift/generated/expr/OtherConstructorDeclRefExpr.qll index 7d139c9b616..0ffa2efbe15 100644 --- a/swift/ql/lib/codeql/swift/generated/expr/OtherConstructorDeclRefExpr.qll +++ b/swift/ql/lib/codeql/swift/generated/expr/OtherConstructorDeclRefExpr.qll @@ -1,6 +1,14 @@ // generated by codegen/codegen.py +import codeql.swift.elements.decl.ConstructorDecl import codeql.swift.elements.expr.Expr class OtherConstructorDeclRefExprBase extends @other_constructor_decl_ref_expr, Expr { override string getAPrimaryQlClass() { result = "OtherConstructorDeclRefExpr" } + + ConstructorDecl getConstructorDecl() { + exists(ConstructorDecl x | + other_constructor_decl_ref_exprs(this, x) and + result = x.resolve() + ) + } } diff --git a/swift/ql/lib/swift.dbscheme b/swift/ql/lib/swift.dbscheme index 092c7f35331..8321d08a940 100644 --- a/swift/ql/lib/swift.dbscheme +++ b/swift/ql/lib/swift.dbscheme @@ -975,7 +975,8 @@ optional_evaluation_exprs( ); other_constructor_decl_ref_exprs( - unique int id: @other_constructor_decl_ref_expr + unique int id: @other_constructor_decl_ref_expr, + int constructor_decl: @constructor_decl ref ); @overload_set_ref_expr = diff --git a/swift/ql/test/extractor-tests/expressions/all.expected b/swift/ql/test/extractor-tests/expressions/all.expected index 2577566af17..7fd99501178 100644 --- a/swift/ql/test/extractor-tests/expressions/all.expected +++ b/swift/ql/test/extractor-tests/expressions/all.expected @@ -162,7 +162,6 @@ | expressions.swift:79:5:79:11 | call to ... | | expressions.swift:79:5:79:21 | call to ... | | expressions.swift:79:5:79:21 | self = ... | -| expressions.swift:79:11:79:11 | TBD (OtherConstructorDeclRefExpr) | | expressions.swift:79:11:79:11 | call to ... | | expressions.swift:79:19:79:19 | 22 | | expressions.swift:83:15:83:15 | Derived.Type | diff --git a/swift/ql/test/library-tests/controlflow/graph/Cfg.expected b/swift/ql/test/library-tests/controlflow/graph/Cfg.expected index 069eb7f7a6b..c6ce7aad26a 100644 --- a/swift/ql/test/library-tests/controlflow/graph/Cfg.expected +++ b/swift/ql/test/library-tests/controlflow/graph/Cfg.expected @@ -4944,7 +4944,6 @@ cfg.swift: # 378| init #-----| -> call to ... -#-----| -> TBD (OtherConstructorDeclRefExpr) # 379| super #-----| -> call to ... @@ -4961,9 +4960,6 @@ cfg.swift: # 379| call to ... #-----| -> super -# 379| TBD (OtherConstructorDeclRefExpr) -#-----| -> super - # 379| 0 #-----| -> call to ... diff --git a/swift/ql/test/library-tests/parent/parent.expected b/swift/ql/test/library-tests/parent/parent.expected index ecc65a7c16a..046a0371bf5 100644 --- a/swift/ql/test/library-tests/parent/parent.expected +++ b/swift/ql/test/library-tests/parent/parent.expected @@ -566,7 +566,6 @@ | expressions.swift:78:3:80:3 | init | ConstructorDecl | expressions.swift:78:10:80:3 | { ... } | BraceStmt | | expressions.swift:78:10:80:3 | { ... } | BraceStmt | expressions.swift:79:5:79:21 | self = ... | RebindSelfInConstructorExpr | | expressions.swift:78:10:80:3 | { ... } | BraceStmt | expressions.swift:80:3:80:3 | return | ReturnStmt | -| expressions.swift:79:5:79:11 | call to ... | DotSyntaxCallExpr | expressions.swift:79:11:79:11 | TBD (OtherConstructorDeclRefExpr) | OtherConstructorDeclRefExpr | | expressions.swift:79:5:79:11 | call to ... | DotSyntaxCallExpr | expressions.swift:79:11:79:11 | call to ... | OtherConstructorDeclRefExpr | | expressions.swift:79:5:79:21 | call to ... | CallExpr | expressions.swift:79:5:79:11 | call to ... | DotSyntaxCallExpr | | expressions.swift:79:5:79:21 | self = ... | RebindSelfInConstructorExpr | expressions.swift:78:3:78:3 | self | ParamDecl |