From: Richard Smith Date: Wed, 8 Jul 2015 21:15:32 +0000 (+0000) Subject: [modules] Fix crash when writing an update record for a redeclaration of an empty... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49e2d9a021a1f969d59d965cd5b97701317e96fa;p=clang [modules] Fix crash when writing an update record for a redeclaration of an empty namespace. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241732 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 371aea8088..cdd8487c55 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -1016,10 +1016,12 @@ void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { StoredDeclsMap *Map = NS->buildLookup(); SmallVector, 16> LookupResults; - LookupResults.reserve(Map->size()); - for (auto &Entry : *Map) - LookupResults.push_back( - std::make_pair(Entry.first, Entry.second.getLookupResult())); + if (Map) { + LookupResults.reserve(Map->size()); + for (auto &Entry : *Map) + LookupResults.push_back( + std::make_pair(Entry.first, Entry.second.getLookupResult())); + } std::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); for (auto &NameAndResult : LookupResults) { diff --git a/test/Modules/Inputs/namespaces-left.h b/test/Modules/Inputs/namespaces-left.h index 787fe753fb..5badf62764 100644 --- a/test/Modules/Inputs/namespaces-left.h +++ b/test/Modules/Inputs/namespaces-left.h @@ -71,3 +71,5 @@ namespace N12 { } Foo *getFoo(); } + +namespace Empty {} diff --git a/test/Modules/Inputs/namespaces-right.h b/test/Modules/Inputs/namespaces-right.h index 77f54ead65..dd2ac33f91 100644 --- a/test/Modules/Inputs/namespaces-right.h +++ b/test/Modules/Inputs/namespaces-right.h @@ -66,3 +66,5 @@ namespace N12 { } void consumeFoo(Foo*); } + +namespace Empty {} diff --git a/test/Modules/Inputs/namespaces-top.h b/test/Modules/Inputs/namespaces-top.h index 7bf5394f55..006b53c8fd 100644 --- a/test/Modules/Inputs/namespaces-top.h +++ b/test/Modules/Inputs/namespaces-top.h @@ -21,3 +21,5 @@ namespace N13 { namespace AddAndReexportBeforeImport { int S; } + +namespace Empty {}