[cfe-commits] r118745 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/CodeGen/CGBlocks.h lib/Sema/SemaExpr.cpp test/CodeGenObjC/block-var-layout.m test/CodeGenObjCXX/block-var-layout.mm

Fariborz Jahanian fjahanian at apple.com
Wed Nov 10 16:11:38 PST 2010


Author: fjahanian
Date: Wed Nov 10 18:11:38 2010
New Revision: 118745

URL: http://llvm.org/viewvc/llvm-project?rev=118745&view=rev
Log:
Adding couple of Block API, a bug fix and
a test change, all for blocks. wip.

Added:
    cfe/trunk/test/CodeGenObjCXX/block-var-layout.mm
      - copied, changed from r118688, cfe/trunk/test/CodeGenObjC/block-var-layout.m
Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGBlocks.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/CodeGenObjC/block-var-layout.m

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=118745&r1=118744&r2=118745&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Nov 10 18:11:38 2010
@@ -311,11 +311,10 @@
       }
 
       const BlockDeclRefExpr *BDRE = cast<BlockDeclRefExpr>(E);
+      Note.RequiresCopying = BlockRequiresCopying(BDRE);
+      
       const ValueDecl *VD = BDRE->getDecl();
       QualType T = VD->getType();
-
-      Note.RequiresCopying = BlockRequiresCopying(T);
-
       if (BDRE->isByRef()) {
         Note.flag = BLOCK_FIELD_IS_BYREF;
         if (T.isObjCGCWeak())
@@ -563,7 +562,7 @@
   // Don't run the expensive check, unless we have to.
   if (!BlockHasCopyDispose)
     if (E->isByRef()
-        || BlockRequiresCopying(E->getType()))
+        || BlockRequiresCopying(E))
       BlockHasCopyDispose = true;
 
   const ValueDecl *D = cast<ValueDecl>(E->getDecl());

Modified: cfe/trunk/lib/CodeGen/CGBlocks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.h?rev=118745&r1=118744&r2=118745&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.h (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.h Wed Nov 10 18:11:38 2010
@@ -103,6 +103,9 @@
 
   bool BlockRequiresCopying(QualType Ty)
     { return getContext().BlockRequiresCopying(Ty); }
+  bool BlockRequiresCopying(const BlockDeclRefExpr *E)
+  { return E->getCopyConstructorExpr() != 0 ||
+           getContext().BlockRequiresCopying(E->getType()); }
 };
 
 class BlockFunction : public BlockBase {
@@ -197,6 +200,9 @@
 
   bool BlockRequiresCopying(QualType Ty)
     { return getContext().BlockRequiresCopying(Ty); }
+  bool BlockRequiresCopying(const BlockDeclRefExpr *E)
+  { return E->getCopyConstructorExpr() != 0 ||
+           getContext().BlockRequiresCopying(E->getType()); }
 };
 
 }  // end namespace CodeGen

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=118745&r1=118744&r2=118745&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Nov 10 18:11:38 2010
@@ -1911,16 +1911,18 @@
         Expr *E = new (Context) 
                     DeclRefExpr(const_cast<ValueDecl*>(BDRE->getDecl()), T,
                                           SourceLocation());
-      
-        ExprResult Res = PerformCopyInitialization(
+        if (T->getAs<RecordType>())
+          if (!T->isUnionType()) {
+            ExprResult Res = PerformCopyInitialization(
                           InitializedEntity::InitializeBlock(VD->getLocation(), 
                                                          T, false),
                                                          SourceLocation(),
                                                          Owned(E));
-        if (!Res.isInvalid()) {
-          Res = MaybeCreateCXXExprWithTemporaries(Res.get());
-          Expr *Init = Res.takeAs<Expr>();
-          BDRE->setCopyConstructorExpr(Init);
+            if (!Res.isInvalid()) {
+              Res = MaybeCreateCXXExprWithTemporaries(Res.get());
+              Expr *Init = Res.takeAs<Expr>();
+              BDRE->setCopyConstructorExpr(Init);
+            }
         }
       }
     }

Modified: cfe/trunk/test/CodeGenObjC/block-var-layout.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/block-var-layout.m?rev=118745&r1=118744&r2=118745&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/block-var-layout.m (original)
+++ cfe/trunk/test/CodeGenObjC/block-var-layout.m Wed Nov 10 18:11:38 2010
@@ -1,7 +1,5 @@
 // RUN: %clang_cc1 -fblocks -fobjc-gc -triple x86_64-apple-darwin -O0 -S %s -o %t-64.s
 // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
-// RUN: %clang_cc1 -x objective-c++ -fblocks -fobjc-gc -triple x86_64-apple-darwin -O0 -S %s -o %t-64.s
-// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
 
 struct S {
     int i1;

Copied: cfe/trunk/test/CodeGenObjCXX/block-var-layout.mm (from r118688, cfe/trunk/test/CodeGenObjC/block-var-layout.m)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/block-var-layout.mm?p2=cfe/trunk/test/CodeGenObjCXX/block-var-layout.mm&p1=cfe/trunk/test/CodeGenObjC/block-var-layout.m&r1=118688&r2=118745&rev=118745&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/block-var-layout.m (original)
+++ cfe/trunk/test/CodeGenObjCXX/block-var-layout.mm Wed Nov 10 18:11:38 2010
@@ -1,8 +1,7 @@
-// RUN: %clang_cc1 -fblocks -fobjc-gc -triple x86_64-apple-darwin -O0 -S %s -o %t-64.s
-// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
 // RUN: %clang_cc1 -x objective-c++ -fblocks -fobjc-gc -triple x86_64-apple-darwin -O0 -S %s -o %t-64.s
 // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
 
+
 struct S {
     int i1;
     id o1;
@@ -141,11 +140,11 @@
 // CHECK-LP64: L_OBJC_CLASS_NAME_11:
 // CHECK-LP64-NEXT: .asciz   "\001A\021\021"
 
-// CHECK-LP64: L_OBJC_CLASS_NAME_14:
+// CHECK-LP64: L_OBJC_CLASS_NAME_16:
 // CHECK-LP64-NEXT: .asciz   "\001A\021\022p"
 
-// CHECK-LP64: L_OBJC_CLASS_NAME_16:
+// CHECK-LP64: L_OBJC_CLASS_NAME_20:
 // CHECK-LP64-NEXT: .asciz   "\0013"
 
-// CHECK-LP64: L_OBJC_CLASS_NAME_20:
+// CHECK-LP64: L_OBJC_CLASS_NAME_24:
 // CHECK-LP64-NEXT: .asciz   "\001"





More information about the cfe-commits mailing list