When setting the anonymous namespace at PCH reading, it may still be initializing so avoid
the invariant checks at NamespaceDecl::setAnonymousNamespace().

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107566 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index da7ad1d..c35a399 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -344,6 +344,9 @@
   static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
     return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
   }
+  
+  friend class PCHDeclReader;
+  friend class PCHDeclWriter;
 };
 
 /// ValueDecl - Represent the declaration of a variable (in which case it is
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index 8e0d635..9de002b 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -564,13 +564,9 @@
   D->setNextNamespace(
                     cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
 
-  // Only read one reference--the original or anonymous namespace.
   bool IsOriginal = Record[Idx++];
-  if (IsOriginal)
-    D->setAnonymousNamespace(
-                    cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
-  else
-    D->setOriginalNamespace(
+  D->OrigOrAnonNamespace.setInt(IsOriginal);
+  D->OrigOrAnonNamespace.setPointer(
                     cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
 }
 
diff --git a/test/PCH/cxx-namespaces.cpp b/test/PCH/cxx-namespaces.cpp
new file mode 100644
index 0000000..0fd3de7
--- /dev/null
+++ b/test/PCH/cxx-namespaces.cpp
@@ -0,0 +1,10 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/cxx-namespaces.h -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-namespaces.h
+// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s 
+
+void m() {
+  N::x = 0;
+}
diff --git a/test/PCH/cxx-namespaces.h b/test/PCH/cxx-namespaces.h
new file mode 100644
index 0000000..f338953
--- /dev/null
+++ b/test/PCH/cxx-namespaces.h
@@ -0,0 +1,7 @@
+// Header for PCH test cxx-namespaces.cpp
+
+namespace N {
+    namespace {
+        int x;
+    }
+}