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

Richard Smith richard-llvm at metafoo.co.uk
Wed Jul 8 14:15:32 PDT 2015


Author: rsmith
Date: Wed Jul  8 16:15:32 2015
New Revision: 241732

URL: http://llvm.org/viewvc/llvm-project?rev=241732&view=rev
Log:
[modules] Fix crash when writing an update record for a redeclaration of an empty namespace.

Modified:
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
    cfe/trunk/test/Modules/Inputs/namespaces-left.h
    cfe/trunk/test/Modules/Inputs/namespaces-right.h
    cfe/trunk/test/Modules/Inputs/namespaces-top.h

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=241732&r1=241731&r2=241732&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Wed Jul  8 16:15:32 2015
@@ -1016,10 +1016,12 @@ void ASTDeclWriter::VisitNamespaceDecl(N
     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) {

Modified: cfe/trunk/test/Modules/Inputs/namespaces-left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/namespaces-left.h?rev=241732&r1=241731&r2=241732&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/namespaces-left.h (original)
+++ cfe/trunk/test/Modules/Inputs/namespaces-left.h Wed Jul  8 16:15:32 2015
@@ -71,3 +71,5 @@ namespace N12 {
   }
   Foo *getFoo();
 }
+
+namespace Empty {}

Modified: cfe/trunk/test/Modules/Inputs/namespaces-right.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/namespaces-right.h?rev=241732&r1=241731&r2=241732&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/namespaces-right.h (original)
+++ cfe/trunk/test/Modules/Inputs/namespaces-right.h Wed Jul  8 16:15:32 2015
@@ -66,3 +66,5 @@ namespace N12 {
   }
   void consumeFoo(Foo*);
 }
+
+namespace Empty {}

Modified: cfe/trunk/test/Modules/Inputs/namespaces-top.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/namespaces-top.h?rev=241732&r1=241731&r2=241732&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/namespaces-top.h (original)
+++ cfe/trunk/test/Modules/Inputs/namespaces-top.h Wed Jul  8 16:15:32 2015
@@ -21,3 +21,5 @@ namespace N13 {
 namespace AddAndReexportBeforeImport {
   int S;
 }
+
+namespace Empty {}





More information about the cfe-commits mailing list