aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaInit.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-29 16:53:55 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-29 16:53:55 +0000
commit0bb76897bedb8b747efc6523efb432fc24966118 (patch)
treef6113fbcc4b4a8e7c5749e565e20487704d2d5a6 /lib/Sema/SemaInit.cpp
parent5d2ff63254bf1c3d3ca6844c96f3bfd88561cc7c (diff)
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
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r--lib/Sema/SemaInit.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 5dc57751ff..527f965dc3 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -573,6 +573,11 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,
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 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,
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 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,
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 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList,
// 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);