Compute instaceStart/instanceSize fields of the class_ro_t meta-data
for objc2's non-fragile abi.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62945 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index be3a0bd..f677782 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -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);