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
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 53bc58b..457e44d 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -622,6 +622,13 @@
     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 @@
       // 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");