aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprConstant.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/CodeGen/CGExprConstant.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/CodeGen/CGExprConstant.cpp')
-rw-r--r--lib/CodeGen/CGExprConstant.cpp45
1 files changed, 21 insertions, 24 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index b05048c946..e523ab3acf 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -241,32 +241,29 @@ public:
RecordDecl *RD = ILE->getType()->getAsRecordType()->getDecl();
const llvm::Type *Ty = ConvertType(ILE->getType());
- // Find the field decl we're initializing, if any
- // FIXME: C99 designated initializers won't always initialize the
- // first field
- int FieldNo = 0; // Field no in RecordDecl
- FieldDecl* curField = 0;
- bool sawAnyFields = false;
- for (RecordDecl::field_iterator Field = RD->field_begin(),
- FieldEnd = RD->field_end();
- Field != FieldEnd; ++Field) {
- curField = *Field;
- FieldNo++;
-
- if (curField->isUnnamedBitfield())
- continue;
-
- // If we have an initializer, find the field whose type is the
- // same as that initializer. This
- sawAnyFields = true;
- if (ILE->getNumInits() > 0 &&
- CGM.getContext().getCanonicalType(curField->getType()) ==
- CGM.getContext().getCanonicalType(ILE->getInit(0)->getType()))
- break;
- }
+ // If this is an empty initializer list, we value-initialize the
+ // union.
+ if (ILE->getNumInits() == 0)
+ return llvm::Constant::getNullValue(Ty);
- if (!curField || !curField->getIdentifier() || ILE->getNumInits() == 0)
+ FieldDecl* curField = ILE->getInitializedFieldInUnion();
+ if (!curField) {
+#ifndef NDEBUG
+#endif
+ }
+
+ if (!curField) {
+ // There's no field to initialize, so value-initialize the union.
+#ifndef NDEBUG
+ // Make sure that it's really an empty and not a failure of
+ // semantic analysis.
+ for (RecordDecl::field_iterator Field = RD->field_begin(),
+ FieldEnd = RD->field_end();
+ Field != FieldEnd; ++Field)
+ assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+#endif
return llvm::Constant::getNullValue(Ty);
+ }
if (curField->isBitField()) {
// Create a dummy struct for bit-field insertion