[modules] Fix crash when writing an update record for a redeclaration of an empty namespace.

llvm-svn: 241732
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 371aea8..cdd8487 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1016,10 +1016,12 @@
     StoredDeclsMap *Map = NS->buildLookup();
     SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 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/clang/test/Modules/Inputs/namespaces-left.h b/clang/test/Modules/Inputs/namespaces-left.h
index 787fe75..5badf62 100644
--- a/clang/test/Modules/Inputs/namespaces-left.h
+++ b/clang/test/Modules/Inputs/namespaces-left.h
@@ -71,3 +71,5 @@
   }
   Foo *getFoo();
 }
+
+namespace Empty {}
diff --git a/clang/test/Modules/Inputs/namespaces-right.h b/clang/test/Modules/Inputs/namespaces-right.h
index 77f54ea..dd2ac33 100644
--- a/clang/test/Modules/Inputs/namespaces-right.h
+++ b/clang/test/Modules/Inputs/namespaces-right.h
@@ -66,3 +66,5 @@
   }
   void consumeFoo(Foo*);
 }
+
+namespace Empty {}
diff --git a/clang/test/Modules/Inputs/namespaces-top.h b/clang/test/Modules/Inputs/namespaces-top.h
index 7bf5394..006b53c 100644
--- a/clang/test/Modules/Inputs/namespaces-top.h
+++ b/clang/test/Modules/Inputs/namespaces-top.h
@@ -21,3 +21,5 @@
 namespace AddAndReexportBeforeImport {
   int S;
 }
+
+namespace Empty {}