Author: rnk
Date: Wed Nov 12 15:30:23 2014
New Revision: 221818
URL: http://llvm.org/viewvc/llvm-project?rev=221818&view=rev
Log:
Fix brace init of unions with unnamed struct members
The check for unnamed members was intended to skip unnamed bitfields,
but it ended up skipping unnamed structs. This lead to an assertion in
IRGen.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=221818&r1=221817&r2=221818&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Nov 12 15:30:23 2014
@@ -1555,10 +1555,11 @@ void InitListChecker::CheckStructUnionTy
}
}
- // Value-initialize the first named member of the union.
+ // Value-initialize the first member of the union that isn't an unnamed
+ // bitfield.
for (RecordDecl::field_iterator FieldEnd = RD->field_end();
Field != FieldEnd; ++Field) {
- if (Field->getDeclName()) {
+ if (!Field->isUnnamedBitfield()) {
if (VerifyOnly)
CheckEmptyInitializable(
InitializedEntity::InitializeMember(*Field, &Entity),
Modified: cfe/trunk/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp?rev=221818&r1=221817&r2=221818&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp Wed Nov 12
15:30:23 2014
@@ -36,6 +36,17 @@ B y {};
B z { 1 };
// CHECK: @z = global {{.*}} { i32 1 }
+// Brace initialization should initialize the first field even though it is
+// unnamed.
+union C {
+ struct {
+ int C::*memptr;
+ };
+};
+
+C n{};
+// CHECK: @n = global %union.C { %struct.anon { i64 -1 } }, align 8
+
// Initialization of 'a':
// CHECK: store i32 0, i32* getelementptr inbounds ({{.*}} @a, i32 0, i32 0)
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits