[cfe-commits] r70916 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/interface-layout-64.m

Daniel Dunbar daniel at zuster.org
Mon May 4 14:26:31 PDT 2009


Author: ddunbar
Date: Mon May  4 16:26:30 2009
New Revision: 70916

URL: http://llvm.org/viewvc/llvm-project?rev=70916&view=rev
Log:
Compute interface instanceStart and instanceSize using the record
layout.
 - This is much simpler / more efficient.

 - This also properly computes the size in the presence of bit-fields.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/test/CodeGenObjC/interface-layout-64.m

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=70916&r1=70915&r2=70916&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon May  4 16:26:30 2009
@@ -4219,35 +4219,16 @@
 void CGObjCNonFragileABIMac::GetClassSizeInfo(const ObjCImplementationDecl *OID,
                                               uint32_t &InstanceStart,
                                               uint32_t &InstanceSize) {
-  // Find first and last (non-padding) ivars in this interface.
-
-  // FIXME: Use iterator.
-  llvm::SmallVector<ObjCIvarDecl*, 16> OIvars;
-  GetNamedIvarList(OID->getClassInterface(), OIvars);
-
-  if (OIvars.empty()) {
+  const ASTRecordLayout &RL = 
+    CGM.getContext().getASTObjCImplementationLayout(OID);
+  
+  if (!RL.getFieldCount()) {
     InstanceStart = InstanceSize = 0;
     return;
   }
 
-  const ObjCIvarDecl *First = OIvars.front();
-  const ObjCIvarDecl *Last = OIvars.back();
-
-  InstanceStart = ComputeIvarBaseOffset(CGM, OID, First);
-  const llvm::Type *FieldTy =
-    CGM.getTypes().ConvertTypeForMem(Last->getType());
-  unsigned Size = CGM.getTargetData().getTypePaddedSize(FieldTy);
-// FIXME. This breaks compatibility with llvm-gcc-4.2 (but makes it compatible
-// with gcc-4.2). We postpone this for now.
-#if 0
-  if (Last->isBitField()) {
-    Expr *BitWidth = Last->getBitWidth();
-    uint64_t BitFieldSize =
-      BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue();
-    Size = (BitFieldSize / 8) + ((BitFieldSize % 8) != 0);
-  }
-#endif
-  InstanceSize = ComputeIvarBaseOffset(CGM, OID, Last) + Size;
+  InstanceStart = RL.getFieldOffset(0) / 8;
+  InstanceSize = llvm::RoundUpToAlignment(RL.getNextOffset(), 8) / 8;
 }
 
 void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) {

Modified: cfe/trunk/test/CodeGenObjC/interface-layout-64.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/interface-layout-64.m?rev=70916&r1=70915&r2=70916&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenObjC/interface-layout-64.m (original)
+++ cfe/trunk/test/CodeGenObjC/interface-layout-64.m Mon May  4 16:26:30 2009
@@ -7,6 +7,8 @@
 // RUN: grep '@"OBJC_IVAR_$_I5._iv5" = global i64 24, section "__DATA, __objc_const", align 8' %t &&
 // RUN: grep '@"OBJC_IVAR_$_I5._iv6_synth" = global i64 28, section "__DATA, __objc_const", align 8' %t &&
 // RUN: grep '@"OBJC_IVAR_$_I5._iv7_synth" = global i64 32, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I6" = internal global .* { i32 2, i32 0, i32 1, .*' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I8" = internal global .* { i32 0, i32 8, i32 16, .*' %t &&
 
 // RUN: true
 
@@ -54,3 +56,24 @@
 @synthesize prop1 = _iv7_synth;
 @synthesize prop2 = _iv5;
 @end
+
+// The size rounds up to the next available byte.
+ at interface I6 {
+  unsigned iv0 : 2;
+}
+ at end
+ at implementation I6
+ at end
+
+// The start of the subclass includes padding for its own alignment.
+ at interface I7 {
+  char a;
+}
+ at end
+ at interface I8 : I7 {
+  double b;
+}
+ at end
+ at implementation I8
+ at end
+





More information about the cfe-commits mailing list