[cfe-commits] r102985 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGenCXX/block-destruct.cpp

Fariborz Jahanian fjahanian at apple.com
Mon May 3 17:26:07 PDT 2010


Author: fjahanian
Date: Mon May  3 19:26:07 2010
New Revision: 102985

URL: http://llvm.org/viewvc/llvm-project?rev=102985&view=rev
Log:
Fixes a Code Gen. Crash when calling destructor on a __block
variabe. Blocks and their construction/destruction is
wip though. 

Added:
    cfe/trunk/test/CodeGenCXX/block-destruct.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=102985&r1=102984&r2=102985&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon May  3 19:26:07 2010
@@ -649,6 +649,11 @@
     DtorTy = getContext().getBaseElementType(Array);
   if (const RecordType *RT = DtorTy->getAs<RecordType>())
     if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+      llvm::Value *Loc = DeclPtr;
+      if (isByRef)
+        Loc = Builder.CreateStructGEP(DeclPtr, getByRefValueLLVMField(&D), 
+                                      D.getNameAsString());
+      
       if (!ClassDecl->hasTrivialDestructor()) {
         const CXXDestructorDecl *D = ClassDecl->getDestructor(getContext());
         assert(D && "EmitLocalBlockVarDecl - destructor is nul");
@@ -661,7 +666,7 @@
             const llvm::Type *BasePtr = ConvertType(BaseElementTy);
             BasePtr = llvm::PointerType::getUnqual(BasePtr);
             llvm::Value *BaseAddrPtr =
-              Builder.CreateBitCast(DeclPtr, BasePtr);
+              Builder.CreateBitCast(Loc, BasePtr);
             EmitCXXAggrDestructorCall(D, Array, BaseAddrPtr);
           
             // Make sure to jump to the exit block.
@@ -673,14 +678,14 @@
             const llvm::Type *BasePtr = ConvertType(BaseElementTy);
             BasePtr = llvm::PointerType::getUnqual(BasePtr);
             llvm::Value *BaseAddrPtr =
-              Builder.CreateBitCast(DeclPtr, BasePtr);
+              Builder.CreateBitCast(Loc, BasePtr);
             EmitCXXAggrDestructorCall(D, Array, BaseAddrPtr);
           }
         } else {
           {
             DelayedCleanupBlock Scope(*this);
             EmitCXXDestructorCall(D, Dtor_Complete, /*ForVirtualBase=*/false,
-                                  DeclPtr);
+                                  Loc);
 
             // Make sure to jump to the exit block.
             EmitBranch(Scope.getCleanupExitBlock());
@@ -688,7 +693,7 @@
           if (Exceptions) {
             EHCleanupBlock Cleanup(*this);
             EmitCXXDestructorCall(D, Dtor_Complete, /*ForVirtualBase=*/false,
-                                  DeclPtr);
+                                  Loc);
           }
         }
       }

Added: cfe/trunk/test/CodeGenCXX/block-destruct.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/block-destruct.cpp?rev=102985&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/block-destruct.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/block-destruct.cpp Mon May  3 19:26:07 2010
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -fblocks -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
+
+struct A { ~A(); };
+
+void f() {
+  __block A a;
+}
+
+// CHECK: call void @_ZN1AD1Ev





More information about the cfe-commits mailing list