From ecd03b447bb0e2ed1954c77441d49a4a17ca8138 Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 25 Sep 2012 10:10:39 +0000 Subject: When performing a ::delete of an object with a virtual destructor, be sure to delete the complete object pointer, not the original pointer. This is necessary if the base being deleted is at a non-zero offset in the complete object. This is only required for objects with virtual destructors because deleting an object via a base-class subobject when the base does not have a virtual destructor is undefined behavior. Noticed while reviewing the last four years of cxx-abi-dev activity. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164597 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprCXX.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/CGExprCXX.cpp') diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index 3aa5e74781..7276440a47 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -1382,8 +1382,14 @@ static void EmitObjectDelete(CodeGenFunction &CGF, if (UseGlobalDelete) { // If we're supposed to call the global delete, make sure we do so // even if the destructor throws. + + // Derive the complete-object pointer, which is what we need + // to pass to the deallocation function. + llvm::Value *completePtr = + CGF.CGM.getCXXABI().adjustToCompleteObject(CGF, Ptr, ElementType); + CGF.EHStack.pushCleanup(NormalAndEHCleanup, - Ptr, OperatorDelete, + completePtr, OperatorDelete, ElementType); } -- cgit v1.2.3