diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 8020916a6ce6..7a104f4d5740 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -947,9 +947,10 @@ void DeclContext::makeDeclVisibleInContext(NamedDecl *D, bool Recoverable) { } // If we already have a lookup data structure, perform the insertion - // into it. Otherwise, be lazy and don't build that structure until - // someone asks for it. - if (LookupPtr || !Recoverable) + // into it. If we haven't deserialized externally stored decls, deserialize + // them so we can add the decl. Otherwise, be lazy and don't build that + // structure until someone asks for it. + if (LookupPtr || !Recoverable || hasExternalVisibleStorage()) makeDeclVisibleInContextImpl(D); // If we are a transparent context, insert into our parent context, @@ -969,18 +970,18 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) { if (isa(D)) return; - ASTContext *C = 0; - if (!LookupPtr) { - C = &getParentASTContext(); - CreateStoredDeclsMap(*C); - } - // If there is an external AST source, load any declarations it knows about // with this declaration's name. if (ExternalASTSource *Source = getParentASTContext().getExternalSource()) if (hasExternalVisibleStorage()) Source->FindExternalVisibleDeclsByName(this, D->getDeclName()); + ASTContext *C = 0; + if (!LookupPtr) { + C = &getParentASTContext(); + CreateStoredDeclsMap(*C); + } + // Insert this declaration into the map. StoredDeclsList &DeclNameEntries = (*LookupPtr)[D->getDeclName()]; if (DeclNameEntries.isNull()) {