[cfe-commits] r115263 - /cfe/trunk/lib/Serialization/ASTReader.cpp

Douglas Gregor dgregor at apple.com
Thu Sep 30 18:18:02 PDT 2010


Author: dgregor
Date: Thu Sep 30 20:18:02 2010
New Revision: 115263

URL: http://llvm.org/viewvc/llvm-project?rev=115263&view=rev
Log:
If we get a TU_CONTEXT update from a chained PCH file before we
actually have an ASTContext, delay the processing of that
update. Patch by Sebastian Redl! Fixes <rdar://problem/8499034>.

Modified:
    cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=115263&r1=115262&r2=115263&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Sep 30 20:18:02 2010
@@ -1768,7 +1768,8 @@
         reinterpret_cast<const DeclID *>(BlobStart),
         BlobLen / sizeof(DeclID)
       };
-      DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info);
+      DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0]
+        .push_back(Info);
       break;
     }
 
@@ -1778,7 +1779,7 @@
                         (const unsigned char *)BlobStart + Record[1],
                         (const unsigned char *)BlobStart,
                         ASTDeclContextNameLookupTrait(*this));
-      if (ID == 1) { // Is it the TU?
+      if (ID == 1 && Context) { // Is it the TU?
         DeclContextInfo Info = {
           Table, /* No lexical inforamtion */ 0, 0
         };
@@ -2229,6 +2230,17 @@
   PP->getHeaderSearchInfo().SetExternalLookup(this);
   PP->setExternalSource(this);
 
+  // If we have an update block for the TU waiting, we have to add it before
+  // deserializing the decl.
+  DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0);
+  if (DCU != DeclContextOffsets.end()) {
+    // Insertion could invalidate map, so grab vector.
+    DeclContextInfos T;
+    T.swap(DCU->second);
+    DeclContextOffsets.erase(DCU);
+    DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T);
+  }
+
   // Load the translation unit declaration
   GetTranslationUnitDecl();
 





More information about the cfe-commits mailing list