]> granicus.if.org Git - clang/commitdiff
Fix a use of an invalidated reference due to a hash map reallocating.
authorSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 28 Sep 2010 02:24:44 +0000 (02:24 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 28 Sep 2010 02:24:44 +0000 (02:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114937 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Serialization/ASTReader.cpp

index 1a42665d075f2f9060c87241269b932b78b50f4c..ee9cd1a4df747e0a709180f85bda0156838de74c 100644 (file)
@@ -3180,7 +3180,9 @@ bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC,
 
   // 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 @@ bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC,
     // 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;