diff options
author | John McCall <rjmccall@apple.com> | 2012-09-25 10:10:39 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2012-09-25 10:10:39 +0000 |
commit | 82fb892019bd1784153587a69d5bdfc72736d0ee (patch) | |
tree | c4f9f3b9512d8f2b045d115e43066a5985c499e2 /clang/lib/CodeGen/CGExprCXX.cpp | |
parent | 8b907e8acbacc4485b0c5cc4777d5d5844ece52d (diff) | |
download | bcm5719-llvm-82fb892019bd1784153587a69d5bdfc72736d0ee.tar.gz bcm5719-llvm-82fb892019bd1784153587a69d5bdfc72736d0ee.zip |
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.
llvm-svn: 164597
Diffstat (limited to 'clang/lib/CodeGen/CGExprCXX.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExprCXX.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index 3aa5e747812..7276440a47a 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/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<CallObjectDelete>(NormalAndEHCleanup, - Ptr, OperatorDelete, + completePtr, OperatorDelete, ElementType); } |