summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExprAgg.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-28 18:53:58 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-28 18:53:58 +0000
commite07425a5e782f362b7d084be34849aa45611d880 (patch)
tree0c920966dae4aee218d3e3678f1553923f97c68c /clang/lib/CodeGen/CGExprAgg.cpp
parentfddbcfbec48f3e077baf5b925729001c4c222c4a (diff)
downloadbcm5719-llvm-e07425a5e782f362b7d084be34849aa45611d880.tar.gz
bcm5719-llvm-e07425a5e782f362b7d084be34849aa45611d880.zip
When value-initializing the elements of an array not not included in the initializer make sure
that a non-trivial C++ constructor gets called. Fixes rdar://9347552 & http://llvm.org/PR9801 llvm-svn: 130421
Diffstat (limited to 'clang/lib/CodeGen/CGExprAgg.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprAgg.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 53bc58b69c8..457e44d086d 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -622,6 +622,13 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
QualType ElementType = CGF.getContext().getCanonicalType(E->getType());
ElementType = CGF.getContext().getAsArrayType(ElementType)->getElementType();
+ bool hasNonTrivialCXXConstructor = false;
+ if (CGF.getContext().getLangOptions().CPlusPlus)
+ if (const RecordType *RT = ElementType->getAs<RecordType>()) {
+ const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
+ hasNonTrivialCXXConstructor = !RD->hasTrivialConstructor();
+ }
+
// FIXME: were we intentionally ignoring address spaces and GC attributes?
for (uint64_t i = 0; i != NumArrayElements; ++i) {
@@ -629,7 +636,8 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
// then we're done.
if (i == NumInitElements &&
Dest.isZeroed() &&
- CGF.getTypes().isZeroInitializable(ElementType))
+ CGF.getTypes().isZeroInitializable(ElementType) &&
+ !hasNonTrivialCXXConstructor)
break;
llvm::Value *NextVal = Builder.CreateStructGEP(DestPtr, i, ".array");
OpenPOWER on IntegriCloud