]> granicus.if.org Git - clang/commitdiff
Reduce code duplication a bit more. NFC.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 15 Sep 2014 19:34:18 +0000 (19:34 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 15 Sep 2014 19:34:18 +0000 (19:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217811 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
lib/CodeGen/CodeGenModule.h
lib/CodeGen/ItaniumCXXABI.cpp
lib/CodeGen/MicrosoftCXXABI.cpp

index 58611e83eea01c5718ab385c104a0f607b52847c..6d10361bf9084810e35bb9152b54b27dfb63c152 100644 (file)
@@ -196,6 +196,28 @@ bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl,
   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) {
index f0daa5169f2f29308f94be8901f3257387f85366..6012606e3dedea347a7c9f5a4246dc3470d0fdc0 100644 (file)
@@ -802,6 +802,12 @@ public:
   /// 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,
index b897abc2c04ec7ed4486fd20fdef344ab5453337..22839cd0fae7d205463da29e9a1ccafc017cdcbd 100644 (file)
@@ -3012,17 +3012,7 @@ static void emitCXXConstructor(CodeGenModule &CGM,
       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,
index 9324b20a4f3c6679426c27723b61a7594e0af002..42cb29c8b44e2b9e614d0a2bd0d6913a6579935e 100644 (file)
@@ -2877,19 +2877,7 @@ static void emitCXXConstructor(CodeGenModule &CGM,
                                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,