From: Chris Lattner Date: Sun, 26 Oct 2008 23:53:12 +0000 (+0000) Subject: make codegen reject initializes with designators, like this: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be20bb558cae5352898e6a913e29d24d20134841;p=clang make codegen reject initializes with designators, like this: t.c:1:13: error: cannot codegen this designators yet int a[10] = {2, 4, [8]=9, 10}; ^~~~~~~~~~~~~~~~~ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58220 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Parse/Designator.h b/include/clang/Parse/Designator.h index 6a5cff63e9..52476383ae 100644 --- a/include/clang/Parse/Designator.h +++ b/include/clang/Parse/Designator.h @@ -198,7 +198,7 @@ public: } bool hasAnyDesignators() const { - return Designations.empty(); + return !Designations.empty(); } Designation &CreateDesignation(unsigned Idx) { diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 9041c17671..e81a64ffa5 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -263,7 +263,11 @@ 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(); @@ -334,6 +338,11 @@ void AggExprEmitter::EmitNullInitializationToLValue(LValue LV, QualType T) { } void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { + if (E->hadDesignators()) { + CGF.ErrorUnsupported(E, "initializer list with designators"); + return; + } + // FIXME: For constant expressions, call into const expr emitter so // that we can emit a memcpy instead of storing the individual // members. This is purely for perf; both codepaths lead to diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 5fc513d125..89b34e611b 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -315,6 +315,12 @@ public: const llvm::Type* RetTy = CGM.getTypes().ConvertType(ILE->getType()); return llvm::Constant::getNullValue(RetTy); } + + // FIXME: We don't codegen or sema designators yet. + if (ILE->hadDesignators()) { + CGM.ErrorUnsupported(ILE, "initializer list with designators"); + return llvm::UndefValue::get(ConvertType(ILE->getType())); + } if (ILE->getType()->isArrayType()) return EmitArrayInitialization(ILE); diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 9af269eaf3..2e2eea3e31 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -154,7 +154,9 @@ public: Value *VisitShuffleVectorExpr(ShuffleVectorExpr *E); Value *VisitMemberExpr(Expr *E) { return EmitLoadOfLValue(E); } Value *VisitExtVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); } - Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { return EmitLoadOfLValue(E); } + Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { + return EmitLoadOfLValue(E); + } Value *VisitStringLiteral(Expr *E) { return EmitLValue(E).getAddress(); } Value *VisitPredefinedExpr(Expr *E) { return EmitLValue(E).getAddress(); } @@ -168,6 +170,11 @@ public: if (!VType) return Visit(E->getInit(0)); + if (E->hadDesignators()) { + CGF.ErrorUnsupported(E, "initializer list with designators"); + return llvm::UndefValue::get(CGF.ConvertType(E->getType())); + } + unsigned NumVectorElements = VType->getNumElements(); const llvm::Type *ElementType = VType->getElementType();