aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/PCHWriterDecl.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-07-09 21:11:43 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-07-09 21:11:43 +0000
commitecf966e837097fb2ea0a80391e129bed7361d396 (patch)
treed05112e62f64091f17e447f92c38bce6e6360fdf /lib/Frontend/PCHWriterDecl.cpp
parent64a5e2c4398105dfc05df7cc3de0e80bcee8e15a (diff)
Reorganize how ClassTemplate[Partial]SpecializationDecls are read/written to avoid the
possibility of adding an unitialized one into the folding set. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108016 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/PCHWriterDecl.cpp')
-rw-r--r--lib/Frontend/PCHWriterDecl.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp
index 81cb79226b..bc4452ed7f 100644
--- a/lib/Frontend/PCHWriterDecl.cpp
+++ b/lib/Frontend/PCHWriterDecl.cpp
@@ -233,7 +233,8 @@ void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
case FunctionDecl::TK_FunctionTemplateSpecialization: {
FunctionTemplateSpecializationInfo *
FTSInfo = D->getTemplateSpecializationInfo();
- Writer.AddDeclRef(FTSInfo->getTemplate(), Record);
+ // We want it canonical to guarantee that it has a Common*.
+ Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record);
Record.push_back(FTSInfo->getTemplateSpecializationKind());
// Template arguments.
@@ -826,6 +827,10 @@ void PCHDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
}
+static bool IsKeptInFoldingSet(ClassTemplateSpecializationDecl *D) {
+ return D->getTypeForDecl()->getAsCXXRecordDecl() == D;
+}
+
void PCHDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
VisitTemplateDecl(D);
@@ -833,27 +838,22 @@ void PCHDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
if (D->getPreviousDeclaration() == 0) {
// This ClassTemplateDecl owns the CommonPtr; write it.
+ assert(D->isCanonicalDecl());
typedef llvm::FoldingSet<ClassTemplateSpecializationDecl> CTSDSetTy;
CTSDSetTy &CTSDSet = D->getSpecializations();
Record.push_back(CTSDSet.size());
for (CTSDSetTy::iterator I=CTSDSet.begin(), E = CTSDSet.end(); I!=E; ++I) {
- ClassTemplateSpecializationDecl *CTSD = &*I;
- Writer.AddDeclRef(CTSD, Record);
- // Write the argument list here because we may get it uninitialized when
- // reading it back.
- Writer.AddTemplateArgumentList(&CTSD->getTemplateArgs(), Record);
+ assert(IsKeptInFoldingSet(&*I));
+ Writer.AddDeclRef(&*I, Record);
}
typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> CTPSDSetTy;
CTPSDSetTy &CTPSDSet = D->getPartialSpecializations();
Record.push_back(CTPSDSet.size());
for (CTPSDSetTy::iterator I=CTPSDSet.begin(), E=CTPSDSet.end(); I!=E; ++I) {
- ClassTemplatePartialSpecializationDecl *CTPSD = &*I;
- Writer.AddDeclRef(CTPSD, Record);
- // Write the argument list here because we may get it uninitialized when
- // reading it back.
- Writer.AddTemplateArgumentList(&CTPSD->getTemplateArgs(), Record);
+ assert(IsKeptInFoldingSet(&*I));
+ Writer.AddDeclRef(&*I, Record);
}
// InjectedClassNameType is computed, no need to write it.
@@ -891,6 +891,13 @@ void PCHDeclWriter::VisitClassTemplateSpecializationDecl(
Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
Record.push_back(D->getSpecializationKind());
+ bool IsInInFoldingSet = IsKeptInFoldingSet(D);
+ Record.push_back(IsInInFoldingSet);
+ if (IsInInFoldingSet) {
+ // When reading, we'll add it to the folding set of this one.
+ Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
+ }
+
Code = pch::DECL_CLASS_TEMPLATE_SPECIALIZATION;
}