[cfe-commits] r150738 - in /cfe/trunk: lib/CodeGen/CGExprCXX.cpp test/CodeGenCXX/debug-info-limit.cpp test/CodeGenCXX/exceptions.cpp test/CodeGenCXX/new.cpp test/CodeGenObjCXX/copy.mm
Eli Friedman
eli.friedman at gmail.com
Thu Feb 16 14:45:48 PST 2012
Author: efriedma
Date: Thu Feb 16 16:45:48 2012
New Revision: 150738
URL: http://llvm.org/viewvc/llvm-project?rev=150738&view=rev
Log:
Elide copy construction in new expressions. PR11757.
Modified:
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/test/CodeGenCXX/debug-info-limit.cpp
cfe/trunk/test/CodeGenCXX/exceptions.cpp
cfe/trunk/test/CodeGenCXX/new.cpp
cfe/trunk/test/CodeGenObjCXX/copy.mm
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=150738&r1=150737&r2=150738&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Thu Feb 16 16:45:48 2012
@@ -890,20 +890,6 @@
return;
}
- if (const CXXConstructExpr *CCE = dyn_cast_or_null<CXXConstructExpr>(Init)) {
- CXXConstructorDecl *Ctor = CCE->getConstructor();
- // Per C++ [expr.new]p15, if we have an initializer, then we're performing
- // direct initialization. C++ [dcl.init]p5 requires that we
- // zero-initialize storage if there are no user-declared constructors.
- if (!Ctor->getParent()->hasUserDeclaredConstructor() &&
- !Ctor->getParent()->isEmpty())
- CGF.EmitNullInitialization(NewPtr, ElementType);
-
- CGF.EmitCXXConstructorCall(Ctor, Ctor_Complete, /*ForVirtualBase=*/false,
- NewPtr, CCE->arg_begin(), CCE->arg_end());
- return;
- }
- // We have a POD type.
if (!Init)
return;
Modified: cfe/trunk/test/CodeGenCXX/debug-info-limit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-limit.cpp?rev=150738&r1=150737&r2=150738&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-limit.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-limit.cpp Thu Feb 16 16:45:48 2012
@@ -7,8 +7,8 @@
int z;
};
-A *foo () {
- A *a = new A();
+A *foo (A* x) {
+ A *a = new A(*x);
return a;
}
Modified: cfe/trunk/test/CodeGenCXX/exceptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/exceptions.cpp?rev=150738&r1=150737&r2=150738&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/exceptions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/exceptions.cpp Thu Feb 16 16:45:48 2012
@@ -194,12 +194,9 @@
// CHECK: [[SAVED0:%.*]] = alloca i8*
// CHECK-NEXT: [[SAVED1:%.*]] = alloca i8*
// CHECK-NEXT: [[CLEANUPACTIVE:%.*]] = alloca i1
- // CHECK-NEXT: [[TMP:%.*]] = alloca [[A]], align 8
- // CHECK: [[TMPACTIVE:%.*]] = alloca i1
// CHECK: [[COND:%.*]] = trunc i8 {{.*}} to i1
// CHECK-NEXT: store i1 false, i1* [[CLEANUPACTIVE]]
- // CHECK-NEXT: store i1 false, i1* [[TMPACTIVE]]
// CHECK-NEXT: br i1 [[COND]]
return (cond ?
@@ -209,24 +206,18 @@
// CHECK-NEXT: store i8* [[FOO]], i8** [[SAVED1]]
// CHECK-NEXT: store i1 true, i1* [[CLEANUPACTIVE]]
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
- // CHECK-NEXT: invoke void @_ZN5test35makeAEv([[A]]* sret [[TMP]])
- // CHECK: store i1 true, i1* [[TMPACTIVE]]
- // CHECK-NEXT: invoke void @_ZN5test31AC1ERKS0_([[A]]* [[CAST]], [[A]]* [[TMP]])
- // CHECK: store i1 false, i1* [[CLEANUPACTIVE]]
- // CHECK-NEXT: br label
+ // CHECK-NEXT: invoke void @_ZN5test35makeAEv([[A]]* sret [[CAST]])
+ // CHECK: br label
// -> cond.end
new(foo(),10.0) A(makeA()) :
- // CHECK: [[MAKE:%.*]] = invoke [[A]]* @_ZN5test38makeAPtrEv()
+ // CHECK: [[MAKE:%.*]] = call [[A]]* @_ZN5test38makeAPtrEv()
// CHECK: br label
// -> cond.end
makeAPtr());
// cond.end:
// CHECK: [[RESULT:%.*]] = phi [[A]]* {{.*}}[[CAST]]{{.*}}[[MAKE]]
- // CHECK-NEXT: [[ISACTIVE:%.*]] = load i1* [[TMPACTIVE]]
- // CHECK-NEXT: br i1 [[ISACTIVE]]
- // CHECK: invoke void @_ZN5test31AD1Ev
// CHECK: ret [[A]]* [[RESULT]]
// in the EH path:
Modified: cfe/trunk/test/CodeGenCXX/new.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new.cpp?rev=150738&r1=150737&r2=150738&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/new.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/new.cpp Thu Feb 16 16:45:48 2012
@@ -239,3 +239,14 @@
// CHECK: store i64 -1
NewTy* f() { return new NewTy[2](); }
}
+
+namespace PR11757 {
+ // Make sure we elide the copy construction.
+ struct X { X(); X(const X&); };
+ X* a(X* x) { return new X(X()); }
+ // CHECK: define {{.*}} @_ZN7PR117571aEPNS_1XE
+ // CHECK: [[CALL:%.*]] = call noalias i8* @_Znwm
+ // CHECK-NEXT: [[CASTED:%.*]] = bitcast i8* [[CALL]] to
+ // CHECK-NEXT: call void @_ZN7PR117571XC1Ev({{.*}}* [[CASTED]])
+ // CHECK-NEXT: ret {{.*}} [[CASTED]]
+}
Modified: cfe/trunk/test/CodeGenObjCXX/copy.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/copy.mm?rev=150738&r1=150737&r2=150738&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/copy.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/copy.mm Thu Feb 16 16:45:48 2012
@@ -14,8 +14,6 @@
// CHECK-NEXT: call noalias i8* @_Znwm(
// CHECK-NEXT: bitcast
// CHECK-NEXT: bitcast
- // CHECK-NEXT: call void @llvm.memset.p0i8.i64(
- // CHECK-NEXT: bitcast
// CHECK-NEXT: bitcast
// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(
// CHECK-NEXT: ret
More information about the cfe-commits
mailing list