[cfe-commits] r105641 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp test/CodeGenCXX/copy-in-cplus-object.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Jun 8 13:57:23 PDT 2010


Author: fjahanian
Date: Tue Jun  8 15:57:22 2010
New Revision: 105641

URL: http://llvm.org/viewvc/llvm-project?rev=105641&view=rev
Log:
Block Code Gen. API. Call destructor on descriptior
entry previously constructed via copy constructor.


Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=105641&r1=105640&r2=105641&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Tue Jun  8 15:57:22 2010
@@ -361,8 +361,36 @@
           Builder.CreateStore(Loc, Addr);
           continue;
         } else {
-            if (BDRE->getCopyConstructorExpr())
-              E = BDRE->getCopyConstructorExpr();
+          if (BDRE->getCopyConstructorExpr()) {
+            E = BDRE->getCopyConstructorExpr();
+            // Code to destruct copy-constructed descriptor element for
+            // copied-in class object.
+            // TODO: Refactor this into common code with mostly similar
+            // CodeGenFunction::EmitLocalBlockVarDecl
+            QualType DtorTy = E->getType();
+            if (const RecordType *RT = DtorTy->getAs<RecordType>())
+              if (CXXRecordDecl *ClassDecl = 
+                    dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+                if (!ClassDecl->hasTrivialDestructor()) {
+                  const CXXDestructorDecl *D = 
+                    ClassDecl->getDestructor(getContext());
+                  assert(D && "BuildBlockLiteralTmp - destructor is nul");
+                  {
+                    // Normal destruction. 
+                    DelayedCleanupBlock Scope(*this);
+                    EmitCXXDestructorCall(D, Dtor_Complete, 
+                                          /*ForVirtualBase=*/false, Addr);
+                    // Make sure to jump to the exit block.
+                    EmitBranch(Scope.getCleanupExitBlock());
+                  }
+                  if (Exceptions) {
+                    EHCleanupBlock Cleanup(*this);
+                    EmitCXXDestructorCall(D, Dtor_Complete, 
+                                          /*ForVirtualBase=*/false, Addr);
+                  }
+                }
+              }
+          }
             else {
               E = new (getContext()) DeclRefExpr(const_cast<ValueDecl*>(VD),
                                             VD->getType().getNonReferenceType(),

Modified: cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp?rev=105641&r1=105640&r2=105641&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp Tue Jun  8 15:57:22 2010
@@ -9,6 +9,7 @@
 {
 	TestObject(const TestObject& inObj, int def = 100,  const S &Silly = "silly");
 	TestObject();
+	~TestObject();
 	TestObject& operator=(const TestObject& inObj);
 	int version() const;
 
@@ -23,4 +24,5 @@
 // CHECK: call void @_ZN1SC1EPKc
 // CHECK: call void @_ZN10TestObjectC1ERKS_iRK1S
 // CHECK: call void @_ZN1SD1Ev
-
+// CHECK: call void @_ZN10TestObjectD1Ev
+// CHECK: call void @_ZN10TestObjectD1Ev





More information about the cfe-commits mailing list