From 0ea4dfd0eb56b065460c1696933748e765120fe0 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 16 Jul 2010 21:18:37 +0000 Subject: [PATCH] When checking whether to bind an expression to a temporary, don't bind Obj-C message send expressions who call methods that return references. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108559 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprCXX.cpp | 28 ++++++++-------------------- test/CodeGenObjCXX/references.mm | 1 + 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 090400fc4e..a32dc53b30 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2579,29 +2579,17 @@ Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) { if (!RT) return Owned(E); - // If this is the result of a call expression, our source might - // actually be a reference, in which case we shouldn't bind. + // If this is the result of a call or an Objective-C message send expression, + // our source might actually be a reference, in which case we shouldn't bind. if (CallExpr *CE = dyn_cast(E)) { - QualType Ty = CE->getCallee()->getType(); - if (const PointerType *PT = Ty->getAs()) - Ty = PT->getPointeeType(); - else if (const BlockPointerType *BPT = Ty->getAs()) - Ty = BPT->getPointeeType(); - - const FunctionType *FTy = Ty->getAs(); - if (FTy->getResultType()->isReferenceType()) + if (CE->getCallReturnType()->isReferenceType()) return Owned(E); + } else if (ObjCMessageExpr *ME = dyn_cast(E)) { + if (const ObjCMethodDecl *MD = ME->getMethodDecl()) { + if (MD->getResultType()->isReferenceType()) + return Owned(E); + } } - else if (ObjCMessageExpr *ME = dyn_cast(E)) { - QualType Ty = ME->getType(); - if (const PointerType *PT = Ty->getAs()) - Ty = PT->getPointeeType(); - else if (const BlockPointerType *BPT = Ty->getAs()) - Ty = BPT->getPointeeType(); - if (Ty->isReferenceType()) - return Owned(E); - } - // That should be enough to guarantee that this type is complete. // If it has a trivial destructor, we can avoid the extra copy. diff --git a/test/CodeGenObjCXX/references.mm b/test/CodeGenObjCXX/references.mm index c2232e2e02..c12abc7de9 100644 --- a/test/CodeGenObjCXX/references.mm +++ b/test/CodeGenObjCXX/references.mm @@ -19,6 +19,7 @@ struct A { ~A(); }; // CHECK: define void @_Z1fP1B // CHECK: objc_msgSend to +// CHECK-NOT: call void @_ZN1AD1Ev // CHECK: ret void void f(B* b) { (void)[b getA]; -- 2.40.0