aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGCXX.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-04-17 01:58:57 +0000
committerAnders Carlsson <andersca@mac.com>2009-04-17 01:58:57 +0000
commit27ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5 (patch)
tree10a22e278b8d77f35f630084165189eeadc0fbca /lib/CodeGen/CGCXX.cpp
parentec9587d5bed6149f6df8b57192bb787c62aedb1b (diff)
Add support for generating (very basic) C++ destructors. These aren't called by anything yet.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69343 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r--lib/CodeGen/CGCXX.cpp91
1 files changed, 65 insertions, 26 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index e61cef3498..cfb93b90d7 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -124,27 +124,6 @@ llvm::Value *CodeGenFunction::LoadCXXThis() {
return Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this");
}
-const char *CodeGenModule::getMangledCXXCtorName(const CXXConstructorDecl *D,
- CXXCtorType Type) {
- llvm::SmallString<256> Name;
- llvm::raw_svector_ostream Out(Name);
- mangleCXXCtor(D, Type, Context, Out);
-
- Name += '\0';
- return UniqueMangledName(Name.begin(), Name.end());
-}
-
-void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *D,
- CXXCtorType Type) {
-
- llvm::Function *Fn = GetAddrOfCXXConstructor(D, Type);
-
- CodeGenFunction(*this).GenerateCode(D, Fn);
-
- SetFunctionDefinitionAttributes(D, Fn);
- SetLLVMFunctionAttributesForDefinition(D, Fn);
-}
-
void
CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
CXXCtorType Type,
@@ -190,10 +169,8 @@ CodeGenFunction::EmitCXXTemporaryObjectExpr(llvm::Value *Dest,
E->arg_begin(), E->arg_end());
}
-static bool canGenerateCXXConstructor(const CXXConstructorDecl *D,
- ASTContext &Context) {
- const CXXRecordDecl *RD = D->getParent();
-
+static bool canGenerateCXXstructor(const CXXRecordDecl *RD,
+ ASTContext &Context) {
// The class has base classes - we don't support that right now.
if (RD->getNumBases() > 0)
return false;
@@ -209,7 +186,7 @@ static bool canGenerateCXXConstructor(const CXXConstructorDecl *D,
}
void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
- if (!canGenerateCXXConstructor(D, getContext())) {
+ if (!canGenerateCXXstructor(D->getParent(), getContext())) {
ErrorUnsupported(D, "C++ constructor", true);
return;
}
@@ -218,6 +195,17 @@ void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
EmitCXXConstructor(D, Ctor_Base);
}
+void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *D,
+ CXXCtorType Type) {
+
+ llvm::Function *Fn = GetAddrOfCXXConstructor(D, Type);
+
+ CodeGenFunction(*this).GenerateCode(D, Fn);
+
+ SetFunctionDefinitionAttributes(D, Fn);
+ SetLLVMFunctionAttributesForDefinition(D, Fn);
+}
+
llvm::Function *
CodeGenModule::GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
CXXCtorType Type) {
@@ -227,3 +215,54 @@ CodeGenModule::GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
const char *Name = getMangledCXXCtorName(D, Type);
return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, D));
}
+
+const char *CodeGenModule::getMangledCXXCtorName(const CXXConstructorDecl *D,
+ CXXCtorType Type) {
+ llvm::SmallString<256> Name;
+ llvm::raw_svector_ostream Out(Name);
+ mangleCXXCtor(D, Type, Context, Out);
+
+ Name += '\0';
+ return UniqueMangledName(Name.begin(), Name.end());
+}
+
+void CodeGenModule::EmitCXXDestructors(const CXXDestructorDecl *D) {
+ if (!canGenerateCXXstructor(D->getParent(), getContext())) {
+ ErrorUnsupported(D, "C++ destructor", true);
+ return;
+ }
+
+ EmitCXXDestructor(D, Dtor_Complete);
+ EmitCXXDestructor(D, Dtor_Base);
+}
+
+void CodeGenModule::EmitCXXDestructor(const CXXDestructorDecl *D,
+ CXXDtorType Type) {
+ llvm::Function *Fn = GetAddrOfCXXDestructor(D, Type);
+
+ CodeGenFunction(*this).GenerateCode(D, Fn);
+
+ SetFunctionDefinitionAttributes(D, Fn);
+ SetLLVMFunctionAttributesForDefinition(D, Fn);
+}
+
+llvm::Function *
+CodeGenModule::GetAddrOfCXXDestructor(const CXXDestructorDecl *D,
+ CXXDtorType Type) {
+ const llvm::FunctionType *FTy =
+ getTypes().GetFunctionType(getTypes().getFunctionInfo(D), false);
+
+ const char *Name = getMangledCXXDtorName(D, Type);
+ return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FTy, D));
+}
+
+const char *CodeGenModule::getMangledCXXDtorName(const CXXDestructorDecl *D,
+ CXXDtorType Type) {
+ llvm::SmallString<256> Name;
+ llvm::raw_svector_ostream Out(Name);
+ mangleCXXDtor(D, Type, Context, Out);
+
+ Name += '\0';
+ return UniqueMangledName(Name.begin(), Name.end());
+}
+