From f6a077edbbfc88d63b43d43f22db93017685c130 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Sat, 24 Jan 2009 23:43:01 +0000 Subject: [PATCH] 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 --- lib/CodeGen/CGObjCMac.cpp | 43 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index be3a0bdd00..f677782ec3 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -3294,9 +3294,48 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { } + InstanceStart = InstanceSize = 0; + if (ObjCInterfaceDecl *OID = + const_cast(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(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); -- 2.40.0