[cfe-commits] r167374 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/arc-captured-block-var-inlined-layout.m test/CodeGenObjC/mrr-captured-block-var-inlined-layout.m

Fariborz Jahanian fjahanian at apple.com
Sun Nov 4 10:19:41 PST 2012


Author: fjahanian
Date: Sun Nov  4 12:19:40 2012
New Revision: 167374

URL: http://llvm.org/viewvc/llvm-project?rev=167374&view=rev
Log:
Fixes liftime of captured block variables in mrr mode, per John's feedback, as
well as couple of tests which were not being excercised because of TYPOs.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/test/CodeGenObjC/arc-captured-block-var-inlined-layout.m
    cfe/trunk/test/CodeGenObjC/mrr-captured-block-var-inlined-layout.m

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=167374&r1=167373&r2=167374&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sun Nov  4 12:19:40 2012
@@ -942,7 +942,7 @@
                            unsigned int BytePos, bool ForStrongLayout,
                            bool &HasUnion);
   
-  Qualifiers::ObjCLifetime GetObjCLifeTime(QualType QT);
+  Qualifiers::ObjCLifetime getBlockCaptureLifetime(QualType QT);
   
   void UpdateRunSkipBlockVars(bool IsByref,
                               Qualifiers::ObjCLifetime LifeTime,
@@ -1964,21 +1964,16 @@
   return C;
 }
 
-Qualifiers::ObjCLifetime CGObjCCommonMac::GetObjCLifeTime(QualType FQT) {
+/// getBlockCaptureLifetime - This routine returns life time of the captured
+/// block variable for the purpose of block layout meta-data generation. FQT is
+/// the type of the variable captured in the block.
+Qualifiers::ObjCLifetime CGObjCCommonMac::getBlockCaptureLifetime(QualType FQT) {
   if (CGM.getLangOpts().ObjCAutoRefCount)
     return FQT.getObjCLifetime();
   
-  // MRR, is more ad hoc.
-  if (FQT.isObjCGCStrong())
-    return Qualifiers::OCL_Strong;
-  if (FQT.isObjCGCWeak())
-    return Qualifiers::OCL_Weak;
-  
+  // MRR.
   if (FQT->isObjCObjectPointerType() || FQT->isBlockPointerType())
-    return Qualifiers::OCL_Strong;
-  
-  if (const PointerType *PT = FQT->getAs<PointerType>())
-    return (GetObjCLifeTime(PT->getPointeeType()));
+    return Qualifiers::OCL_ExplicitNone;
   
   return Qualifiers::OCL_None;
 }
@@ -2095,7 +2090,7 @@
       }
     } else {
       UpdateRunSkipBlockVars(false,
-                             GetObjCLifeTime(FQT),
+                             getBlockCaptureLifetime(FQT),
                              BytePos + FieldOffset,
                              FieldSize);
     }
@@ -2110,7 +2105,7 @@
                         ((BitFieldSize % ByteSizeInBits) != 0);
       Size += LastBitfieldOrUnnamedOffset;
       UpdateRunSkipBlockVars(false,
-                             GetObjCLifeTime(LastFieldBitfieldOrUnnamed->getType()),
+                             getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType()),
                              BytePos + LastBitfieldOrUnnamedOffset,
                              Size*ByteSizeInBits);
     } else {
@@ -2119,7 +2114,7 @@
       unsigned FieldSize
         = CGM.getContext().getTypeSize(LastFieldBitfieldOrUnnamed->getType());
       UpdateRunSkipBlockVars(false,
-                             GetObjCLifeTime(LastFieldBitfieldOrUnnamed->getType()),
+                             getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType()),
                              BytePos + LastBitfieldOrUnnamedOffset,
                              FieldSize);
     }
@@ -2127,7 +2122,7 @@
   
   if (MaxField)
     UpdateRunSkipBlockVars(false,
-                           GetObjCLifeTime(MaxField->getType()),
+                           getBlockCaptureLifetime(MaxField->getType()),
                            BytePos + MaxFieldOffset,
                            MaxUnionSize);
 }
@@ -2295,7 +2290,7 @@
     }
     unsigned fieldSize = ci->isByRef() ? WordSizeInBits
                                        : CGM.getContext().getTypeSize(type);
-    UpdateRunSkipBlockVars(ci->isByRef(), GetObjCLifeTime(type),
+    UpdateRunSkipBlockVars(ci->isByRef(), getBlockCaptureLifetime(type),
                            fieldOffset, fieldSize);
   }
   

Modified: cfe/trunk/test/CodeGenObjC/arc-captured-block-var-inlined-layout.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-captured-block-var-inlined-layout.m?rev=167374&r1=167373&r2=167374&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/arc-captured-block-var-inlined-layout.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-captured-block-var-inlined-layout.m Sun Nov  4 12:19:40 2012
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-runtime-has-weak -triple x86_64-apple-darwin -O0 -emit-llvm %s -o %t-64.s
+// RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-runtime-has-weak -triple x86_64-apple-darwin -O0 -emit-llvm %s -o - | FileCheck %s
 // rdar://12184410
 
 void x(id y) {}
@@ -15,13 +15,13 @@
     __block id bl_var1;
 
 //  Inline instruction for block variable layout: 0x0100
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 256 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 256 }
     void (^b)() = ^{
         x(bar);
     };    
 
 // Inline instruction for block variable layout: 0x0210
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 528 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 528 }
     void (^c)() = ^{
         x(bar);
         x(baz);
@@ -29,7 +29,7 @@
     };    
 
 // Inline instruction for block variable layout: 0x0230
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 560 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 560 }
     void (^d)() = ^{
         x(bar);
         x(baz);
@@ -39,7 +39,7 @@
     };
 
 // Inline instruction for block variable layout: 0x0231
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 561 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 561 }
     __weak id wid;
     id (^e)() = ^{
         x(bar);
@@ -51,7 +51,7 @@
     };
 
 // Inline instruction for block variable layout: 0x0235
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 565 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 565 }
     __weak id wid1, wid2, wid3, wid4;
     id (^f)() = ^{
         x(bar);
@@ -67,7 +67,7 @@
     };
 
 // Inline instruction for block variable layout: 0x035
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 53 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 53 }
     id (^g)() = ^{
         byref_int = 1;
         bl_var1 = 0;
@@ -80,20 +80,20 @@
     };
 
 // Inline instruction for block variable layout: 0x01
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 1 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 1 }
     id (^h)() = ^{
         return wid;
     };
 
 // Inline instruction for block variable layout: 0x020
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 32 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 32 }
     void (^ii)() = ^{
        byref_int = 1;
        byref_bab = 0;
     };
 
 // Inline instruction for block variable layout: 0x0102
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 258 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 258 }
     void (^jj)() = ^{
       x(bar);
       x(wid1);

Modified: cfe/trunk/test/CodeGenObjC/mrr-captured-block-var-inlined-layout.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/mrr-captured-block-var-inlined-layout.m?rev=167374&r1=167373&r2=167374&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/mrr-captured-block-var-inlined-layout.m (original)
+++ cfe/trunk/test/CodeGenObjC/mrr-captured-block-var-inlined-layout.m Sun Nov  4 12:19:40 2012
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin -O0 -emit-llvm %s -o %t-64.s
+// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin -O0 -emit-llvm %s -o - | FileCheck %s
 // rdar://12184410
 
 void x(id y) {}
@@ -15,22 +15,22 @@
     __block id byref_bab = (id)0;
     __block id bl_var1;
 
-//  Inline instruction for block variable layout: 0x0100
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 256 }
+// block variable layout: BL_UNRETAINED:1, BL_OPERATOR:0
+// CHECK: @"\01L_OBJC_CLASS_NAME_{{.*}}" = internal global [2 x i8] c"`\00"
     void (^b)() = ^{
         x(bar);
     };    
 
-// Inline instruction for block variable layout: 0x0210
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 528 }
+// block variable layout: BL_UNRETAINED:2, BL_BYREF:1, BL_OPERATOR:0
+// CHECK: @"\01L_OBJC_CLASS_NAME_{{.*}}" = internal global [3 x i8] c"a@\00"
     void (^c)() = ^{
         x(bar);
         x(baz);
         byref_int = 1;
     };    
 
-// Inline instruction for block variable layout: 0x0230
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 560 }
+// block variable layout: BL_UNRETAINED:2, BL_BYREF:3, BL_OPERATOR:0
+// CHECK: @"\01L_OBJC_CLASS_NAME_{{.*}}" = internal global [3 x i8] c"aB\00
     void (^d)() = ^{
         x(bar);
         x(baz);
@@ -39,8 +39,8 @@
         byref_bab = 0;
     };
 
-// Inline instruction for block variable layout: 0x0230
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 560 }
+// block variable layout: BL_UNRETAINED:2, BL_BYREF:3, BL_OPERATOR:0
+// CHECK: @"\01L_OBJC_CLASS_NAME_{{.*}}" = internal global [3 x i8] c"aB\00"
     id (^e)() = ^{
         x(bar);
         x(baz);
@@ -51,7 +51,7 @@
     };
 
 // Inline instruction for block variable layout: 0x020
-// CKECK-LP64: i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i64 32 }
+// CHECK: i8* getelementptr inbounds ([6 x i8]* {{@.*}}, i32 0, i32 0), i64 32 }
     void (^ii)() = ^{
        byref_int = 1;
        byref_bab = 0;





More information about the cfe-commits mailing list