[cfe-commits] r90578 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/virtual-destructor-calls.cpp
Anders Carlsson
andersca at mac.com
Fri Dec 4 11:33:17 PST 2009
Author: andersca
Date: Fri Dec 4 13:33:17 2009
New Revision: 90578
URL: http://llvm.org/viewvc/llvm-project?rev=90578&view=rev
Log:
When generating a virtual destructor, don't try to make a virtual call to the base class destructor because then we'll just re-enter the same destructor!
This was done to fix PR5619, so I went ahead and passed a dummy VTT pointer for now.
Added:
cfe/trunk/test/CodeGenCXX/virtual-destructor-calls.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=90578&r1=90577&r2=90578&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Dec 4 13:33:17 2009
@@ -691,21 +691,29 @@
EmitCXXMemberCall(D, Callee, This, ArgBeg, ArgEnd);
}
-void CodeGenFunction::EmitCXXDestructorCall(const CXXDestructorDecl *D,
+void CodeGenFunction::EmitCXXDestructorCall(const CXXDestructorDecl *DD,
CXXDtorType Type,
llvm::Value *This) {
- if (D->isVirtual()) {
- const llvm::Type *Ty =
- CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(D),
- /*isVariadic=*/false);
+ llvm::Value *Callee = CGM.GetAddrOfCXXDestructor(DD, Type);
+
+ CallArgList Args;
+
+ // Push the this ptr.
+ Args.push_back(std::make_pair(RValue::get(This),
+ DD->getThisType(getContext())));
+
+ // Add a VTT parameter if necessary.
+ // FIXME: This should not be a dummy null parameter!
+ if (Type == Dtor_Base && DD->getParent()->getNumVBases() != 0) {
+ QualType T = getContext().getPointerType(getContext().VoidPtrTy);
- llvm::Value *Callee = BuildVirtualCall(D, Dtor_Deleting, This, Ty);
- EmitCXXMemberCall(D, Callee, This, 0, 0);
- return;
+ Args.push_back(std::make_pair(RValue::get(CGM.EmitNullConstant(T)), T));
}
- llvm::Value *Callee = CGM.GetAddrOfCXXDestructor(D, Type);
- EmitCXXMemberCall(D, Callee, This, 0, 0);
+ // FIXME: We should try to share this code with EmitCXXMemberCall.
+
+ QualType ResultType = DD->getType()->getAs<FunctionType>()->getResultType();
+ EmitCall(CGM.getTypes().getFunctionInfo(ResultType, Args), Callee, Args, DD);
}
void
Added: cfe/trunk/test/CodeGenCXX/virtual-destructor-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-destructor-calls.cpp?rev=90578&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-destructor-calls.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/virtual-destructor-calls.cpp Fri Dec 4 13:33:17 2009
@@ -0,0 +1,24 @@
+// RUN: clang-cc -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s
+
+struct A {
+ virtual ~A();
+};
+
+struct B : A {
+ virtual ~B();
+};
+
+// Deleting dtor.
+// CHECK: define void @_ZN1BD0Ev
+// CHECK: call void @_ZN1AD2Ev
+// check: call void @_ZdlPv
+
+// Complete dtor.
+// CHECK: define void @_ZN1BD1Ev
+// CHECK: call void @_ZN1AD2Ev
+
+// Base dtor.
+// CHECK: define void @_ZN1BD2Ev
+// CHECK: call void @_ZN1AD2Ev
+
+B::~B() { }
More information about the cfe-commits
mailing list