From 3e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 21 Apr 2011 20:03:38 +0000 Subject: [PATCH] Use the ArrayFiller to fill out "holes" in the array initializer due to designated initializers, avoiding to create separate Exprs for each one. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129933 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Expr.h | 4 +--- lib/AST/Expr.cpp | 9 +++++++++ lib/Sema/SemaInit.cpp | 7 ++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 7420408226..d8d006440c 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -3246,9 +3246,7 @@ public: Expr *getArrayFiller() { return ArrayFillerOrUnionFieldInit.dyn_cast(); } - void setArrayFiller(Expr *filler) { - ArrayFillerOrUnionFieldInit = filler; - } + void setArrayFiller(Expr *filler); /// \brief If this initializes a union, specifies which field in the /// union to initialize. diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 9b978e8439..dd1a317f4a 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1289,6 +1289,15 @@ Expr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { return Result; } +void InitListExpr::setArrayFiller(Expr *filler) { + ArrayFillerOrUnionFieldInit = filler; + // Fill out any "holes" in the array due to designated initializers. + Expr **inits = getInits(); + for (unsigned i = 0, e = getNumInits(); i != e; ++i) + if (inits[i] == 0) + inits[i] = filler; +} + SourceRange InitListExpr::getSourceRange() const { if (SyntacticForm) return SyntacticForm->getSourceRange(); diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 307db14b58..2acb482c41 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -404,7 +404,12 @@ InitListChecker::FillInValueInitializations(const InitializedEntity &Entity, if (hadError) { // Do nothing } else if (Init < NumInits) { - ILE->setInit(Init, ElementInit.takeAs()); + // For arrays, just set the expression used for value-initialization + // of the "holes" in the array. + if (ElementEntity.getKind() == InitializedEntity::EK_ArrayElement) + ILE->setArrayFiller(ElementInit.takeAs()); + else + ILE->setInit(Init, ElementInit.takeAs()); } else { // For arrays, just set the expression used for value-initialization // of the rest of elements and exit. -- 2.50.1