diff options
-rw-r--r-- | clang/include/clang/AST/DeclCXX.h | 3 | ||||
-rw-r--r-- | clang/lib/AST/DeclCXX.cpp | 17 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGCXX.cpp | 8 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 4 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 2 |
5 files changed, 34 insertions, 0 deletions
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 85ca2503d76..19adc6d8294 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -439,6 +439,9 @@ public: TemplateOrInstantiation = Template; } + /// getDestructor - Returns the destructor decl for this class. + const CXXDestructorDecl *getDestructor(ASTContext &Context); + /// viewInheritance - Renders and displays an inheritance diagram /// for this C++ class and all of its base classes (transitively) using /// GraphViz. diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 30d76cb9e3d..5b806fae7b8 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -187,6 +187,23 @@ void CXXRecordDecl::addConversionFunction(ASTContext &Context, Conversions.addOverload(ConvDecl); } +const CXXDestructorDecl * +CXXRecordDecl::getDestructor(ASTContext &Context) { + QualType ClassType = Context.getTypeDeclType(this); + + DeclarationName Name + = Context.DeclarationNames.getCXXDestructorName(ClassType); + + DeclContext::lookup_iterator I, E; + llvm::tie(I, E) = lookup(Context, Name); + assert(I != E && "Did not find a destructor!"); + + const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I); + assert(++I == E && "Found more than one destructor!"); + + return Dtor; +} + CXXMethodDecl * CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation L, DeclarationName N, diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index 94d69d846c6..6ab59e11b6e 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -166,6 +166,14 @@ CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D, EmitCXXMemberCall(D, Callee, This, ArgBeg, ArgEnd); } +void CodeGenFunction::EmitCXXDestructorCall(const CXXDestructorDecl *D, + CXXDtorType Type, + llvm::Value *This) { + llvm::Value *Callee = CGM.GetAddrOfCXXDestructor(D, Type); + + EmitCXXMemberCall(D, Callee, This, 0, 0); +} + void CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E) { diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 7c54a4da04a..d7d6c729adf 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -37,6 +37,7 @@ namespace llvm { namespace clang { class ASTContext; + class CXXDestructorDecl; class Decl; class EnumConstantDecl; class FunctionDecl; @@ -476,6 +477,9 @@ public: CallExpr::const_arg_iterator ArgBeg, CallExpr::const_arg_iterator ArgEnd); + void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, + llvm::Value *This); + //===--------------------------------------------------------------------===// // Declaration Emission //===--------------------------------------------------------------------===// diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 04693fd502e..b69301ed589 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -576,6 +576,8 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) { if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(D)) EmitCXXConstructor(CD, GD.getCtorType()); + else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D)) + EmitCXXDestructor(DD, GD.getDtorType()); else if (isa<FunctionDecl>(D)) EmitGlobalFunctionDefinition(GD); else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) |