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<CallExpr>(E)) {
- QualType Ty = CE->getCallee()->getType();
- if (const PointerType *PT = Ty->getAs<PointerType>())
- Ty = PT->getPointeeType();
- else if (const BlockPointerType *BPT = Ty->getAs<BlockPointerType>())
- Ty = BPT->getPointeeType();
-
- const FunctionType *FTy = Ty->getAs<FunctionType>();
- if (FTy->getResultType()->isReferenceType())
+ if (CE->getCallReturnType()->isReferenceType())
return Owned(E);
+ } else if (ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E)) {
+ if (const ObjCMethodDecl *MD = ME->getMethodDecl()) {
+ if (MD->getResultType()->isReferenceType())
+ return Owned(E);
+ }
}
- else if (ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E)) {
- QualType Ty = ME->getType();
- if (const PointerType *PT = Ty->getAs<PointerType>())
- Ty = PT->getPointeeType();
- else if (const BlockPointerType *BPT = Ty->getAs<BlockPointerType>())
- 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.