diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2014-08-23 01:48:50 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2014-08-23 01:48:50 +0000 |
| commit | 58e4ea904bf625ea621ccebd513f58496886f918 (patch) | |
| tree | fa7b410f5f9389dc4cbf7c6352102c46dc78d3e5 | |
| parent | 88ebade8d9f8c9b3f818ee43acd8960ec6475952 (diff) | |
| download | bcm5719-llvm-58e4ea904bf625ea621ccebd513f58496886f918.tar.gz bcm5719-llvm-58e4ea904bf625ea621ccebd513f58496886f918.zip | |
CodeGen: Skip unnamed bitfields when handling designated initializers
We would accidently initialize unnamed bitfields instead of the
following field.
llvm-svn: 216313
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 10 | ||||
| -rw-r--r-- | clang/test/CodeGen/designated-initializers.c | 3 |
2 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 79fe8db2379..326bfc90875 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/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/clang/test/CodeGen/designated-initializers.c b/clang/test/CodeGen/designated-initializers.c index b11c67a4542..74532c8fa5b 100644 --- a/clang/test/CodeGen/designated-initializers.c +++ b/clang/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 } |

