From: Rafael Espindola Date: Mon, 15 Sep 2014 19:34:18 +0000 (+0000) Subject: Reduce code duplication a bit more. NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=313ac763803510f9f439482cff5a958e9604cd74;p=clang Reduce code duplication a bit more. NFC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217811 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 58611e83ee..6d10361bf9 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -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( + getAddrOfCXXStructor(MD, Type, &FnInfo, nullptr, true)); + + GlobalDecl GD; + if (const auto *DD = dyn_cast(MD)) { + GD = GlobalDecl(DD, toCXXDtorType(Type)); + } else { + const auto *CD = cast(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/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index f0daa5169f..6012606e3d 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -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, diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index b897abc2c0..22839cd0fa 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -3012,17 +3012,7 @@ static void emitCXXConstructor(CodeGenModule &CGM, return; } - const CGFunctionInfo &fnInfo = - CGM.getTypes().arrangeCXXStructorDeclaration(ctor, ctorType); - - auto *fn = cast( - 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/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp index 9324b20a4f..42cb29c8b4 100644 --- a/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/lib/CodeGen/MicrosoftCXXABI.cpp @@ -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( - 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,