r230840 - [modules] Avoid adding a redecl chain to the 'pending out of date' list as the

Richard Smith richard-llvm at metafoo.co.uk
Fri Feb 27 21:57:03 PST 2015


Author: rsmith
Date: Fri Feb 27 23:57:02 2015
New Revision: 230840

URL: http://llvm.org/viewvc/llvm-project?rev=230840&view=rev
Log:
[modules] Avoid adding a redecl chain to the 'pending out of date' list as the
very first step in updating it.

Modified:
    cfe/trunk/include/clang/AST/Redeclarable.h
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/include/clang/AST/Redeclarable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Redeclarable.h?rev=230840&r1=230839&r2=230840&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Redeclarable.h (original)
+++ cfe/trunk/include/clang/AST/Redeclarable.h Fri Feb 27 23:57:02 2015
@@ -92,6 +92,13 @@ protected:
     }
 
     void markIncomplete() { Next.get<KnownLatest>().markIncomplete(); }
+
+    Decl *getLatestNotUpdated() const {
+      assert(NextIsLatest() && "expected a canonical decl");
+      if (Next.is<NotKnownLatest>())
+        return nullptr;
+      return Next.get<KnownLatest>().getNotUpdated();
+    }
   };
 
   static DeclLink PreviousDeclLink(decl_type *D) {

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=230840&r1=230839&r2=230840&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Fri Feb 27 23:57:02 2015
@@ -229,6 +229,11 @@ namespace clang {
           TypedefNameForLinkage(nullptr), HasPendingBody(false) {}
 
     template <typename DeclT>
+    static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D);
+    static Decl *getMostRecentDeclImpl(...);
+    static Decl *getMostRecentDecl(Decl *D);
+
+    template <typename DeclT>
     static void attachPreviousDeclImpl(ASTReader &Reader,
                                        Redeclarable<DeclT> *D, Decl *Previous);
     static void attachPreviousDeclImpl(ASTReader &Reader, ...);
@@ -2783,6 +2788,27 @@ ASTDeclReader::FindExistingResult ASTDec
 }
 
 template<typename DeclT>
+Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
+  return D->RedeclLink.getLatestNotUpdated();
+}
+Decl *ASTDeclReader::getMostRecentDeclImpl(...) {
+  llvm_unreachable("getMostRecentDecl on non-redeclarable declaration");
+}
+
+Decl *ASTDeclReader::getMostRecentDecl(Decl *D) {
+  assert(D);
+
+  switch (D->getKind()) {
+#define ABSTRACT_DECL(TYPE)
+#define DECL(TYPE, BASE)                               \
+  case Decl::TYPE:                                     \
+    return getMostRecentDeclImpl(cast<TYPE##Decl>(D));
+#include "clang/AST/DeclNodes.inc"
+  }
+  llvm_unreachable("unknown decl kind");
+}
+
+template<typename DeclT>
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
                                            Redeclarable<DeclT> *D,
                                            Decl *Previous) {
@@ -3359,9 +3385,14 @@ void ASTReader::loadPendingDeclChain(ser
   ArrayRef<Decl *> Chain = Visitor.getChain();
   if (Chain.empty())
     return;
-    
+
   // Hook up the chains.
-  Decl *MostRecent = CanonDecl->getMostRecentDecl();
+  //
+  // FIXME: We have three different dispatches on decl kind here; maybe
+  // we should instead generate one loop per kind and dispatch up-front?
+  Decl *MostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl);
+  if (!MostRecent)
+    MostRecent = CanonDecl;
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
     if (Chain[I] == CanonDecl)
       continue;
@@ -3369,8 +3400,7 @@ void ASTReader::loadPendingDeclChain(ser
     ASTDeclReader::attachPreviousDecl(*this, Chain[I], MostRecent);
     MostRecent = Chain[I];
   }
-  
-  ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent);  
+  ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent);
 }
 
 namespace {





More information about the cfe-commits mailing list