[cfe-commits] r152485 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CodeGenCXX/copy-constructor-elim-2.cpp
Douglas Gregor
dgregor at apple.com
Fri Mar 9 22:53:13 PST 2012
Author: dgregor
Date: Sat Mar 10 00:53:13 2012
New Revision: 152485
URL: http://llvm.org/viewvc/llvm-project?rev=152485&view=rev
Log:
Only make a call to a copy constructor elidable if in fact we are
doing a copy. Fixes PR12139.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=152485&r1=152484&r2=152485&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Mar 10 00:53:13 2012
@@ -8876,6 +8876,25 @@
}
}
+/// \brief Determine whether the given list arguments contains exactly one
+/// "real" (non-default) argument.
+static bool hasOneRealArgument(MultiExprArg Args) {
+ switch (Args.size()) {
+ case 0:
+ return false;
+
+ default:
+ if (!Args.get()[1]->isDefaultArgument())
+ return false;
+
+ // fall through
+ case 1:
+ return !Args.get()[0]->isDefaultArgument();
+ }
+
+ return false;
+}
+
ExprResult
Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
CXXConstructorDecl *Constructor,
@@ -8897,7 +8916,7 @@
// can be omitted by constructing the temporary object
// directly into the target of the omitted copy/move
if (ConstructKind == CXXConstructExpr::CK_Complete &&
- Constructor->isCopyOrMoveConstructor() && ExprArgs.size() >= 1) {
+ Constructor->isCopyOrMoveConstructor() && hasOneRealArgument(ExprArgs)) {
Expr *SubExpr = ((Expr **)ExprArgs.get())[0];
Elidable = SubExpr->isTemporaryObject(Context, Constructor->getParent());
}
Modified: cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp?rev=152485&r1=152484&r2=152485&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp Sat Mar 10 00:53:13 2012
@@ -53,3 +53,25 @@
}
}
+
+namespace PR12139 {
+ struct A {
+ A() : value(1) { }
+ A(A const &, int value = 2) : value(value) { }
+ int value;
+
+ static A makeA() { A a; a.value = 2; return a; }
+ };
+
+ // CHECK: define i32 @_ZN7PR121394testEv
+ int test() {
+ // CHECK: call void @_ZN7PR121391A5makeAEv
+ // CHECK-NEXT: call void @_ZN7PR121391AC1ERKS0_i
+ A a(A::makeA(), 3);
+ // CHECK-NEXT: getelementptr inbounds
+ // CHECK-NEXT: load
+ // CHECK-NEXT: ret i32
+ return a.value;
+ }
+}
+
More information about the cfe-commits
mailing list