Add a decl update when a static data member of a class template is instantiated in a different PCH than its containing class. Otherwise we get double definition errors. Fixes a Boost.MPL problem that affects Boost.Accumulators and probably a lot more of Boost.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130488 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTCommon.h b/lib/Serialization/ASTCommon.h
index 904f8ed..838df13 100644
--- a/lib/Serialization/ASTCommon.h
+++ b/lib/Serialization/ASTCommon.h
@@ -24,7 +24,8 @@
UPD_CXX_SET_DEFINITIONDATA,
UPD_CXX_ADDED_IMPLICIT_MEMBER,
UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION,
- UPD_CXX_ADDED_ANONYMOUS_NAMESPACE
+ UPD_CXX_ADDED_ANONYMOUS_NAMESPACE,
+ UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER
};
TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index 52eff19..831e68c 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -82,7 +82,8 @@
void Visit(Decl *D);
- void UpdateDecl(Decl *D, const RecordData &Record);
+ void UpdateDecl(Decl *D, ASTReader::PerFileData &Module,
+ const RecordData &Record);
void VisitDecl(Decl *D);
void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
@@ -1703,7 +1704,7 @@
unsigned RecCode = Cursor.ReadRecord(Code, Record);
(void)RecCode;
assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
- Reader.UpdateDecl(D, Record);
+ Reader.UpdateDecl(D, *F, Record);
}
}
@@ -1717,7 +1718,8 @@
return D;
}
-void ASTDeclReader::UpdateDecl(Decl *D, const RecordData &Record) {
+void ASTDeclReader::UpdateDecl(Decl *D, ASTReader::PerFileData &Module,
+ const RecordData &Record) {
unsigned Idx = 0;
while (Idx < Record.size()) {
switch ((DeclUpdateKind)Record[Idx++]) {
@@ -1752,6 +1754,11 @@
}
break;
}
+
+ case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
+ cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
+ Reader.ReadSourceLocation(Module, Record, Idx));
+ break;
}
}
}
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 9616f8b..c163cf3 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -3955,4 +3955,16 @@
RewriteDecl(D);
}
+void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) {
+ if (D->getPCHLevel() == 0)
+ return;
+
+ // Since the actual instantiation is delayed, this really means that we need
+ // to update the instantiation location.
+ UpdateRecord &Record = DeclUpdates[D];
+ Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER);
+ AddSourceLocation(
+ D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record);
+}
+
ASTSerializationListener::~ASTSerializationListener() { }