[cfe-commits] r77991 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGenCXX/destructor-calls.cpp
Fariborz Jahanian
fjahanian at apple.com
Mon Aug 3 13:20:33 PDT 2009
Author: fjahanian
Date: Mon Aug 3 15:20:07 2009
New Revision: 77991
URL: http://llvm.org/viewvc/llvm-project?rev=77991&view=rev
Log:
ir-gen for destructor calls.
Added:
cfe/trunk/test/CodeGenCXX/destructor-calls.cpp
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=77991&r1=77990&r2=77991&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Aug 3 15:20:07 2009
@@ -432,6 +432,18 @@
}
}
+ // 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();
Added: cfe/trunk/test/CodeGenCXX/destructor-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructor-calls.cpp?rev=77991&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructor-calls.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/destructor-calls.cpp Mon Aug 3 15:20:07 2009
@@ -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;
+}
More information about the cfe-commits
mailing list