r216313 - CodeGen: Skip unnamed bitfields when handling designated initializers
David Majnemer
david.majnemer at gmail.com
Fri Aug 22 18:48:50 PDT 2014
Author: majnemer
Date: Fri Aug 22 20:48:50 2014
New Revision: 216313
URL: http://llvm.org/viewvc/llvm-project?rev=216313&view=rev
Log:
CodeGen: Skip unnamed bitfields when handling designated initializers
We would accidently initialize unnamed bitfields instead of the
following field.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/CodeGen/designated-initializers.c
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=216313&r1=216312&r2=216313&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug 22 20:48:50 2014
@@ -1932,7 +1932,15 @@ InitListChecker::CheckDesignatedInitiali
}
}
- 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));
Modified: cfe/trunk/test/CodeGen/designated-initializers.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/designated-initializers.c?rev=216313&r1=216312&r2=216313&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/designated-initializers.c (original)
+++ cfe/trunk/test/CodeGen/designated-initializers.c Fri Aug 22 20:48:50 2014
@@ -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 }
More information about the cfe-commits
mailing list