From: David Majnemer Date: Sat, 23 Aug 2014 01:48:50 +0000 (+0000) Subject: CodeGen: Skip unnamed bitfields when handling designated initializers X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3209c1580ae58e6182e0c0a2043d0554c83bd32;p=clang CodeGen: Skip unnamed bitfields when handling designated initializers We would accidently initialize unnamed bitfields instead of the following field. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216313 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 79fe8db237..326bfc9087 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -1932,7 +1932,15 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity, } } - unsigned FieldIndex = KnownField->getFieldIndex(); + unsigned FieldIndex = 0; + for (auto *FI : RT->getDecl()->fields()) { + if (FI->isUnnamedBitfield()) + continue; + if (KnownField == FI) + break; + ++FieldIndex; + } + RecordDecl::field_iterator Field = RecordDecl::field_iterator(DeclContext::decl_iterator(KnownField)); diff --git a/test/CodeGen/designated-initializers.c b/test/CodeGen/designated-initializers.c index b11c67a454..74532c8fa5 100644 --- a/test/CodeGen/designated-initializers.c +++ b/test/CodeGen/designated-initializers.c @@ -139,6 +139,9 @@ union_16644_t union_16644_instance_4[2] = [1].b[1] = 4 }; +// CHECK: @lab = global { [4 x i8], i32 } { [4 x i8] undef, i32 123 } +struct leading_anon_bitfield { int : 32; int n; } lab = { .n = 123 }; + void test1(int argc, char **argv) { // CHECK: internal global %struct.foo { i8* null, i32 1024 }