Misc key function fixes.

llvm-svn: 90831
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 6250e69..a063e213 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -522,6 +522,16 @@
         FD->hasAttr<DestructorAttr>())
       return false;
 
+    // The key function for a class must never be deferred.
+    if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Global)) {
+      const CXXRecordDecl *RD = MD->getParent();
+      if (MD->isOutOfLine() && RD->isDynamicClass()) {
+        const CXXMethodDecl *KeyFunction = getContext().getKeyFunction(RD);
+        if (KeyFunction == MD->getCanonicalDecl())
+          return false;
+      }
+    }
+
     GVALinkage Linkage = GetLinkageForFunction(getContext(), FD, Features);
 
     // static, static inline, always_inline, and extern inline functions can