diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-05-04 21:26:30 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-05-04 21:26:30 +0000 |
commit | b4c79e027fdcc752b5a377611fd4cfbb21611a05 (patch) | |
tree | 56c5003cf11ca50e0b4bd1ca23eb2ffcfaef18d8 /lib/CodeGen | |
parent | c2e57bfc7f784e8f2d6026ec6b03259c1109f120 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70916 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index e735efb490..1a1ef83123 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -4219,35 +4219,16 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassMetaData( 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) { |