r251666 - Fix the emission of ARC ivar layouts in the non-fragile Mac runtime.

John McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 29 16:36:14 PDT 2015


Author: rjmccall
Date: Thu Oct 29 18:36:14 2015
New Revision: 251666

URL: http://llvm.org/viewvc/llvm-project?rev=251666&view=rev
Log:
Fix the emission of ARC ivar layouts in the non-fragile Mac runtime.

My previous change in this area accidentally broke the rule when
InstanceBegin was not a multiple of the word size.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/test/CodeGenObjC/arc-ivar-layout.m

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=251666&r1=251665&r2=251666&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Oct 29 18:36:14 2015
@@ -2081,7 +2081,7 @@ llvm::Constant *CGObjCCommonMac::BuildGC
 
   llvm::SmallVector<unsigned char, 32> buffer;
   llvm::Constant *C = builder.buildBitmap(*this, buffer);
-  if (CGM.getLangOpts().ObjCGCBitmapPrint) {
+  if (CGM.getLangOpts().ObjCGCBitmapPrint && !buffer.empty()) {
     printf("\n block variable layout for block: ");
     builder.dump(buffer);
   }
@@ -4861,6 +4861,9 @@ llvm::Constant *IvarLayoutBuilder::build
     endOfLastScanInWords = endOfScanInWords;
   }
 
+  if (buffer.empty())
+    return llvm::ConstantPointerNull::get(CGM.Int8PtrTy);
+
   // For GC layouts, emit a skip to the end of the allocation so that we
   // have precise information about the entire thing.  This isn't useful
   // or necessary for the ARC-style layout strings.
@@ -4922,9 +4925,9 @@ CGObjCCommonMac::BuildIvarLayout(const O
   // up.
   //
   // ARC layout strings only include the class's ivars.  In non-fragile
-  // runtimes, that means starting at InstanceStart.  In fragile runtimes,
-  // there's no InstanceStart, so it means starting at the end of the
-  // superclass, rounded up to word alignment.
+  // runtimes, that means starting at InstanceStart, rounded up to word
+  // alignment.  In fragile runtimes, there's no InstanceStart, so it means
+  // starting at the end of the superclass, rounded up to word alignment.
   //
   // MRC weak layout strings follow the ARC style.
   CharUnits baseOffset;
@@ -4938,10 +4941,12 @@ CGObjCCommonMac::BuildIvarLayout(const O
     } else if (auto superClass = OI->getSuperClass()) {
       auto startOffset =
         CGM.getContext().getASTObjCInterfaceLayout(superClass).getSize();
-      baseOffset = startOffset.RoundUpToAlignment(CGM.getPointerAlign());
+      baseOffset = startOffset;
     } else {
       baseOffset = CharUnits::Zero();
     }
+
+    baseOffset = baseOffset.RoundUpToAlignment(CGM.getPointerAlign());
   }
   else {
     CGM.getContext().DeepCollectObjCIvars(OI, true, ivars);
@@ -4965,7 +4970,7 @@ CGObjCCommonMac::BuildIvarLayout(const O
   llvm::SmallVector<unsigned char, 4> buffer;
   llvm::Constant *C = builder.buildBitmap(*this, buffer);
   
-   if (CGM.getLangOpts().ObjCGCBitmapPrint) {
+   if (CGM.getLangOpts().ObjCGCBitmapPrint && !buffer.empty()) {
     printf("\n%s ivar layout for class '%s': ",
            ForStrongLayout ? "strong" : "weak",
            OMD->getClassInterface()->getName().str().c_str());

Modified: cfe/trunk/test/CodeGenObjC/arc-ivar-layout.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-ivar-layout.m?rev=251666&r1=251665&r2=251666&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/arc-ivar-layout.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-ivar-layout.m Thu Oct 29 18:36:14 2015
@@ -1,6 +1,4 @@
-// RUN: %clang_cc1 -fobjc-arc -fobjc-runtime-has-weak -triple x86_64-apple-darwin -S %s -o %t-64.s
-// RUN: FileCheck -check-prefix CHECK-LP64 --input-file=%t-64.s %s
-// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -fobjc-arc -fobjc-runtime-has-weak -triple x86_64-apple-darwin -print-ivar-layout -emit-llvm %s -o %t-64.s | FileCheck -check-prefix CHECK-LP64 %s
 // rdar://8991729
 
 @interface NSObject {
@@ -17,8 +15,7 @@
 
 @implementation AllPointers
 @end
-// CHECK-LP64: L_OBJC_CLASS_NAME_.1:
-// CHECK-LP64-NEXT: .asciz	"\003"
+// CHECK-LP64: strong ivar layout for class 'AllPointers': 0x03, 0x00
 
 @class NSString, NSNumber;
 @interface A : NSObject {
@@ -38,10 +35,12 @@
 
 @implementation A @end
 
+// CHECK-LP64: strong ivar layout for class 'A': 0x02, 0x00
+// CHECK-LP64: weak ivar layout for class 'A': 0x31, 0x00
+
 @implementation B @end
 
-// CHECK-LP64: L_OBJC_CLASS_NAME_.15:
-// CHECK-LP64-NEXT: .asciz	"\022"
+// CHECK-LP64: strong ivar layout for class 'B': 0x12, 0x00
 
 @interface UnsafePerson {
 @public
@@ -52,8 +51,8 @@
 @end
 
 @implementation UnsafePerson @end
-// CHECK-LP64: L_OBJC_CLASS_NAME_.20:
-// CHECK-LP64-NEXT: .asciz      "!"
+
+// CHECK-LP64: strong ivar layout for class 'UnsafePerson': 0x21, 0x00
 
 // rdar://16136439
 @interface rdar16136439
@@ -61,5 +60,20 @@
 @end
 
 @implementation rdar16136439 @end
-// CHECK-LP64: L_OBJC_PROP_NAME_ATTR_.29:
-// CHECK-LP64-NEXT: .asciz  "T@,R,W,N,V_first"
+
+// CHECK-LP64: weak ivar layout for class 'rdar16136439': 0x01, 0x00
+
+ at interface Misalign : NSObject {
+  char a;
+}
+ at end
+
+ at interface Misaligned : Misalign {
+  char b;
+  id x;
+}
+ at end
+
+ at implementation Misaligned @end
+
+// CHECK-LP64: strong ivar layout for class 'Misaligned': 0x01, 0x00




More information about the cfe-commits mailing list