From: Daniel Dunbar Date: Mon, 20 Apr 2009 05:53:40 +0000 (+0000) Subject: Don't emit ivar offsets for unnamed bit fields. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3eec8aac935eda70975d7d88f1f4a09be90f33c9;p=clang Don't emit ivar offsets for unnamed bit fields. Also, added assertion that the field matches what would be looked up. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69572 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index e92796b5ba..665e927142 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -4600,13 +4600,16 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList( unsigned iv = 0; for (RecordDecl::field_iterator e = RD->field_end(CGM.getContext()); i != e; ++i) { + ObjCIvarDecl *IVD = OIvars[iv++]; + // Don't emit entries for unnamed bit fields. + if (!IVD->getDeclName()) + continue; + FieldDecl *Field = *i; - Ivar[0] = EmitIvarOffsetVar(ID->getClassInterface(), OIvars[iv++], + assert(Field == OID->lookupFieldDeclForIvar(CGM.getContext(), IVD)); + Ivar[0] = EmitIvarOffsetVar(ID->getClassInterface(), IVD, GetIvarBaseOffset(Layout, Field)); - if (Field->getIdentifier()) - Ivar[1] = GetMethodVarName(Field->getIdentifier()); - else - Ivar[1] = llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy); + Ivar[1] = GetMethodVarName(Field->getIdentifier()); Ivar[2] = GetMethodVarType(Field); const llvm::Type *FieldTy = CGM.getTypes().ConvertTypeForMem(Field->getType()); diff --git a/test/CodeGenObjC/bitfield-ivar-offsets.m b/test/CodeGenObjC/bitfield-ivar-offsets.m index 0078a8c76a..23a09a3a15 100644 --- a/test/CodeGenObjC/bitfield-ivar-offsets.m +++ b/test/CodeGenObjC/bitfield-ivar-offsets.m @@ -1,3 +1,4 @@ +// RUNX: llvm-gcc -m64 -emit-llvm -S -o %t %s && // RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s && // RUN: grep -F '@"OBJC_IVAR_$_I0._b0" = global i64 0, section "__DATA, __objc_const", align 8' %t && // RUN: grep -F '@"OBJC_IVAR_$_I0._b1" = global i64 0, section "__DATA, __objc_const", align 8' %t && @@ -6,6 +7,7 @@ // RUN: grep -F '@"OBJC_IVAR_$_I0._b3" = global i64 4, section "__DATA, __objc_const", align 8' %t && // RUN: grep -F '@"OBJC_IVAR_$_I0._y" = global i64 6, section "__DATA, __objc_const", align 8' %t && // RUN: grep -F '@"OBJC_IVAR_$_I0._b4" = global i64 7, section "__DATA, __objc_const", align 8' %t && +// RUN: grep -F '@"OBJC_IVAR_$_I0." = global' %t | count 0 && // RUN: true @interface I0 { @@ -16,6 +18,7 @@ unsigned _b3:9; char _y; char _b4:3; + char : 0; } @end