[cfe-commits] r116887 - in /cfe/trunk: lib/Serialization/ASTReaderDecl.cpp test/PCH/chain-cxx.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Oct 19 17:11:15 PDT 2010


Author: akirtzidis
Date: Tue Oct 19 19:11:15 2010
New Revision: 116887

URL: http://llvm.org/viewvc/llvm-project?rev=116887&view=rev
Log:
Fix issue with chained PCH where forward references did not pick up later definition in the chained PCH.

Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/test/PCH/chain-cxx.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=116887&r1=116886&r2=116887&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Tue Oct 19 19:11:15 2010
@@ -788,6 +788,24 @@
 
   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;

Modified: cfe/trunk/test/PCH/chain-cxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-cxx.cpp?rev=116887&r1=116886&r2=116887&view=diff
==============================================================================
--- cfe/trunk/test/PCH/chain-cxx.cpp (original)
+++ cfe/trunk/test/PCH/chain-cxx.cpp Tue Oct 19 19:11:15 2010
@@ -31,6 +31,9 @@
 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 @@
 template <>
 struct S<int &> { typedef int L; };
 
+template <typename T> struct TS2 { };
+
 //===----------------------------------------------------------------------===//
 #else
 //===----------------------------------------------------------------------===//
@@ -89,6 +94,8 @@
   typedef S<double &>::J T4;
   typedef S<int *>::K T5;
   typedef S<int &>::L T6;
+
+  TS2int ts2;
 }
 
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list