Fix a crash when we were trying to compute the linkage too early.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182773 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index f2dda23..f5e4b42 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -7999,8 +7999,7 @@
 void ASTContext::addUnnamedTag(const TagDecl *Tag) {
   // FIXME: This mangling should be applied to function local classes too
   if (!Tag->getName().empty() || Tag->getTypedefNameForAnonDecl() ||
-      !isa<CXXRecordDecl>(Tag->getParent()) ||
-      !Tag->isExternallyVisible())
+      !isa<CXXRecordDecl>(Tag->getParent()))
     return;
 
   std::pair<llvm::DenseMap<const DeclContext *, unsigned>::iterator, bool> P =
diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp
index e7955a8..5f31e54 100644
--- a/test/CodeGenCXX/mangle.cpp
+++ b/test/CodeGenCXX/mangle.cpp
@@ -875,3 +875,25 @@
 
 // CHECK: define void @_Z6ASfuncPU3AS3i
 void ASfunc(__attribute__((address_space(3))) int* x) {}
+
+namespace test38 {
+  // CHECK: define linkonce_odr void @_ZN6test384funcINS_3fooUt_EEEvT_
+  typedef struct {
+    struct {
+    } a;
+  } foo;
+
+  template <typename T> void func(T) {}
+  void test() { func(foo().a); }
+}
+
+namespace test39 {
+  // CHECK: define internal void @"_ZN6test394funcINS_3$_0Ut_EEEvT_"
+  typedef struct {
+    struct {} a;
+  } *foo;
+  template<typename T> void func(T) {}
+  void test(foo x) {
+    func(x->a);
+  }
+}