[cfe-commits] r72591 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclCXX.cpp lib/CodeGen/CGCXX.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp
Anders Carlsson
andersca at mac.com
Fri May 29 14:03:38 PDT 2009
Author: andersca
Date: Fri May 29 16:03:38 2009
New Revision: 72591
URL: http://llvm.org/viewvc/llvm-project?rev=72591&view=rev
Log:
Add code for emitting C++ destructors. Not used yet.
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=72591&r1=72590&r2=72591&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Fri May 29 16:03:38 2009
@@ -439,6 +439,9 @@
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.
Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=72591&r1=72590&r2=72591&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Fri May 29 16:03:38 2009
@@ -187,6 +187,23 @@
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,
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=72591&r1=72590&r2=72591&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri May 29 16:03:38 2009
@@ -166,6 +166,14 @@
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) {
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=72591&r1=72590&r2=72591&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri May 29 16:03:38 2009
@@ -37,6 +37,7 @@
namespace clang {
class ASTContext;
+ class CXXDestructorDecl;
class Decl;
class EnumConstantDecl;
class FunctionDecl;
@@ -476,6 +477,9 @@
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd);
+ void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
+ llvm::Value *This);
+
//===--------------------------------------------------------------------===//
// Declaration Emission
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=72591&r1=72590&r2=72591&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri May 29 16:03:38 2009
@@ -576,6 +576,8 @@
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))
More information about the cfe-commits
mailing list