]> granicus.if.org Git - clang/commitdiff
Teach the ASTReader how to avoid cycles when loading declarations that
authorDouglas Gregor <dgregor@apple.com>
Fri, 26 Aug 2011 22:04:51 +0000 (22:04 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 26 Aug 2011 22:04:51 +0000 (22:04 +0000)
are lexically within a particular DeclContext. Test forthcoming.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138668 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclBase.h
include/clang/Lex/ModuleLoader.h [new file with mode: 0644]
lib/Serialization/ASTReader.cpp

index 042c50f2a8b13b29e79c69aed4ec374b8f6b307c..8dc15de0f8b3a7f3d6750b40cc249d67a4ce6b14 100644 (file)
@@ -1322,6 +1322,12 @@ public:
     ExternalVisibleStorage = ES;
   }
 
+  /// \brief Determine whether the given declaration is stored in the list of
+  /// declarations lexically within this context.
+  bool isDeclInLexicalTraversal(const Decl *D) const {
+    return D && (D->NextDeclInContext || D == FirstDecl || D == LastDecl);
+  }
+  
   static bool classof(const Decl *D);
   static bool classof(const DeclContext *D) { return true; }
 #define DECL(NAME, BASE)
diff --git a/include/clang/Lex/ModuleLoader.h b/include/clang/Lex/ModuleLoader.h
new file mode 100644 (file)
index 0000000..e69de29
index 540b9ef034a8805f81fed8227c683b4e4013827c..c991cc07764274eed6271d557a47956341feacf1 100644 (file)
@@ -2553,7 +2553,7 @@ namespace {
       = static_cast<IdentifierLookupVisitor *>(UserData);
       
       ASTIdentifierLookupTable *IdTable
-      = (ASTIdentifierLookupTable *)M.IdentifierLookupTable;
+        = (ASTIdentifierLookupTable *)M.IdentifierLookupTable;
       if (!IdTable)
         return false;
       
@@ -2786,7 +2786,7 @@ void ASTReader::setPreprocessor(Preprocessor &pp) {
 void ASTReader::InitializeContext(ASTContext &Ctx) {
   Context = &Ctx;
   assert(Context && "Passed null context!");
-
+  
   assert(PP && "Forgot to set Preprocessor ?");
   PP->getIdentifierTable().setExternalIdentifierLookup(this);
   PP->setExternalSource(this);
@@ -4163,6 +4163,7 @@ namespace {
     ASTReader &Reader;
     const DeclContext *DC;
     bool (*isKindWeWant)(Decl::Kind);
+    
     SmallVectorImpl<Decl*> &Decls;
     bool PredefsVisited[NUM_PREDEF_DECL_IDS];
 
@@ -4204,9 +4205,10 @@ namespace {
           This->PredefsVisited[ID->second] = true;
         }
 
-        Decl *D = This->Reader.GetLocalDecl(M, ID->second);
-        assert(D && "Null decl in lexical decls");
-        This->Decls.push_back(D);
+        if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) {
+          if (!This->DC->isDeclInLexicalTraversal(D))
+            This->Decls.push_back(D);
+        }
       }
 
       return false;