[cfe-commits] r162643 - in /cfe/trunk: lib/CodeGen/CGExprCXX.cpp test/CodeGenCXX/new.cpp

Eli Friedman eli.friedman at gmail.com
Sat Aug 25 00:11:29 PDT 2012


Author: efriedma
Date: Sat Aug 25 02:11:29 2012
New Revision: 162643

URL: http://llvm.org/viewvc/llvm-project?rev=162643&view=rev
Log:
Fix a CodeGen bug where we would skip zero-initialization for
array new with a non-trivial constructor. Pointed out in PR13380.


Modified:
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/new.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=162643&r1=162642&r2=162643&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Sat Aug 25 02:11:29 2012
@@ -956,7 +956,6 @@
   if (E->isArray()) {
     if (const CXXConstructExpr *CCE = dyn_cast_or_null<CXXConstructExpr>(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 @@
           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<ImplicitValueInitExpr>(Init) &&
                CGF.CGM.getTypes().isZeroInitializable(ElementType)) {

Modified: cfe/trunk/test/CodeGenCXX/new.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new.cpp?rev=162643&r1=162642&r2=162643&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/new.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/new.cpp Sat Aug 25 02:11:29 2012
@@ -250,3 +250,13 @@
   // 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](); }
+}





More information about the cfe-commits mailing list