diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-03 20:20:07 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-03 20:20:07 +0000 |
| commit | 18c062361d6322e2fcfb2c234c527083264b8c5f (patch) | |
| tree | af7a4cdbdffae4e7a5290676c1692dc41cfdb55a /clang | |
| parent | 49bfce4227b7b7f5806f68cdef8d969d15a203a5 (diff) | |
| download | bcm5719-llvm-18c062361d6322e2fcfb2c234c527083264b8c5f.tar.gz bcm5719-llvm-18c062361d6322e2fcfb2c234c527083264b8c5f.zip | |
ir-gen for destructor calls.
llvm-svn: 77991
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 12 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/destructor-calls.cpp | 36 |
2 files changed, 48 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 9fd571b8164..347a0af6968 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -432,6 +432,18 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { } } + // Handle CXX destruction of variables. + // FIXME - destruction of arrays NYI. + if (const RecordType *RT = Ty->getAs<RecordType>()) + if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) { + if (!ClassDecl->hasTrivialDestructor()) { + const CXXDestructorDecl *D = ClassDecl->getDestructor(getContext()); + assert(D && "EmitLocalBlockVarDecl - destructor is nul"); + CleanupScope scope(*this); + EmitCXXDestructorCall(D, Dtor_Complete, DeclPtr); + } + } + // Handle the cleanup attribute if (const CleanupAttr *CA = D.getAttr<CleanupAttr>()) { const FunctionDecl *FD = CA->getFunctionDecl(); diff --git a/clang/test/CodeGenCXX/destructor-calls.cpp b/clang/test/CodeGenCXX/destructor-calls.cpp new file mode 100644 index 00000000000..7b9225590a7 --- /dev/null +++ b/clang/test/CodeGenCXX/destructor-calls.cpp @@ -0,0 +1,36 @@ +// RUN: clang-cc %s -emit-llvm -o %t + +extern "C" int printf(...); + +static int val; + +struct B { + B() : iB(++val) { printf("B()\n"); } + int iB; + ~B() { printf("~B(%d)\n", iB); --val; } +}; + +struct M : B { + M() : iM(++val) { printf("M()\n"); } + int iM; + ~M() { printf("~M(%d)\n", iM); --val; } +}; + +struct P { + P() : iP(++val) { printf("P()\n"); } + int iP; + ~P() { printf("~P(%d)\n", iP); --val; } +}; + +struct N : M, P { + N() { printf("N()\n"); iN = ++val; } + ~N() { printf("~N(%d) val = %d\n", iN, --val); } + int iN; + M m; + P p; +}; + +int main() { + N n1; + N n2; +} |

