summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExprCXX.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-07-13 00:54:47 +0000
committerDouglas Gregor <dgregor@apple.com>2011-07-13 00:54:47 +0000
commit1c2e20d73d39b6b3087e33fb8c7aa58b463017b9 (patch)
treec8953e89042c541f9f432a1dae41d0f5b7c5eb23 /clang/lib/CodeGen/CGExprCXX.cpp
parentee6e776be2e4f68606378906e8079a9dfda5a47b (diff)
downloadbcm5719-llvm-1c2e20d73d39b6b3087e33fb8c7aa58b463017b9.tar.gz
bcm5719-llvm-1c2e20d73d39b6b3087e33fb8c7aa58b463017b9.zip
When compiling ::delete for a class with a virtual destructor, call
the complete destructor and then invoke the global delete operator. Previously, we would invoke the deleting destructor, which calls the wrong delete operator. Fixes PR10341. llvm-svn: 135021
Diffstat (limited to 'clang/lib/CodeGen/CGExprCXX.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprCXX.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 9139eb6035d..6b1b88924aa 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1211,7 +1211,8 @@ namespace {
static void EmitObjectDelete(CodeGenFunction &CGF,
const FunctionDecl *OperatorDelete,
llvm::Value *Ptr,
- QualType ElementType) {
+ QualType ElementType,
+ bool UseGlobalDelete) {
// Find the destructor for the type, if applicable. If the
// destructor is virtual, we'll just emit the vcall and return.
const CXXDestructorDecl *Dtor = 0;
@@ -1221,17 +1222,30 @@ static void EmitObjectDelete(CodeGenFunction &CGF,
Dtor = RD->getDestructor();
if (Dtor->isVirtual()) {
+ if (UseGlobalDelete) {
+ // If we're supposed to call the global delete, make sure we do so
+ // even if the destructor throws.
+ CGF.EHStack.pushCleanup<CallObjectDelete>(NormalAndEHCleanup,
+ Ptr, OperatorDelete,
+ ElementType);
+ }
+
const llvm::Type *Ty =
CGF.getTypes().GetFunctionType(CGF.getTypes().getFunctionInfo(Dtor,
Dtor_Complete),
/*isVariadic=*/false);
llvm::Value *Callee
- = CGF.BuildVirtualCall(Dtor, Dtor_Deleting, Ptr, Ty);
+ = CGF.BuildVirtualCall(Dtor,
+ UseGlobalDelete? Dtor_Complete : Dtor_Deleting,
+ Ptr, Ty);
CGF.EmitCXXMemberCall(Dtor, Callee, ReturnValueSlot(), Ptr, /*VTT=*/0,
0, 0);
- // The dtor took care of deleting the object.
+ if (UseGlobalDelete) {
+ CGF.PopCleanupBlock();
+ }
+
return;
}
}
@@ -1477,7 +1491,8 @@ void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
if (E->isArrayForm()) {
EmitArrayDelete(*this, E, Ptr, DeleteTy);
} else {
- EmitObjectDelete(*this, E->getOperatorDelete(), Ptr, DeleteTy);
+ EmitObjectDelete(*this, E->getOperatorDelete(), Ptr, DeleteTy,
+ E->isGlobalDelete());
}
EmitBlock(DeleteEnd);
OpenPOWER on IntegriCloud