From 3b4d490b09347e0b68ec0511ddfae79dfaba77a6 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 28 Apr 2011 18:53:58 +0000 Subject: 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130421 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprAgg.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/CGExprAgg.cpp') diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 53bc58b69c..457e44d086 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/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()) { + const CXXRecordDecl *RD = cast(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"); -- cgit v1.2.3