diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-04-21 20:03:38 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-04-21 20:03:38 +0000 |
commit | 3e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2 (patch) | |
tree | c08f5ea90e624a522d83e1d952c00f9af0f01993 | |
parent | 6f141659cab11109d9931d92d0988f8850778de3 (diff) |
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
-rw-r--r-- | include/clang/AST/Expr.h | 4 | ||||
-rw-r--r-- | lib/AST/Expr.cpp | 9 | ||||
-rw-r--r-- | 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<Expr *>(); } - 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<Expr>()); + // 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<Expr>()); + else + ILE->setInit(Init, ElementInit.takeAs<Expr>()); } else { // For arrays, just set the expression used for value-initialization // of the rest of elements and exit. |