From 4c67834407ca6ab344dcf44fc599ad4938cfa96d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 28 Jan 2009 21:54:33 +0000 Subject: Code generation support for C99 designated initializers. The approach I've taken in this patch is relatively straightforward, although the code itself is non-trivial. Essentially, as we process an initializer list we build up a fully-explicit representation of the initializer list, where each of the subobject initializations occurs in order. Designators serve to "fill in" subobject initializations in a non-linear way. The fully-explicit representation makes initializer lists (both with and without designators) easy to grok for codegen and later semantic analyses. We keep the syntactic form of the initializer list linked into the AST for those clients interested in exactly what the user wrote. Known limitations: - Designating a member of a union that isn't the first member may result in bogus initialization (we warn about this) - GNU array-range designators are not supported (we warn about this) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63242 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprAgg.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'lib/CodeGen/CGExprAgg.cpp') diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 9181bf6654..2534a14cb6 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -71,7 +71,7 @@ public: void VisitArraySubscriptExpr(ArraySubscriptExpr *E) { EmitAggLoadOfLValue(E); } - + // Operators. // case Expr::UnaryOperatorClass: // case Expr::CastExprClass: @@ -303,11 +303,6 @@ void AggExprEmitter::VisitVAArgExpr(VAArgExpr *VE) { } void AggExprEmitter::EmitNonConstInit(InitListExpr *E) { - if (E->hadDesignators()) { - CGF.ErrorUnsupported(E, "initializer list with designators"); - return; - } - const llvm::PointerType *APType = cast(DestPtr->getType()); const llvm::Type *DestType = APType->getElementType(); @@ -346,6 +341,8 @@ void AggExprEmitter::EmitInitializationToLValue(Expr* E, LValue LV) { // FIXME: Are initializers affected by volatile? if (E->getType()->isComplexType()) { CGF.EmitComplexExprIntoAddr(E, LV.getAddress(), false); + } else if (isa(E)) { + EmitNullInitializationToLValue(LV, E->getType()); } else if (CGF.hasAggregateLLVMType(E->getType())) { CGF.EmitAnyExpr(E, LV.getAddress(), false); } else { @@ -380,11 +377,6 @@ void AggExprEmitter::EmitNullInitializationToLValue(LValue LV, QualType T) { } void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { - if (E->hadDesignators()) { - CGF.ErrorUnsupported(E, "initializer list with designators"); - return; - } - #if 0 // FIXME: Disabled while we figure out what to do about // test/CodeGen/bitfield.c @@ -426,7 +418,7 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { uint64_t NumArrayElements = AType->getNumElements(); QualType ElementType = CGF.getContext().getCanonicalType(E->getType()); - ElementType =CGF.getContext().getAsArrayType(ElementType)->getElementType(); + ElementType = CGF.getContext().getAsArrayType(ElementType)->getElementType(); unsigned CVRqualifier = ElementType.getCVRQualifiers(); @@ -479,7 +471,7 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { } // Unions only initialize one field. - // (things can get weird with designators, but they aren't + // (FIXME: things can get weird with designators, but they aren't // supported yet.) if (isUnion) break; -- cgit v1.2.3