diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-01-28 23:36:17 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-01-28 23:36:17 +0000 |
commit | 34e7946831a63f96d3ba3478c74ca8e25ee52d7e (patch) | |
tree | abb077e17e60200375521dcaa14875641f5ad747 /lib/CodeGen/CGExprAgg.cpp | |
parent | 939abced90071beb750041ee9c2cf57f827e024a (diff) |
Improvements to code-generation and semantic analysis of designated
initializers.
- We now initialize unions properly when a member other than the
first is named by a designated initializer.
- We now provide proper semantic analysis and code generation for
GNU array-range designators *except* that side effects will occur
more than once. We warn about this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63253 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprAgg.cpp')
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 2534a14cb6..075a12c57e 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -454,10 +454,17 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { if (Field->getType()->isIncompleteArrayType()) break; - if (Field->getIdentifier() == 0) { - // Initializers can't initialize unnamed fields, e.g. "int : 20;" + if (Field->isUnnamedBitfield()) continue; - } + + // When we're coping with C99 designated initializers into a + // union, find the field that has the same type as the expression + // we're initializing the union with. + if (isUnion && CurInitVal < NumInitElements && + (CGF.getContext().getCanonicalType(Field->getType()) != + CGF.getContext().getCanonicalType(E->getInit(CurInitVal)->getType()))) + continue; + // FIXME: volatility LValue FieldLoc = CGF.EmitLValueForField(DestPtr, *Field, isUnion,0); if (CurInitVal < NumInitElements) { @@ -471,8 +478,6 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { } // Unions only initialize one field. - // (FIXME: things can get weird with designators, but they aren't - // supported yet.) if (isUnion) break; } |