diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-02-19 00:42:33 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-02-19 00:42:33 +0000 |
commit | 9f9269e810bfe9aea0a57b09250be215808fc1a2 (patch) | |
tree | d7cb45bf9e3387ffdacb0a1106cd2ceca04cf454 /lib/Sema/SemaInit.cpp | |
parent | b9c903bc7c11adf86b1f1e68ad35cd49703dc654 (diff) |
Change InitListExpr to allocate the array for holding references
to initializer expressions in an array allocated using ASTContext.
This plugs a memory leak when ASTContext uses a BumpPtrAllocator to
allocate memory for AST nodes.
In my mind this isn't an ideal solution; it would be nice to have
a general "vector"-like class that allocates memory using ASTContext,
but whose guts could be separated from the methods of InitListExpr
itself. I haven't gone and taken this approach yet because it isn't
clear yet if we'll eventually want an alternate solution for recylcing
memory using by InitListExprs as we are constructing the ASTs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96642 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r-- | lib/Sema/SemaInit.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 7b4a41777b..1c4e2c837a 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -280,7 +280,7 @@ void InitListChecker::FillInValueInitForField(unsigned Init, FieldDecl *Field, // extend the initializer list to include the constructor // call and make a note that we'll need to take another pass // through the initializer list. - ILE->updateInit(Init, MemberInit.takeAs<Expr>()); + ILE->updateInit(SemaRef.Context, Init, MemberInit.takeAs<Expr>()); RequiresSecondPass = true; } } else if (InitListExpr *InnerILE @@ -390,7 +390,7 @@ InitListChecker::FillInValueInitializations(const InitializedEntity &Entity, // extend the initializer list to include the constructor // call and make a note that we'll need to take another pass // through the initializer list. - ILE->updateInit(Init, ElementInit.takeAs<Expr>()); + ILE->updateInit(SemaRef.Context, Init, ElementInit.takeAs<Expr>()); RequiresSecondPass = true; } } else if (InitListExpr *InnerILE @@ -1669,8 +1669,8 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index, } InitListExpr *Result - = new (SemaRef.Context) InitListExpr(InitRange.getBegin(), 0, 0, - InitRange.getEnd()); + = new (SemaRef.Context) InitListExpr(SemaRef.Context, InitRange.getBegin(), + 0, 0, InitRange.getEnd()); Result->setType(CurrentObjectType.getNonReferenceType()); @@ -1707,12 +1707,12 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index, if (NumElements < NumInits) NumElements = IList->getNumInits(); - Result->reserveInits(NumElements); + Result->reserveInits(SemaRef.Context, NumElements); // Link this new initializer list into the structured initializer // lists. if (StructuredList) - StructuredList->updateInit(StructuredIndex, Result); + StructuredList->updateInit(SemaRef.Context, StructuredIndex, Result); else { Result->setSyntacticForm(IList); SyntacticToSemantic[IList] = Result; @@ -1730,7 +1730,8 @@ void InitListChecker::UpdateStructuredListElement(InitListExpr *StructuredList, if (!StructuredList) return; - if (Expr *PrevInit = StructuredList->updateInit(StructuredIndex, expr)) { + if (Expr *PrevInit = StructuredList->updateInit(SemaRef.Context, + StructuredIndex, expr)) { // This initializer overwrites a previous initializer. Warn. SemaRef.Diag(expr->getSourceRange().getBegin(), diag::warn_initializer_overrides) |