[cfe-commits] r130421 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp test/CodeGenCXX/value-init.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Apr 28 11:53:58 PDT 2011
Author: akirtzidis
Date: Thu Apr 28 13:53:58 2011
New Revision: 130421
URL: http://llvm.org/viewvc/llvm-project?rev=130421&view=rev
Log:
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
Modified:
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/test/CodeGenCXX/value-init.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=130421&r1=130420&r2=130421&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Apr 28 13:53:58 2011
@@ -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");
Modified: cfe/trunk/test/CodeGenCXX/value-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/value-init.cpp?rev=130421&r1=130420&r2=130421&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/value-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/value-init.cpp Thu Apr 28 13:53:58 2011
@@ -83,6 +83,47 @@
}
}
+namespace PR9801 {
+
+struct Test {
+ Test() : i(10) {}
+ Test(int i) : i(i) {}
+ int i;
+private:
+ int j;
+};
+
+struct Test2 {
+ Test t;
+};
+
+struct Test3 : public Test { };
+
+// CHECK: define void @_ZN6PR98011fEv
+void f() {
+ // CHECK: call void @_ZN6PR98014TestC1Ei
+ // CHECK: call void @_ZN6PR98014TestC1Ev
+ // CHECK: call void @_ZN6PR98014TestC1Ev
+ Test partial[3] = { 1 };
+
+ // CHECK: call void @_ZN6PR98014TestC1Ev
+ // CHECK: call void @_ZN6PR98014TestC1Ev
+ // CHECK: call void @_ZN6PR98014TestC1Ev
+ Test empty[3] = {};
+
+ // CHECK: call void @_ZN6PR98015Test2C1Ev
+ // CHECK: call void @_ZN6PR98015Test2C1Ev
+ // CHECK: call void @_ZN6PR98015Test2C1Ev
+ Test2 empty2[3] = {};
+
+ // CHECK: call void @_ZN6PR98015Test3C1Ev
+ // CHECK: call void @_ZN6PR98015Test3C1Ev
+ // CHECK: call void @_ZN6PR98015Test3C1Ev
+ Test3 empty3[3] = {};
+}
+
+}
+
namespace zeroinit {
struct S { int i; };
More information about the cfe-commits
mailing list