Skip to content

Commit 9681358

Browse files
committed
Swift: extract OtherConstructorDeclRefExpr
1 parent 6f63d9a commit 9681358

File tree

8 files changed

+24
-8
lines changed

8 files changed

+24
-8
lines changed

swift/codegen/schema.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ OptionalEvaluationExpr:
471471
sub_expr: Expr
472472

473473
OtherConstructorDeclRefExpr:
474+
constructor_decl: ConstructorDecl
474475
_extends: Expr
475476

476477
OverloadSetRefExpr:

swift/extractor/visitors/ExprVisitor.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,21 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
518518
auto label = dispatcher_.assignNewLabel(expr);
519519
assert(expr->getBase() && "KeyPathApplicationExpr has getBase()");
520520
assert(expr->getKeyPath() && "KeyPathApplicationExpr has getKeyPath()");
521-
521+
522522
auto baseLabel = dispatcher_.fetchLabel(expr->getBase());
523523
auto keyPathLabel = dispatcher_.fetchLabel(expr->getKeyPath());
524524

525525
dispatcher_.emit(KeyPathApplicationExprsTrap{label, baseLabel, keyPathLabel});
526526
}
527527

528+
void visitOtherConstructorDeclRefExpr(swift::OtherConstructorDeclRefExpr* expr) {
529+
auto label = dispatcher_.assignNewLabel(expr);
530+
assert(expr->getDecl() && "OtherConstructorDeclRefExpr has getDecl()");
531+
532+
auto ctorLabel = dispatcher_.fetchLabel(expr->getDecl());
533+
dispatcher_.emit(OtherConstructorDeclRefExprsTrap{label, ctorLabel});
534+
}
535+
528536
private:
529537
TrapLabel<ArgumentTag> emitArgument(const swift::Argument& arg) {
530538
auto argLabel = dispatcher_.createLabel<ArgumentTag>();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,10 @@ module Exprs {
12921292
DeclRefExprLValueTree() { isLValue(ast) }
12931293
}
12941294

1295+
class OtherConstructorDeclRefTree extends AstLeafTree {
1296+
override OtherConstructorDeclRefExpr ast;
1297+
}
1298+
12951299
abstract class DeclRefExprRValueTree extends AstControlFlowTree {
12961300
override DeclRefExpr ast;
12971301

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// generated by codegen/codegen.py
2+
import codeql.swift.elements.decl.ConstructorDecl
23
import codeql.swift.elements.expr.Expr
34

45
class OtherConstructorDeclRefExprBase extends @other_constructor_decl_ref_expr, Expr {
56
override string getAPrimaryQlClass() { result = "OtherConstructorDeclRefExpr" }
7+
8+
ConstructorDecl getConstructorDecl() {
9+
exists(ConstructorDecl x |
10+
other_constructor_decl_ref_exprs(this, x) and
11+
result = x.resolve()
12+
)
13+
}
614
}

swift/ql/lib/swift.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,8 @@ optional_evaluation_exprs(
975975
);
976976

977977
other_constructor_decl_ref_exprs(
978-
unique int id: @other_constructor_decl_ref_expr
978+
unique int id: @other_constructor_decl_ref_expr,
979+
int constructor_decl: @constructor_decl ref
979980
);
980981

981982
@overload_set_ref_expr =

swift/ql/test/extractor-tests/expressions/all.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
| expressions.swift:79:5:79:11 | call to ... |
163163
| expressions.swift:79:5:79:21 | call to ... |
164164
| expressions.swift:79:5:79:21 | self = ... |
165-
| expressions.swift:79:11:79:11 | TBD (OtherConstructorDeclRefExpr) |
166165
| expressions.swift:79:11:79:11 | call to ... |
167166
| expressions.swift:79:19:79:19 | 22 |
168167
| expressions.swift:83:15:83:15 | Derived.Type |

swift/ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,7 +4944,6 @@ cfg.swift:
49444944

49454945
# 378| init
49464946
#-----| -> call to ...
4947-
#-----| -> TBD (OtherConstructorDeclRefExpr)
49484947

49494948
# 379| super
49504949
#-----| -> call to ...
@@ -4961,9 +4960,6 @@ cfg.swift:
49614960
# 379| call to ...
49624961
#-----| -> super
49634962

4964-
# 379| TBD (OtherConstructorDeclRefExpr)
4965-
#-----| -> super
4966-
49674963
# 379| 0
49684964
#-----| -> call to ...
49694965

swift/ql/test/library-tests/parent/parent.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@
566566
| expressions.swift:78:3:80:3 | init | ConstructorDecl | expressions.swift:78:10:80:3 | { ... } | BraceStmt |
567567
| expressions.swift:78:10:80:3 | { ... } | BraceStmt | expressions.swift:79:5:79:21 | self = ... | RebindSelfInConstructorExpr |
568568
| expressions.swift:78:10:80:3 | { ... } | BraceStmt | expressions.swift:80:3:80:3 | return | ReturnStmt |
569-
| expressions.swift:79:5:79:11 | call to ... | DotSyntaxCallExpr | expressions.swift:79:11:79:11 | TBD (OtherConstructorDeclRefExpr) | OtherConstructorDeclRefExpr |
570569
| expressions.swift:79:5:79:11 | call to ... | DotSyntaxCallExpr | expressions.swift:79:11:79:11 | call to ... | OtherConstructorDeclRefExpr |
571570
| expressions.swift:79:5:79:21 | call to ... | CallExpr | expressions.swift:79:5:79:11 | call to ... | DotSyntaxCallExpr |
572571
| expressions.swift:79:5:79:21 | self = ... | RebindSelfInConstructorExpr | expressions.swift:78:3:78:3 | self | ParamDecl |

0 commit comments

Comments
 (0)