diff options
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 18 | ||||
-rw-r--r-- | test/PCH/chain-cxx.cpp | 7 |
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index bcef244723..38672a6536 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -788,6 +788,24 @@ void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { VisitRecordDecl(D); + if (D->DefinitionData) { + // Synchronize the DefinitionData pointer among all redeclarations. + // This synchronization ends up being done multiple times but it's necessary + // because a chained PCH may introduce a definition that earlier + // redeclarations in another PCH have no information about. + llvm::SmallPtrSet<CXXRecordDecl *, 16> PrevRedecls; + PrevRedecls.insert(D); + CXXRecordDecl *Redecl = cast<CXXRecordDecl>(D->RedeclLink.getNext()); + while (!PrevRedecls.count(Redecl)) { + PrevRedecls.insert(Redecl); + assert((!Redecl->DefinitionData || + Redecl->DefinitionData == D->DefinitionData) && + "Multiple definitions in the redeclaration chain ?"); + Redecl->DefinitionData = D->DefinitionData; + Redecl = cast<CXXRecordDecl>(Redecl->RedeclLink.getNext()); + } + } + if (OwnsDefinitionData) { assert(D->DefinitionData); struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; diff --git a/test/PCH/chain-cxx.cpp b/test/PCH/chain-cxx.cpp index b2d0523410..d269de529f 100644 --- a/test/PCH/chain-cxx.cpp +++ b/test/PCH/chain-cxx.cpp @@ -31,6 +31,9 @@ struct S { typedef int G; }; template <typename T> struct S<T *> { typedef int H; }; +template <typename T> struct TS2; +typedef TS2<int> TS2int; + //===----------------------------------------------------------------------===// #elif not defined(HEADER2) #define HEADER2 @@ -68,6 +71,8 @@ struct S<int *> { typedef int K; }; template <> struct S<int &> { typedef int L; }; +template <typename T> struct TS2 { }; + //===----------------------------------------------------------------------===// #else //===----------------------------------------------------------------------===// @@ -89,6 +94,8 @@ void test() { typedef S<double &>::J T4; typedef S<int *>::K T5; typedef S<int &>::L T6; + + TS2int ts2; } //===----------------------------------------------------------------------===// |