From: Douglas Gregor Date: Tue, 15 Jun 2010 17:44:38 +0000 (+0000) Subject: Allocate template parameter lists for out-of-line definitions via the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c722ea4fbf886d6460b256b5e819a4ee751d5fff;p=clang Allocate template parameter lists for out-of-line definitions via the ASTContext rather than via the normal heap. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106008 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 2c7dfecab9..f4ca149b5a 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -385,10 +385,12 @@ struct QualifierInfo { : NNS(0), NNSRange(), NumTemplParamLists(0), TemplParamLists(0) {} /// setTemplateParameterListsInfo - Sets info about matched template /// parameter lists. - void setTemplateParameterListsInfo(unsigned NumTPLists, + void setTemplateParameterListsInfo(ASTContext &Context, + unsigned NumTPLists, TemplateParameterList **TPLists); - /// Destructor: frees the array of template parameter lists pointers. - ~QualifierInfo() { delete[] TemplParamLists; } + + void Destroy(ASTContext &Context); + private: // Copy constructor and copy assignment are disabled. QualifierInfo(const QualifierInfo&); @@ -447,9 +449,9 @@ public: assert(index < getNumTemplateParameterLists()); return getExtInfo()->TemplParamLists[index]; } - void setTemplateParameterListsInfo(unsigned NumTPLists, + void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists, TemplateParameterList **TPLists) { - getExtInfo()->setTemplateParameterListsInfo(NumTPLists, TPLists); + getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists); } SourceLocation getTypeSpecStartLoc() const; @@ -1887,9 +1889,9 @@ public: assert(i < getNumTemplateParameterLists()); return getExtInfo()->TemplParamLists[i]; } - void setTemplateParameterListsInfo(unsigned NumTPLists, + void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists, TemplateParameterList **TPLists) { - getExtInfo()->setTemplateParameterListsInfo(NumTPLists, TPLists); + getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists); } // Implement isa/cast/dyncast/etc. diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 4593c6f0e5..25687e15c4 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -567,7 +567,8 @@ void DeclaratorDecl::setQualifierInfo(NestedNameSpecifier *Qualifier, } void -QualifierInfo::setTemplateParameterListsInfo(unsigned NumTPLists, +QualifierInfo::setTemplateParameterListsInfo(ASTContext &Context, + unsigned NumTPLists, TemplateParameterList **TPLists) { assert((NumTPLists == 0 || TPLists != 0) && "Empty array of template parameters with positive size!"); @@ -576,19 +577,25 @@ QualifierInfo::setTemplateParameterListsInfo(unsigned NumTPLists, // Free previous template parameters (if any). if (NumTemplParamLists > 0) { - delete[] TemplParamLists; + Context.Deallocate(TemplParamLists); TemplParamLists = 0; NumTemplParamLists = 0; } // Set info on matched template parameter lists (if any). if (NumTPLists > 0) { - TemplParamLists = new TemplateParameterList*[NumTPLists]; + TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; NumTemplParamLists = NumTPLists; for (unsigned i = NumTPLists; i-- > 0; ) TemplParamLists[i] = TPLists[i]; } } +void QualifierInfo::Destroy(ASTContext &Context) { + // FIXME: Deallocate template parameter lists themselves! + if (TemplParamLists) + Context.Deallocate(TemplParamLists); +} + //===----------------------------------------------------------------------===// // VarDecl Implementation //===----------------------------------------------------------------------===// diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 9ba3ee6ca4..d1818b813c 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2573,7 +2573,8 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, SetNestedNameSpecifier(NewVD, D); if (NumMatchedTemplateParamLists > 0) { - NewVD->setTemplateParameterListsInfo(NumMatchedTemplateParamLists, + NewVD->setTemplateParameterListsInfo(Context, + NumMatchedTemplateParamLists, (TemplateParameterList**)TemplateParamLists.release()); } @@ -3151,7 +3152,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, } if (NumMatchedTemplateParamLists > 0) { - NewFD->setTemplateParameterListsInfo(NumMatchedTemplateParamLists, + NewFD->setTemplateParameterListsInfo(Context, + NumMatchedTemplateParamLists, (TemplateParameterList**)TemplateParamLists.release()); } @@ -5412,7 +5414,8 @@ CreateNewDecl: = static_cast(SS.getScopeRep()); New->setQualifierInfo(NNS, SS.getRange()); if (NumMatchedTemplateParamLists > 0) { - New->setTemplateParameterListsInfo(NumMatchedTemplateParamLists, + New->setTemplateParameterListsInfo(Context, + NumMatchedTemplateParamLists, (TemplateParameterList**) TemplateParameterLists.release()); } } diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 21d5702ea2..234665c4aa 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -3868,7 +3868,8 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, SequenceNumber); SetNestedNameSpecifier(Partial, SS); if (NumMatchedTemplateParamLists > 0) { - Partial->setTemplateParameterListsInfo(NumMatchedTemplateParamLists, + Partial->setTemplateParameterListsInfo(Context, + NumMatchedTemplateParamLists, (TemplateParameterList**) TemplateParameterLists.release()); } @@ -3929,8 +3930,8 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, PrevDecl); SetNestedNameSpecifier(Specialization, SS); if (NumMatchedTemplateParamLists > 0) { - Specialization->setTemplateParameterListsInfo( - NumMatchedTemplateParamLists, + Specialization->setTemplateParameterListsInfo(Context, + NumMatchedTemplateParamLists, (TemplateParameterList**) TemplateParameterLists.release()); }