diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2011-04-29 08:19:30 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2011-04-29 08:19:30 +0000 |
commit | f79a71908d6f28cb2bc0c081d9a801ed14d61d82 (patch) | |
tree | 7442ee6471bcf6ab641f771befe670fc0faea9ed | |
parent | 0acc4ea40d2a75fbaf385e095a252f59078c7b94 (diff) |
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
-rw-r--r-- | include/clang/AST/ASTMutationListener.h | 3 | ||||
-rw-r--r-- | include/clang/Serialization/ASTWriter.h | 1 | ||||
-rw-r--r-- | lib/Frontend/MultiplexConsumer.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 4 | ||||
-rw-r--r-- | lib/Serialization/ASTCommon.h | 3 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 13 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 12 | ||||
-rw-r--r-- | test/PCH/chain-cxx.cpp | 20 |
8 files changed, 58 insertions, 4 deletions
diff --git a/include/clang/AST/ASTMutationListener.h b/include/clang/AST/ASTMutationListener.h index b1f52b5f66..470cca8ee7 100644 --- a/include/clang/AST/ASTMutationListener.h +++ b/include/clang/AST/ASTMutationListener.h @@ -51,6 +51,9 @@ public: /// \brief An implicit member got a definition. virtual void CompletedImplicitDefinition(const FunctionDecl *D) {} + + /// \brief A static data member was implicitly instantiated. + virtual void StaticDataMemberInstantiated(const VarDecl *D) {} }; } // end namespace clang diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index b7a0208d92..1a79b31d26 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -589,6 +589,7 @@ public: virtual void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, const FunctionDecl *D); virtual void CompletedImplicitDefinition(const FunctionDecl *D); + virtual void StaticDataMemberInstantiated(const VarDecl *D); }; /// \brief AST and semantic-analysis consumer that generates a diff --git a/lib/Frontend/MultiplexConsumer.cpp b/lib/Frontend/MultiplexConsumer.cpp index 721bd05a98..5aa65d7a60 100644 --- a/lib/Frontend/MultiplexConsumer.cpp +++ b/lib/Frontend/MultiplexConsumer.cpp @@ -98,6 +98,7 @@ public: virtual void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, const FunctionDecl *D); virtual void CompletedImplicitDefinition(const FunctionDecl *D); + virtual void StaticDataMemberInstantiated(const VarDecl *D); private: std::vector<ASTMutationListener*> Listeners; }; @@ -138,6 +139,11 @@ void MultiplexASTMutationListener::CompletedImplicitDefinition( for (size_t i = 0, e = Listeners.size(); i != e; ++i) Listeners[i]->CompletedImplicitDefinition(D); } +void MultiplexASTMutationListener::StaticDataMemberInstantiated( + const VarDecl *D) { + for (size_t i = 0, e = Listeners.size(); i != e; ++i) + Listeners[i]->StaticDataMemberInstantiated(D); +} } // end namespace clang diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c4ec8dc116..20b92b8420 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -16,6 +16,7 @@ #include "clang/Sema/Lookup.h" #include "clang/Sema/AnalysisBasedWarnings.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/ASTMutationListener.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" @@ -10000,6 +10001,9 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { if (MSInfo->getPointOfInstantiation().isInvalid() && MSInfo->getTemplateSpecializationKind()== TSK_ImplicitInstantiation) { MSInfo->setPointOfInstantiation(Loc); + // This is a modification of an existing AST node. Notify listeners. + if (ASTMutationListener *L = getASTMutationListener()) + L->StaticDataMemberInstantiated(Var); PendingInstantiations.push_back(std::make_pair(Var, Loc)); } } diff --git a/lib/Serialization/ASTCommon.h b/lib/Serialization/ASTCommon.h index 904f8ed6ae..838df13f2d 100644 --- a/lib/Serialization/ASTCommon.h +++ b/lib/Serialization/ASTCommon.h @@ -24,7 +24,8 @@ enum DeclUpdateKind { 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 52eff1957d..831e68c95a 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -82,7 +82,8 @@ namespace clang { 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 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) { 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 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) { 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 @@ void ASTDeclReader::UpdateDecl(Decl *D, const RecordData &Record) { } 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 9616f8bfd7..c163cf3d99 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -3955,4 +3955,16 @@ void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { 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() { } diff --git a/test/PCH/chain-cxx.cpp b/test/PCH/chain-cxx.cpp index 107ddfee1c..af0a23afea 100644 --- a/test/PCH/chain-cxx.cpp +++ b/test/PCH/chain-cxx.cpp @@ -35,9 +35,23 @@ typedef TS2<int> TS2int; template <typename T> struct TestBaseSpecifiers { }; template<typename T> struct TestBaseSpecifiers2 : TestBaseSpecifiers<T> { }; +template <typename T> +struct TS3 { + static const int value = 0; +}; +template <typename T> +const int TS3<T>::value; +// Instantiate struct, but not value. +struct instantiate : TS3<int> {}; + + //===----------------------------------------------------------------------===// #elif not defined(HEADER2) #define HEADER2 +#if !defined(HEADER1) +#error Header inclusion order messed up +#endif + //===----------------------------------------------------------------------===// // Dependent header for C++ chained PCH test @@ -80,6 +94,9 @@ struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { }; struct A { }; struct B : A { }; +// Instantiate TS3's member. +static const int ts3m1 = TS3<int>::value; + //===----------------------------------------------------------------------===// #else //===----------------------------------------------------------------------===// @@ -107,5 +124,8 @@ void test() { B b; } +// Should have remembered that there is a definition. +static const int ts3m2 = TS3<int>::value; + //===----------------------------------------------------------------------===// #endif |