[cfe-commits] r66345 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/bitfield-ivar-metadata.m
Fariborz Jahanian
fjahanian at apple.com
Sat Mar 7 11:43:21 PST 2009
Author: fjahanian
Date: Sat Mar 7 13:43:20 2009
New Revision: 66345
URL: http://llvm.org/viewvc/llvm-project?rev=66345&view=rev
Log:
correct bitfield ivar offset in ivar meta-data.
(objc abi specific).
Added:
cfe/trunk/test/CodeGenObjC/bitfield-ivar-metadata.m
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=66345&r1=66344&r2=66345&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sat Mar 7 13:43:20 2009
@@ -1706,8 +1706,13 @@
const RecordDecl *RD = GetFirstIvarInRecord(OID, ifield, pfield);
for (RecordDecl::field_iterator e = RD->field_end(); ifield != e; ++ifield) {
FieldDecl *Field = *ifield;
- unsigned Offset = Layout->getElementOffset(CGM.getTypes().
- getLLVMFieldNo(Field));
+ unsigned Offset;
+ if (Field->isBitField())
+ // Bit field staring offset is cached in FieldInfo[Field].
+ Offset = CGM.getTypes().getLLVMFieldNo(Field);
+ else
+ Offset = Layout->getElementOffset(CGM.getTypes().
+ getLLVMFieldNo(Field));
if (Field->getIdentifier())
Ivar[0] = GetMethodVarName(Field->getIdentifier());
else
@@ -2267,8 +2272,9 @@
const llvm::StructLayout *Layout =
CGM.getTargetData().getStructLayout(cast<llvm::StructType>(InterfaceLTy));
FieldDecl *Field = Interface->lookupFieldDeclForIvar(CGM.getContext(), Ivar);
- uint64_t Offset =
- Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
+ uint64_t Offset =
+ Field->isBitField() ? CGM.getTypes().getLLVMFieldNo(Field) :
+ Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
return llvm::ConstantInt::get(
CGM.getTypes().ConvertType(CGM.getContext().LongTy),
@@ -3841,14 +3847,18 @@
const llvm::Type *FieldTy =
CGM.getTypes().ConvertTypeForMem(Field->getType());
unsigned Size = CGM.getTargetData().getTypePaddedSize(FieldTy);
- InstanceSize = Layout->getElementOffset(
- CGM.getTypes().getLLVMFieldNo(Field)) +
- Size;
+ uint64_t Offset =
+ Field->isBitField() ? CGM.getTypes().getLLVMFieldNo(Field) :
+ Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
+ InstanceSize = Offset + Size;
if (firstField == RD->field_end())
InstanceStart = InstanceSize;
- else
- InstanceStart = Layout->getElementOffset(CGM.getTypes().
- getLLVMFieldNo(*firstField));
+ else {
+ Field = *firstField;
+ InstanceStart =
+ Field->isBitField() ? CGM.getTypes().getLLVMFieldNo(Field) :
+ Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
+ }
}
}
CLASS_RO_GV = BuildClassRoTInitializer(flags,
@@ -4150,8 +4160,13 @@
for (RecordDecl::field_iterator e = RD->field_end(); i != e; ++i) {
FieldDecl *Field = *i;
- unsigned long offset = Layout->getElementOffset(CGM.getTypes().
- getLLVMFieldNo(Field));
+ unsigned long offset;
+ if (Field->isBitField())
+ // Bit field starting offset is cached in FieldInfo[Field].
+ offset = CGM.getTypes().getLLVMFieldNo(Field);
+ else
+ offset = Layout->getElementOffset(CGM.getTypes().
+ getLLVMFieldNo(Field));
const ObjCIvarDecl *ivarDecl = *I++;
Ivar[0] = EmitIvarOffsetVar(ID->getClassInterface(), ivarDecl, offset);
if (Field->getIdentifier())
Added: cfe/trunk/test/CodeGenObjC/bitfield-ivar-metadata.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/bitfield-ivar-metadata.m?rev=66345&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/bitfield-ivar-metadata.m (added)
+++ cfe/trunk/test/CodeGenObjC/bitfield-ivar-metadata.m Sat Mar 7 13:43:20 2009
@@ -0,0 +1,15 @@
+// RUN: clang -fnext-runtime -emit-llvm -o %t %s
+
+ at interface INTF
+{
+ unsigned ivar1;
+ unsigned ivar2;
+ unsigned char BDIVAR3:1;
+ unsigned char BDIVAR4:1;
+}
+ at end
+
+ at implementation INTF
+ at end
+
+
More information about the cfe-commits
mailing list