diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGCXX.cpp | 22 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 6 | ||||
-rw-r--r-- | clang/lib/CodeGen/ItaniumCXXABI.cpp | 12 | ||||
-rw-r--r-- | clang/lib/CodeGen/MicrosoftCXXABI.cpp | 14 |
4 files changed, 30 insertions, 24 deletions
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index 58611e83eea..6d10361bf90 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/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<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 f0daa5169f2..6012606e3de 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/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/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index b897abc2c04..22839cd0fae 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/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<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 9324b20a4f3..42cb29c8b44 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/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<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, |