Now that deserializing a definition of a C++ class/Objective-C
class/Objective-C protocol suffices get all of the redeclarations of
that declaration wired to the definition, we no longer need to record
the identity of the definition in every declaration. Instead, just
record a bit to indicate whether a particular declaration is the
definition.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148224 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index 863aabb..8becd35 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -103,10 +103,6 @@
     void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
                                const RecordData &R, unsigned &I);
 
-    void InitializeCXXDefinitionData(CXXRecordDecl *D,
-                                     CXXRecordDecl *DefinitionDecl,
-                                     const RecordData &Record, unsigned &Idx);
-    
     /// \brief RAII class used to capture the first ID within a redeclaration
     /// chain and to introduce it into the list of pending redeclaration chains
     /// on destruction.
@@ -672,8 +668,7 @@
   TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
   mergeRedeclarable(ID, Redecl);
   
-  ObjCInterfaceDecl *Def = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
-  if (ID == Def) {
+  if (Record[Idx++]) {
     // Read the definition.
     ID->allocateDefinitionData();
     
@@ -745,8 +740,7 @@
   VisitObjCContainerDecl(PD);
   mergeRedeclarable(PD, Redecl);
   
-  ObjCProtocolDecl *Def = ReadDeclAs<ObjCProtocolDecl>(Record, Idx);
-  if (PD == Def) {
+  if (Record[Idx++]) {
     // Read the definition.
     PD->allocateDefinitionData();
     
@@ -1104,13 +1098,11 @@
   Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
 }
 
-void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
-                                                CXXRecordDecl *DefinitionDecl,
-                                                const RecordData &Record,
-                                                unsigned &Idx) {
-  ASTContext &C = Reader.getContext();
+void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
+  VisitRecordDecl(D);
 
-  if (D == DefinitionDecl) {
+  ASTContext &C = Reader.getContext();
+  if (Record[Idx++]) {
     D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
     
     // Propagate the DefinitionData pointer to the canonical declaration, so
@@ -1119,24 +1111,15 @@
     D->getCanonicalDecl()->DefinitionData = D->DefinitionData;
     
     ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
-
+    
     // Note that we have deserialized a definition. Any declarations 
     // deserialized before this one will be be given the DefinitionData pointer
     // at the end.
     Reader.PendingDefinitions.insert(D);
   } else {
     // Propagate DefinitionData pointer from the canonical declaration.
-    D->DefinitionData = D->getCanonicalDecl()->DefinitionData;
+    D->DefinitionData = D->getCanonicalDecl()->DefinitionData;    
   }
-}
-
-void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
-  VisitRecordDecl(D);
-
-  CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
-  InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
-
-  ASTContext &C = Reader.getContext();
 
   enum CXXRecKind {
     CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp
index 0b55d73..8829dc6 100644
--- a/lib/Serialization/ASTWriterDecl.cpp
+++ b/lib/Serialization/ASTWriterDecl.cpp
@@ -454,10 +454,8 @@
   VisitObjCContainerDecl(D);
   Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
 
-  ObjCInterfaceDecl *Def = D->getDefinition();
-  Writer.AddDeclRef(Def, Record);
-  
-  if (D == Def) {
+  Record.push_back(D->isThisDeclarationADefinition());
+  if (D->isThisDeclarationADefinition()) {
     // Write the DefinitionData
     ObjCInterfaceDecl::DefinitionData &Data = D->data();
     
@@ -520,10 +518,8 @@
   VisitRedeclarable(D);
   VisitObjCContainerDecl(D);
   
-  ObjCProtocolDecl *Def = D->getDefinition();
-  Writer.AddDeclRef(Def, Record);
-
-  if (D == Def) {
+  Record.push_back(D->isThisDeclarationADefinition());
+  if (D->isThisDeclarationADefinition()) {
     Record.push_back(D->protocol_size());
     for (ObjCProtocolDecl::protocol_iterator
          I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I)
@@ -905,12 +901,8 @@
 
 void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
   VisitRecordDecl(D);
-
-  CXXRecordDecl *DefinitionDecl = 0;
-  if (D->DefinitionData)
-    DefinitionDecl = D->DefinitionData->Definition;
-  Writer.AddDeclRef(DefinitionDecl, Record);
-  if (D == DefinitionDecl)
+  Record.push_back(D->isThisDeclarationADefinition());
+  if (D->isThisDeclarationADefinition())
     Writer.AddCXXDefinitionData(D, Record);
 
   enum {