]> granicus.if.org Git - clang/commitdiff
Fix brace init of unions with unnamed struct members
authorReid Kleckner <reid@kleckner.net>
Wed, 12 Nov 2014 21:30:23 +0000 (21:30 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 12 Nov 2014 21:30:23 +0000 (21:30 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221818 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/CodeGenCXX/cxx1y-initializer-aggregate.cpp

index d1e51de621051171f83a12ce344b22b9f2a0a940..39d6a575aa2cb04e4ca441d24b368074263f94d9 100644 (file)
@@ -1555,10 +1555,11 @@ void InitListChecker::CheckStructUnionTypes(const InitializedEntity &Entity,
       }
     }
 
-    // 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),
index 8bdf8633d61e2b7c614baf41205b372e9f846ea0..098a4b945e04a97384a56cef3f0ac6bf236d240d 100644 (file)
@@ -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)