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
--- /dev/null
+// 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() { }