Clean up designated initialization of unions, so that CodeGen doesn't
have to try to guess which member is being initialized.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63315 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 5dc5775..527f965 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -573,6 +573,11 @@
                                      StructuredList, StructuredIndex))
         hadError = true;
 
+      // Abort early for unions: the designator handled the
+      // initialization of the appropriate field.
+      if (DeclType->isUnionType())
+        break;
+
       continue;
     }
 
@@ -585,7 +590,7 @@
     if (Field->getType()->isIncompleteArrayType())
       break;
 
-    if (!Field->getIdentifier() && Field->isBitField()) {
+    if (Field->isUnnamedBitfield()) {
       // Don't initialize unnamed bitfields, e.g. "int : 20;"
       ++Field;
       continue;
@@ -593,8 +598,12 @@
 
     CheckSubElementType(IList, Field->getType(), Index,
                         StructuredList, StructuredIndex);
-    if (DeclType->isUnionType())
+
+    if (DeclType->isUnionType()) {
+      // Initialize the first field within the union.
+      StructuredList->setInitializedFieldInUnion(*Field);
       break;
+    }
 
     ++Field;
   }
@@ -753,8 +762,10 @@
 
     // All of the fields of a union are located at the same place in
     // the initializer list.
-    if (RT->getDecl()->isUnion())
+    if (RT->getDecl()->isUnion()) {
       FieldIndex = 0;
+      StructuredList->setInitializedFieldInUnion(*Field);
+    }
 
     // Update the designator with the field declaration.
     D->setField(*Field);