From 4a9eb26500086f913c4683bb360b14f8ce662fb4 Mon Sep 17 00:00:00 2001 From: Sebastian Redl Date: Tue, 28 Sep 2010 02:24:44 +0000 Subject: [PATCH] Fix a use of an invalidated reference due to a hash map reallocating. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114937 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReader.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 1a42665d07..ee9cd1a4df 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -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; -- 2.40.0