[cfe-commits] r81743 - in /cfe/trunk: lib/CodeGen/CGCXXTemp.cpp lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/temp-1.cpp

Anders Carlsson andersca at mac.com
Sun Sep 13 18:30:44 PDT 2009


Author: andersca
Date: Sun Sep 13 20:30:44 2009
New Revision: 81743

URL: http://llvm.org/viewvc/llvm-project?rev=81743&view=rev
Log:
If a function call returns a reference, don't bind it to a temporary.

Modified:
    cfe/trunk/lib/CodeGen/CGCXXTemp.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/temp-1.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXTemp.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXTemp.cpp?rev=81743&r1=81742&r2=81743&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXXTemp.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXXTemp.cpp Sun Sep 13 20:30:44 2009
@@ -54,7 +54,13 @@
   assert(!CleanupInfo.EndBlock &&
          "Should not have an end block for temporary cleanup!");
 
-  EmitBlock(Info.DtorBlock);
+  llvm::BasicBlock *CurBB = Builder.GetInsertBlock();
+  if (CurBB && !CurBB->getTerminator() &&
+      Info.DtorBlock->getNumUses() == 0) {
+    CurBB->getInstList().splice(CurBB->end(), Info.DtorBlock->getInstList());
+    delete Info.DtorBlock;
+  } else
+    EmitBlock(Info.DtorBlock);
 
   llvm::BasicBlock *CondEnd = 0;
 

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=81743&r1=81742&r2=81743&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Sep 13 20:30:44 2009
@@ -1778,6 +1778,15 @@
   if (RD->hasTrivialDestructor())
     return Owned(E);
 
+  if (CallExpr *CE = dyn_cast<CallExpr>(E)) {
+    QualType Ty = CE->getCallee()->getType();
+    if (const PointerType *PT = Ty->getAs<PointerType>())
+      Ty = PT->getPointeeType();
+    
+    const FunctionType *FTy = Ty->getAsFunctionType();
+    if (FTy->getResultType()->isReferenceType())
+      return Owned(E);
+  }
   CXXTemporary *Temp = CXXTemporary::Create(Context,
                                             RD->getDestructor(Context));
   ExprTemporaries.push_back(Temp);

Modified: cfe/trunk/test/CodeGenCXX/temp-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/temp-1.cpp?rev=81743&r1=81742&r2=81743&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/temp-1.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/temp-1.cpp Sun Sep 13 20:30:44 2009
@@ -63,9 +63,21 @@
 };
 
 // RUN: grep "call void @_ZN1EC1Ev" %t | count 3 &&
-// RUN: grep "call void @_ZN1ED1Ev" %t | count 5 
+// RUN: grep "call void @_ZN1ED1Ev" %t | count 5 &&
 void f5() {
   E() + E();
   !E();
 }
 
+struct F {
+  F();
+  ~F();
+  F& f();
+};
+
+// RUN: grep "call void @_ZN1FC1Ev" %t | count 1 &&
+// RUN: grep "call void @_ZN1FD1Ev" %t | count 1 
+void f6() {
+  F().f();
+}
+





More information about the cfe-commits mailing list