From b41ba1aa47a66979df578074de3c218d820c152d Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Sat, 25 Aug 2012 07:11:29 +0000 Subject: [PATCH] Fix a CodeGen bug where we would skip zero-initialization for array new with a non-trivial constructor. Pointed out in PR13380. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162643 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprCXX.cpp | 5 +---- test/CodeGenCXX/new.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index 0faf98032c..17e2bc1874 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -956,7 +956,6 @@ static void EmitNewInitializer(CodeGenFunction &CGF, const CXXNewExpr *E, if (E->isArray()) { if (const CXXConstructExpr *CCE = dyn_cast_or_null(Init)){ CXXConstructorDecl *Ctor = CCE->getConstructor(); - bool RequiresZeroInitialization = false; if (Ctor->isTrivial()) { // If new expression did not specify value-initialization, then there // is no initialization. @@ -969,13 +968,11 @@ static void EmitNewInitializer(CodeGenFunction &CGF, const CXXNewExpr *E, EmitZeroMemSet(CGF, ElementType, NewPtr, AllocSizeWithoutCookie); return; } - - RequiresZeroInitialization = true; } CGF.EmitCXXAggrConstructorCall(Ctor, NumElements, NewPtr, CCE->arg_begin(), CCE->arg_end(), - RequiresZeroInitialization); + CCE->requiresZeroInitialization()); return; } else if (Init && isa(Init) && CGF.CGM.getTypes().isZeroInitializable(ElementType)) { diff --git a/test/CodeGenCXX/new.cpp b/test/CodeGenCXX/new.cpp index 8d9f641ba1..e0523909a3 100644 --- a/test/CodeGenCXX/new.cpp +++ b/test/CodeGenCXX/new.cpp @@ -250,3 +250,13 @@ namespace PR11757 { // CHECK-NEXT: call void @_ZN7PR117571XC1Ev({{.*}}* [[CASTED]]) // CHECK-NEXT: ret {{.*}} [[CASTED]] } + +namespace PR13380 { + struct A { A() {} }; + struct B : public A { int x; }; + // CHECK: define i8* @_ZN7PR133801fEv + // CHECK: call noalias i8* @_Znam( + // CHECK: call void @llvm.memset.p0i8 + // CHECK-NEXT: call void @_ZN7PR133801BC1Ev + void* f() { return new B[2](); } +} -- 2.40.0