Skip to content

Commit a26fc55

Browse files
authored
Merge pull request #34243 from slavapestov/fix-astscope-leak
ASTScope: Allocate list of local bindings for BraceStmt in the ASTContext
2 parents 33109db + ef26ecf commit a26fc55

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

include/swift/AST/ASTScope.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,11 +1534,11 @@ class BraceStmtScope final : public AbstractStmtScope {
15341534
BraceStmt *const stmt;
15351535

15361536
/// Declarations which are in scope from the beginning of the statement.
1537-
SmallVector<ValueDecl *, 2> localFuncsAndTypes;
1537+
ArrayRef<ValueDecl *> localFuncsAndTypes;
15381538

15391539
/// Declarations that are normally in scope only after their
15401540
/// definition.
1541-
SmallVector<VarDecl *, 2> localVars;
1541+
ArrayRef<VarDecl *> localVars;
15421542

15431543
/// The end location for bindings introduced in this scope. This can
15441544
/// extend past the actual end of the BraceStmt in top-level code,
@@ -1548,8 +1548,8 @@ class BraceStmtScope final : public AbstractStmtScope {
15481548

15491549
public:
15501550
BraceStmtScope(BraceStmt *e,
1551-
SmallVector<ValueDecl *, 2> localFuncsAndTypes,
1552-
SmallVector<VarDecl *, 2> localVars,
1551+
ArrayRef<ValueDecl *> localFuncsAndTypes,
1552+
ArrayRef<VarDecl *> localVars,
15531553
SourceLoc endLoc)
15541554
: stmt(e),
15551555
localFuncsAndTypes(localFuncsAndTypes),

lib/AST/ASTScopeCreation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,15 @@ class NodeAdder
588588
if (endLoc.hasValue())
589589
endLocForBraceStmt = *endLoc;
590590

591-
if (auto *s = scopeCreator.getASTContext().Stats)
591+
ASTContext &ctx = scopeCreator.getASTContext();
592+
if (auto *s = ctx.Stats)
592593
++s->getFrontendCounters().NumBraceStmtASTScopes;
593594

594595
return
595596
scopeCreator.constructExpandAndInsert<BraceStmtScope>(
596-
p, bs, std::move(localFuncsAndTypes), std::move(localVars),
597+
p, bs,
598+
ctx.AllocateCopy(localFuncsAndTypes),
599+
ctx.AllocateCopy(localVars),
597600
endLocForBraceStmt);
598601
}
599602

0 commit comments

Comments
 (0)