diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-06-13 23:04:49 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-06-13 23:04:49 +0000 |
| commit | 461cfc5c98be23dbefdbf953b8a635b74ee546c0 (patch) | |
| tree | 71eb8d9d169a719ece5f2b63dabd8ffa72a1974c /lib/CodeGen/CGExprAgg.cpp | |
| parent | 748531c892f76b83f8140e38e6b6ad0df622eedb (diff) | |
| download | clang-461cfc5c98be23dbefdbf953b8a635b74ee546c0.tar.gz clang-461cfc5c98be23dbefdbf953b8a635b74ee546c0.tar.bz2 clang-461cfc5c98be23dbefdbf953b8a635b74ee546c0.tar.xz | |
A non-trivial array-fill expression isn't necessarily a CXXConstructExpr. It
could be an InitListExpr that runs constructors in C++11 onwards. Fixes a
recent regression (introduced in r210091).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210954 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprAgg.cpp')
| -rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 4cb81b54cd..b1406cdd7c 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -370,6 +370,29 @@ AggExprEmitter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) { } } +/// \brief Determine if E is a trivial array filler, that is, one that is +/// equivalent to zero-initialization. +static bool isTrivialFiller(Expr *E) { + if (!E) + return true; + + if (isa<ImplicitValueInitExpr>(E)) + return true; + + if (auto *ILE = dyn_cast<InitListExpr>(E)) { + if (ILE->getNumInits()) + return false; + return isTrivialFiller(ILE->getArrayFiller()); + } + + if (auto *Cons = dyn_cast_or_null<CXXConstructExpr>(E)) + return Cons->getConstructor()->isDefaultConstructor() && + Cons->getConstructor()->isTrivial(); + + // FIXME: Are there other cases where we can avoid emitting an initializer? + return false; +} + /// \brief Emit initialization of an array from an initializer list. void AggExprEmitter::EmitArrayInit(llvm::Value *DestPtr, llvm::ArrayType *AType, QualType elementType, InitListExpr *E) { @@ -435,13 +458,8 @@ void AggExprEmitter::EmitArrayInit(llvm::Value *DestPtr, llvm::ArrayType *AType, } // Check whether there's a non-trivial array-fill expression. - // Note that this will be a CXXConstructExpr even if the element - // type is an array (or array of array, etc.) of class type. Expr *filler = E->getArrayFiller(); - bool hasTrivialFiller = true; - if (CXXConstructExpr *cons = dyn_cast_or_null<CXXConstructExpr>(filler)) - hasTrivialFiller = cons->getConstructor()->isDefaultConstructor() && - cons->getConstructor()->isTrivial(); + bool hasTrivialFiller = isTrivialFiller(filler); // Any remaining elements need to be zero-initialized, possibly // using the filler expression. We can skip this if the we're |
