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

Sebastian Redl sebastian.redl at getdesigned.at
Mon Sep 27 19:24:44 PDT 2010


Author: cornedbee
Date: Mon Sep 27 21:24:44 2010
New Revision: 114937

URL: http://llvm.org/viewvc/llvm-project?rev=114937&view=rev
Log:
Fix a use of an invalidated reference due to a hash map reallocating.

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=114937&r1=114936&r2=114937&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Sep 27 21:24:44 2010
@@ -3180,7 +3180,9 @@
 
   // There might be lexical decls in multiple parts of the chain, for the TU
   // at least.
-  DeclContextInfos &Infos = DeclContextOffsets[DC];
+  // DeclContextOffsets might reallocate as we load additional decls below,
+  // so make a copy of the vector.
+  DeclContextInfos Infos = DeclContextOffsets[DC];
   for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end();
        I != E; ++I) {
     // IDs can be 0 if this context doesn't contain declarations.
@@ -3190,8 +3192,11 @@
     // Load all of the declaration IDs
     for (const DeclID *ID = I->LexicalDecls,
                            *IDE = ID + I->NumLexicalDecls;
-         ID != IDE; ++ID)
-      Decls.push_back(GetDecl(*ID));
+        ID != IDE; ++ID) {
+      Decl *D = GetDecl(*ID);
+      assert(D && "Null decl in lexical decls");
+      Decls.push_back(D);
+    }
   }
 
   ++NumLexicalDeclContextsRead;





More information about the cfe-commits mailing list