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/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 4593c6f..25687e1 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -567,7 +567,8 @@
}
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 @@
// 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 9ba3ee6..d1818b8 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2573,7 +2573,8 @@
SetNestedNameSpecifier(NewVD, D);
if (NumMatchedTemplateParamLists > 0) {
- NewVD->setTemplateParameterListsInfo(NumMatchedTemplateParamLists,
+ NewVD->setTemplateParameterListsInfo(Context,
+ NumMatchedTemplateParamLists,
(TemplateParameterList**)TemplateParamLists.release());
}
@@ -3151,7 +3152,8 @@
}
if (NumMatchedTemplateParamLists > 0) {
- NewFD->setTemplateParameterListsInfo(NumMatchedTemplateParamLists,
+ NewFD->setTemplateParameterListsInfo(Context,
+ NumMatchedTemplateParamLists,
(TemplateParameterList**)TemplateParamLists.release());
}
@@ -5412,7 +5414,8 @@
= static_cast<NestedNameSpecifier*>(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 21d5702..234665c 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -3868,7 +3868,8 @@
SequenceNumber);
SetNestedNameSpecifier(Partial, SS);
if (NumMatchedTemplateParamLists > 0) {
- Partial->setTemplateParameterListsInfo(NumMatchedTemplateParamLists,
+ Partial->setTemplateParameterListsInfo(Context,
+ NumMatchedTemplateParamLists,
(TemplateParameterList**) TemplateParameterLists.release());
}
@@ -3929,8 +3930,8 @@
PrevDecl);
SetNestedNameSpecifier(Specialization, SS);
if (NumMatchedTemplateParamLists > 0) {
- Specialization->setTemplateParameterListsInfo(
- NumMatchedTemplateParamLists,
+ Specialization->setTemplateParameterListsInfo(Context,
+ NumMatchedTemplateParamLists,
(TemplateParameterList**) TemplateParameterLists.release());
}