diff options
-rw-r--r-- | lib/CodeGen/CGCXXTemp.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 9 | ||||
-rw-r--r-- | test/CodeGenCXX/temp-1.cpp | 14 |
3 files changed, 29 insertions, 2 deletions
diff --git a/lib/CodeGen/CGCXXTemp.cpp b/lib/CodeGen/CGCXXTemp.cpp index 177c6db3e8..4768556f6b 100644 --- a/lib/CodeGen/CGCXXTemp.cpp +++ b/lib/CodeGen/CGCXXTemp.cpp @@ -54,7 +54,13 @@ void CodeGenFunction::PopCXXTemporary() { 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; diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index a060e47067..a6bf82b590 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -1778,6 +1778,15 @@ Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) { 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); diff --git a/test/CodeGenCXX/temp-1.cpp b/test/CodeGenCXX/temp-1.cpp index 19a6acecf2..9b97f0083c 100644 --- a/test/CodeGenCXX/temp-1.cpp +++ b/test/CodeGenCXX/temp-1.cpp @@ -63,9 +63,21 @@ struct E { }; // 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(); +} + |