Don't apply -fvisibility-inlines-hidden to extern templates.
Part 2 of rdar://problem/8595231



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117567 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 8526ecc..19cfe9e 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -456,7 +456,9 @@
     // member functions get "hidden" visibility if they don't have an
     // explicit visibility attribute.
     if (!VA && MD->isInlined() && LV.second > HiddenVisibility &&
-        D->getASTContext().getLangOptions().InlineVisibilityHidden)
+        D->getASTContext().getLangOptions().InlineVisibilityHidden &&
+        MD->getTemplateSpecializationKind()
+          != TSK_ExplicitInstantiationDeclaration)
       LV.second = HiddenVisibility;
 
   // Similarly for member class template specializations.
diff --git a/test/CodeGenCXX/visibility-inlines-hidden.cpp b/test/CodeGenCXX/visibility-inlines-hidden.cpp
index bb1574f..69ce256 100644
--- a/test/CodeGenCXX/visibility-inlines-hidden.cpp
+++ b/test/CodeGenCXX/visibility-inlines-hidden.cpp
@@ -1,4 +1,9 @@
-// RUN: %clang_cc1 -fvisibility-inlines-hidden -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fvisibility-inlines-hidden -emit-llvm -o - %s -O2 -disable-llvm-optzns | FileCheck %s
+
+// The trickery with optimization in the run line is to get IR
+// generation to emit available_externally function bodies, but not
+// actually inline them (and thus remove the emitted bodies).
+
 struct X0 {
   void __attribute__((visibility("default"))) f1() { }
   void f2() { }
@@ -29,7 +34,9 @@
   void f2() { }
 };
 
-void use(X0 *x0, X1<int> *x1, X2 *x2) {
+extern template struct X1<float>;
+
+void use(X0 *x0, X1<int> *x1, X2 *x2, X1<float> *x3) {
   // CHECK: define linkonce_odr void @_ZN2X02f1Ev
   x0->f1();
   // CHECK: define linkonce_odr hidden void @_ZN2X02f2Ev
@@ -54,4 +61,6 @@
   x1->X1::f6();
   // CHECK: define linkonce_odr hidden void @_ZN2X22f2Ev
   x2->f2();
+  // CHECK: define available_externally void @_ZN2X1IfE2f2Ev
+  x3->f2();
 }