Reduce code duplication a bit more. NFC.

llvm-svn: 217811
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp
index 58611e8..6d10361 100644
--- a/clang/lib/CodeGen/CGCXX.cpp
+++ b/clang/lib/CodeGen/CGCXX.cpp
@@ -196,6 +196,28 @@
   return false;
 }
 
+llvm::Function *CodeGenModule::codegenCXXStructor(const CXXMethodDecl *MD,
+                                                  StructorType Type) {
+  const CGFunctionInfo &FnInfo =
+      getTypes().arrangeCXXStructorDeclaration(MD, Type);
+  auto *Fn = cast<llvm::Function>(
+      getAddrOfCXXStructor(MD, Type, &FnInfo, nullptr, true));
+
+  GlobalDecl GD;
+  if (const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
+    GD = GlobalDecl(DD, toCXXDtorType(Type));
+  } else {
+    const auto *CD = cast<CXXConstructorDecl>(MD);
+    GD = GlobalDecl(CD, toCXXCtorType(Type));
+  }
+
+  setFunctionLinkage(GD, Fn);
+  CodeGenFunction(*this).GenerateCode(GD, Fn, FnInfo);
+  setFunctionDefinitionAttributes(MD, Fn);
+  SetLLVMFunctionAttributesForDefinition(MD, Fn);
+  return Fn;
+}
+
 llvm::GlobalValue *CodeGenModule::getAddrOfCXXStructor(
     const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo,
     llvm::FunctionType *FnType, bool DontDefer) {
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index f0daa51..6012606 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -802,6 +802,12 @@
   /// Objective-C fast enumeration loop (for..in).
   QualType getObjCFastEnumerationStateType();
 
+  // Produce code for this constructor/destructor. This method doesn't try
+  // to apply any ABI rules about which other constructors/destructors
+  // are needed or if they are alias to each other.
+  llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
+                                     StructorType Type);
+
   /// Return the address of the constructor/destructor of the given type.
   llvm::GlobalValue *
   getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type,
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index b897abc..22839cd 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3012,17 +3012,7 @@
       return;
   }
 
-  const CGFunctionInfo &fnInfo =
-      CGM.getTypes().arrangeCXXStructorDeclaration(ctor, ctorType);
-
-  auto *fn = cast<llvm::Function>(
-      CGM.getAddrOfCXXStructor(ctor, ctorType, &fnInfo, nullptr, true));
-  GlobalDecl GD(ctor, toCXXCtorType(ctorType));
-  CGM.setFunctionLinkage(GD, fn);
-  CodeGenFunction(CGM).GenerateCode(GD, fn, fnInfo);
-
-  CGM.setFunctionDefinitionAttributes(ctor, fn);
-  CGM.SetLLVMFunctionAttributesForDefinition(ctor, fn);
+  CGM.codegenCXXStructor(ctor, ctorType);
 }
 
 static void emitCXXDestructor(CodeGenModule &CGM, const CXXDestructorDecl *dtor,
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 9324b20..42cb29c 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -2877,19 +2877,7 @@
                                const CXXConstructorDecl *ctor,
                                StructorType ctorType) {
   // There are no constructor variants, always emit the complete destructor.
-  ctorType = StructorType::Complete;
-
-  const CGFunctionInfo &fnInfo =
-      CGM.getTypes().arrangeCXXStructorDeclaration(ctor, ctorType);
-
-  auto *fn = cast<llvm::Function>(
-      CGM.getAddrOfCXXStructor(ctor, ctorType, &fnInfo, nullptr, true));
-  GlobalDecl GD(ctor, toCXXCtorType(ctorType));
-  CGM.setFunctionLinkage(GD, fn);
-  CodeGenFunction(CGM).GenerateCode(GD, fn, fnInfo);
-
-  CGM.setFunctionDefinitionAttributes(ctor, fn);
-  CGM.SetLLVMFunctionAttributesForDefinition(ctor, fn);
+  CGM.codegenCXXStructor(ctor, StructorType::Complete);
 }
 
 static void emitCXXDestructor(CodeGenModule &CGM, const CXXDestructorDecl *dtor,