[cfe-commits] r62429 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/unname-bf-metadata.m
Fariborz Jahanian
fjahanian at apple.com
Sat Jan 17 11:36:33 PST 2009
Author: fjahanian
Date: Sat Jan 17 13:36:33 2009
New Revision: 62429
URL: http://llvm.org/viewvc/llvm-project?rev=62429&view=rev
Log:
Patch to re-implement ivar-list meta-data generation to fix
cases of unnamed ivar bitfields.
Added:
cfe/trunk/test/CodeGenObjC/unname-bf-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=62429&r1=62428&r2=62429&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sat Jan 17 13:36:33 2009
@@ -1295,6 +1295,21 @@
return GV;
}
+/// countInheritedIvars - count number of ivars in class and its super class(s)
+///
+static int countInheritedIvars(const ObjCInterfaceDecl *OI) {
+ int count = 0;
+ if (!OI)
+ return 0;
+ const ObjCInterfaceDecl *SuperClass = OI->getSuperClass();
+ if (SuperClass)
+ count += countInheritedIvars(SuperClass);
+ for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
+ E = OI->ivar_end(); I != E; ++I)
+ ++count;
+ return count;
+}
+
/*
struct objc_ivar {
char *ivar_name;
@@ -1322,18 +1337,23 @@
const llvm::StructLayout *Layout =
CGM.getTargetData().getStructLayout(cast<llvm::StructType>(InterfaceTy));
- for (ObjCInterfaceDecl::ivar_iterator
- i = ID->getClassInterface()->ivar_begin(),
- e = ID->getClassInterface()->ivar_end(); i != e; ++i) {
- const ObjCIvarDecl *V = *i;
- ObjCInterfaceDecl *OID =
- const_cast<ObjCInterfaceDecl *>(ID->getClassInterface());
- FieldDecl *Field = OID->lookupFieldDeclForIvar(CGM.getContext(), V);
- unsigned Offset =
- Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
+ ObjCInterfaceDecl *OID =
+ const_cast<ObjCInterfaceDecl *>(ID->getClassInterface());
+ int countSuperClassIvars = countInheritedIvars(OID->getSuperClass());
+ const RecordDecl *RD = CGM.getContext().addRecordToClass(OID);
+ RecordDecl::field_iterator ifield = RD->field_begin();
+ while (countSuperClassIvars-- > 0)
+ ++ifield;
+ for (RecordDecl::field_iterator e = RD->field_end(); ifield != e; ++ifield) {
+ FieldDecl *Field = *ifield;
+ unsigned Offset = Layout->getElementOffset(CGM.getTypes().
+ getLLVMFieldNo(Field));
+ if (Field->getIdentifier())
+ Ivar[0] = GetMethodVarName(Field->getIdentifier());
+ else
+ Ivar[0] = llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy);
std::string TypeStr;
- Ivar[0] = GetMethodVarName(V->getIdentifier());
- CGM.getContext().getObjCEncodingForType(V->getType(), TypeStr, Field);
+ CGM.getContext().getObjCEncodingForType(Field->getType(), TypeStr, Field);
Ivar[1] = GetMethodVarType(TypeStr);
Ivar[2] = llvm::ConstantInt::get(ObjCTypes.IntTy, Offset);
Ivars.push_back(llvm::ConstantStruct::get(ObjCTypes.IvarTy, Ivar));
Added: cfe/trunk/test/CodeGenObjC/unname-bf-metadata.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/unname-bf-metadata.m?rev=62429&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/unname-bf-metadata.m (added)
+++ cfe/trunk/test/CodeGenObjC/unname-bf-metadata.m Sat Jan 17 13:36:33 2009
@@ -0,0 +1,14 @@
+// RUN: clang -fnext-runtime -emit-llvm -o %t %s
+// Test that meta-data for ivar lists with unnamed bitfield are generated.
+//
+ at interface Foo {
+ at private
+ int first;
+ int :1;
+ int third :1;
+ int :1;
+ int fifth :1;
+}
+ at end
+ at implementation Foo
+ at end
More information about the cfe-commits
mailing list