diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-11-13 22:29:45 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-11-13 22:29:45 +0000 |
commit | ebea00581283314330a709a08b333e8a092ceb5a (patch) | |
tree | be18593c20b74801ebb2eedfd35989f633806d34 | |
parent | 6e9901494788dffd7e300dec5c3fbbd756d738c0 (diff) | |
download | bcm5719-llvm-ebea00581283314330a709a08b333e8a092ceb5a.tar.gz bcm5719-llvm-ebea00581283314330a709a08b333e8a092ceb5a.zip |
Code gen. For virtual destructor call on array objects
(still part of pr5472).
llvm-svn: 88712
-rw-r--r-- | clang/lib/CodeGen/CGCXX.cpp | 11 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGCXXExpr.cpp | 1 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/array-operator-delete-call.cpp | 11 |
3 files changed, 21 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index c23ad597649..bcb0b5c5c3b 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -567,7 +567,16 @@ CodeGenFunction::EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, Counter = Builder.CreateLoad(IndexPtr); Counter = Builder.CreateSub(Counter, One); llvm::Value *Address = Builder.CreateInBoundsGEP(This, Counter, "arrayidx"); - EmitCXXDestructorCall(D, Dtor_Complete, Address); + if (D->isVirtual()) { + const llvm::Type *Ty = + CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(D), + /*isVariadic=*/false); + + llvm::Value *Callee = BuildVirtualCall(D, Dtor_Deleting, Address, Ty); + EmitCXXMemberCall(D, Callee, Address, 0, 0); + } + else + EmitCXXDestructorCall(D, Dtor_Complete, Address); EmitBlock(ContinueBlock); diff --git a/clang/lib/CodeGen/CGCXXExpr.cpp b/clang/lib/CodeGen/CGCXXExpr.cpp index aa8acab4e61..abf8d16524d 100644 --- a/clang/lib/CodeGen/CGCXXExpr.cpp +++ b/clang/lib/CodeGen/CGCXXExpr.cpp @@ -293,7 +293,6 @@ void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) { Builder.CreateIntCast(NumElements, llvm::Type::getInt64Ty(VMContext), false, "count.tmp"); - assert (!Dtor->isVirtual() && "delete [] with virtual dtors NYI"); EmitCXXAggrDestructorCall(Dtor, NumElements, Ptr); Ptr = AllocatedObjectPtr; } diff --git a/clang/test/CodeGenCXX/array-operator-delete-call.cpp b/clang/test/CodeGenCXX/array-operator-delete-call.cpp index d394aa16739..c23d33632a3 100644 --- a/clang/test/CodeGenCXX/array-operator-delete-call.cpp +++ b/clang/test/CodeGenCXX/array-operator-delete-call.cpp @@ -13,9 +13,16 @@ struct S { int iS; }; +struct V { + V() : iV (++count) { printf("V::V(%d)\n", iV); } + virtual ~V() { printf("V::~V(%d)\n", iV); } + int iV; +}; + struct COST { S *cost; + V *vcost; unsigned *cost_val; ~COST(); @@ -26,6 +33,7 @@ struct COST COST::COST() { cost = new S[3]; + vcost = new V[4]; cost_val = new unsigned[10]; } @@ -34,6 +42,9 @@ COST::~COST() if (cost) { delete [] cost; } + if (vcost) { + delete [] vcost; + } if (cost_val) delete [] cost_val; } |