[cfe-commits] r62945 - /cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Fariborz Jahanian fjahanian at apple.com
Sat Jan 24 15:43:02 PST 2009


Author: fjahanian
Date: Sat Jan 24 17:43:01 2009
New Revision: 62945

URL: http://llvm.org/viewvc/llvm-project?rev=62945&view=rev
Log:
Compute instaceStart/instanceSize fields of the class_ro_t meta-data
for objc2's non-fragile abi.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sat Jan 24 17:43:01 2009
@@ -3294,9 +3294,48 @@
     
   }
   
+  InstanceStart = InstanceSize = 0;
+  if (ObjCInterfaceDecl *OID = 
+      const_cast<ObjCInterfaceDecl*>(ID->getClassInterface())) {
+    // FIXME. Share this with the one in EmitIvarList.
+    int countSuperClassIvars = countInheritedIvars(OID->getSuperClass());
+    const RecordDecl *RD = CGM.getContext().addRecordToClass(OID);
+    RecordDecl::field_iterator firstField = RD->field_begin();
+    RecordDecl::field_iterator lastField = RD->field_end();
+    
+    while (countSuperClassIvars-- > 0) {
+      lastField = firstField;
+      ++firstField;
+    }
+    
+    for (RecordDecl::field_iterator e = RD->field_end(),
+         ifield = firstField; ifield != e; ++ifield)
+      lastField = ifield;
+    
+    const llvm::Type *InterfaceTy = 
+      CGM.getTypes().ConvertType(CGM.getContext().getObjCInterfaceType(OID));
+    const llvm::StructLayout *Layout =
+     CGM.getTargetData().getStructLayout(cast<llvm::StructType>(InterfaceTy));
+     
+    if (lastField != RD->field_end()) {
+      FieldDecl *Field = *lastField;
+      const llvm::Type *FieldTy =
+        CGM.getTypes().ConvertTypeForMem(Field->getType());
+      unsigned Size = CGM.getTargetData().getTypePaddedSize(FieldTy);
+      InstanceSize = Layout->getElementOffset(
+                                  CGM.getTypes().getLLVMFieldNo(Field)) + 
+                                  Size;
+      if (firstField == RD->field_end())
+        InstanceStart = InstanceSize;
+      else
+        InstanceStart =  Layout->getElementOffset(CGM.getTypes().
+                                                  getLLVMFieldNo(*firstField));
+    }
+  }
   CLASS_RO_GV = BuildClassRoTInitializer(flags,
-                                         0,
-                                         0,ID);
+                                         InstanceStart,
+                                         InstanceSize, 
+                                         ID);
   
   TClassName = ObjCClassName + ClassName;
   BuildClassMetaData(TClassName, MetaTClass, SuperClassGV, CLASS_RO_GV);





More information about the cfe-commits mailing list