[cfe-commits] r138661 - /cfe/trunk/lib/AST/DeclBase.cpp

Douglas Gregor dgregor at apple.com
Fri Aug 26 14:23:06 PDT 2011


Author: dgregor
Date: Fri Aug 26 16:23:06 2011
New Revision: 138661

URL: http://llvm.org/viewvc/llvm-project?rev=138661&view=rev
Log:
When we're deserializing declarations lexically stored in a RecordDecl
after having already deserialized the fields, clear out the fields
first. This makes sure that we keep all of the declarations in the
lexical context (including those implicitly added by later
type-checking) within the same list. A test case for this behavior is
coming as part of another commit; testing for this problem in
isolation is a nightmare.

Modified:
    cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=138661&r1=138660&r2=138661&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Fri Aug 26 16:23:06 2011
@@ -841,6 +841,22 @@
   // Notify that we have a DeclContext that is initializing.
   ExternalASTSource::Deserializing ADeclContext(Source);
 
+  // We may have already loaded just the fields of this record, in which case
+  // we remove all of the fields from the list. The fields will be reloaded
+  // from the external source as part of re-establishing the context.
+  if (const RecordDecl *RD = dyn_cast<RecordDecl>(this)) {
+    if (RD->LoadedFieldsFromExternalStorage) {
+      while (FirstDecl && isa<FieldDecl>(FirstDecl)) {
+        Decl *Next = FirstDecl->NextDeclInContext;
+        FirstDecl->NextDeclInContext = 0;
+        FirstDecl = Next;
+      }
+      
+      if (!FirstDecl)
+        LastDecl = 0;
+    }
+  }
+  
   // Load the external declarations, if any.
   SmallVector<Decl*, 64> Decls;
   ExternalLexicalStorage = false;
@@ -856,14 +872,6 @@
   if (Decls.empty())
     return;
 
-  // We may have already loaded just the fields of this record, in which case
-  // don't add the decls, just replace the FirstDecl/LastDecl chain.
-  if (const RecordDecl *RD = dyn_cast<RecordDecl>(this))
-    if (RD->LoadedFieldsFromExternalStorage) {
-      llvm::tie(FirstDecl, LastDecl) = BuildDeclChain(Decls);
-      return;
-    }
-
   // Splice the newly-read declarations into the beginning of the list
   // of declarations.
   Decl *ExternalFirst, *ExternalLast;





More information about the cfe-commits mailing list