[cfe-commits] r85512 - /cfe/trunk/lib/CodeGen/CGDecl.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Oct 29 09:22:54 PDT 2009


Author: fjahanian
Date: Thu Oct 29 11:22:54 2009
New Revision: 85512

URL: http://llvm.org/viewvc/llvm-project?rev=85512&view=rev
Log:
Patch for destruction of array of objects on block exit.


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=85512&r1=85511&r2=85512&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Thu Oct 29 11:22:54 2009
@@ -492,16 +492,25 @@
   // Handle CXX destruction of variables.
   QualType DtorTy(Ty);
   if (const ArrayType *Array = DtorTy->getAs<ArrayType>())
-    DtorTy = Array->getElementType();
+    DtorTy = getContext().getBaseElementType(Array);
   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 && "EmitLocalBlockVarDecl - destructor is nul");
-        assert(!Ty->getAs<ArrayType>() && "FIXME - destruction of arrays NYI");
-
+        
         CleanupScope scope(*this);
-        EmitCXXDestructorCall(D, Dtor_Complete, DeclPtr);
+        if (const ConstantArrayType *Array = 
+              getContext().getAsConstantArrayType(Ty)) {
+          QualType BaseElementTy = getContext().getBaseElementType(Array);
+          const llvm::Type *BasePtr = ConvertType(BaseElementTy);
+          BasePtr = llvm::PointerType::getUnqual(BasePtr);
+          llvm::Value *BaseAddrPtr =
+            Builder.CreateBitCast(DeclPtr, BasePtr);
+          EmitCXXAggrDestructorCall(D, Array, BaseAddrPtr);
+        }
+        else
+          EmitCXXDestructorCall(D, Dtor_Complete, DeclPtr);
       }
   }
 





More information about the cfe-commits mailing list