Make use of available_externally linkage for vtables when the
non-inline key function of a class template instantiation, when no key
function is present, the class template instantiation itself was
instantiated with an explicit instantiation declaration (aka extern
template). I'm fairly certain that the C++0x specification gives us
this lattitude, although GCC doesn't take advantage of it.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92779 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp
index ca148da..ccbb105 100644
--- a/lib/CodeGen/CGVtable.cpp
+++ b/lib/CodeGen/CGVtable.cpp
@@ -1501,16 +1501,31 @@
       break;
 
     case TSK_ImplicitInstantiation:
-    case TSK_ExplicitInstantiationDeclaration:
-      // FIXME: could an explicit instantiation declaration imply
-      // available_externally linkage?
     case TSK_ExplicitInstantiationDefinition:
       Linkage = llvm::GlobalVariable::WeakODRLinkage;
       break;
+
+    case TSK_ExplicitInstantiationDeclaration:
+      Linkage = llvm::GlobalVariable::AvailableExternallyLinkage;
+      break;
     }
   }
-  else
+  else if (KeyFunction)
     Linkage = llvm::GlobalVariable::WeakODRLinkage;
+  else {
+    switch (RD->getTemplateSpecializationKind()) {
+    case TSK_Undeclared:
+    case TSK_ExplicitSpecialization:
+    case TSK_ImplicitInstantiation:
+    case TSK_ExplicitInstantiationDefinition:
+      Linkage = llvm::GlobalVariable::WeakODRLinkage;
+      break;
+
+    case TSK_ExplicitInstantiationDeclaration:
+      Linkage = llvm::GlobalVariable::AvailableExternallyLinkage;
+      break;
+    }
+  }
   
   // Emit the data.
   GenerateClassData(Linkage, RD);