Don't produce a vtable if we are just instantiating a method and the
class has no key function.

Fix PR6738.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99900 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp
index 841281c..bae588a 100644
--- a/lib/CodeGen/CGVtable.cpp
+++ b/lib/CodeGen/CGVtable.cpp
@@ -3138,19 +3138,28 @@
   // Get the key function.
   const CXXMethodDecl *KeyFunction = CGM.getContext().getKeyFunction(RD);
   
+  TemplateSpecializationKind RDKind = RD->getTemplateSpecializationKind();
+  TemplateSpecializationKind MDKind = MD->getTemplateSpecializationKind();
+
   if (KeyFunction) {
     // We don't have the right key function.
     if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl())
       return;
+  } else {
+    // If this is an explicit instantiation of a method, we don't need a vtable.
+    // Since we have no key function, we will emit the vtable when we see
+    // a use, and just defining a function is not an use.
+    if ((RDKind == TSK_ImplicitInstantiation ||
+         RDKind == TSK_ExplicitInstantiationDeclaration) &&
+        MDKind == TSK_ExplicitInstantiationDefinition)
+      return;
   }
 
   if (Vtables.count(RD))
     return;
 
-  TemplateSpecializationKind kind = RD->getTemplateSpecializationKind();
-  if (kind == TSK_ImplicitInstantiation)
+  if (RDKind == TSK_ImplicitInstantiation)
     CGM.DeferredVtables.push_back(RD);
   else
     GenerateClassData(CGM.getVtableLinkage(RD), RD);
 }
-