]> granicus.if.org Git - clang/commitdiff
Make copy constructor elimination work in more cases; the case in question
authorEli Friedman <eli.friedman@gmail.com>
Thu, 24 Dec 2009 23:33:34 +0000 (23:33 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 24 Dec 2009 23:33:34 +0000 (23:33 +0000)
here affects clang-on-clang.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92151 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/copy-constructor-elim-2.cpp [new file with mode: 0644]

index 7b9ee20abafa4627ab523f1d818a5276a0034be4..b0f23af8200b2439c15e8c921c5d01e8a65cf286 100644 (file)
@@ -590,6 +590,9 @@ CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest,
       Arg = ICE->getSubExpr();
     }
 
+    if (const CXXFunctionalCastExpr *FCE = dyn_cast<CXXFunctionalCastExpr>(Arg))
+      Arg = FCE->getSubExpr();
+
     if (const CXXBindTemporaryExpr *BindExpr = 
            dyn_cast<CXXBindTemporaryExpr>(Arg))
       Arg = BindExpr->getSubExpr();
index b70b0dccb75eeff546174c24805154b50f6b2c89..f29300e4acb47293e2d370503e0957aed3f6c342 100644 (file)
@@ -3793,6 +3793,8 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
     if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
       if (ICE->getCastKind() == CastExpr::CK_NoOp)
         E = ICE->getSubExpr();
+    if (CXXFunctionalCastExpr *FCE = dyn_cast<CXXFunctionalCastExpr>(E))
+      E = FCE->getSubExpr();
     while (CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E))
       E = BE->getSubExpr();
     if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
@@ -3803,6 +3805,8 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
       Elidable = !CE->getCallReturnType()->isReferenceType();
     else if (isa<CXXTemporaryObjectExpr>(E))
       Elidable = true;
+    else if (isa<CXXConstructExpr>(E))
+      Elidable = true;
   }
 
   return BuildCXXConstructExpr(ConstructLoc, DeclInitType, Constructor,
diff --git a/test/CodeGenCXX/copy-constructor-elim-2.cpp b/test/CodeGenCXX/copy-constructor-elim-2.cpp
new file mode 100644 (file)
index 0000000..3a06c10
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+struct A { int x; A(int); ~A(); };
+A f() { return A(0); }
+// CHECK: define void @_Z1fv
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: ret void