From 180ff3ac073c86bf7b5dbf48cfdfb7fc8252ce5f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 2 Mar 2011 20:09:49 +0000 Subject: [PATCH] IRGen. Fix IR when message returns reference type. // rdar://8604515. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126869 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprScalar.cpp | 3 +++ test/CodeGenObjCXX/message-reference.mm | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/CodeGenObjCXX/message-reference.mm diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index b11236a97f..6f52a539cf 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -245,6 +245,9 @@ public: return EmitLoadOfLValue(E); } Value *VisitObjCMessageExpr(ObjCMessageExpr *E) { + if (E->getMethodDecl() && + E->getMethodDecl()->getResultType()->isReferenceType()) + return EmitLoadOfLValue(E); return CGF.EmitObjCMessageExpr(E).getScalarVal(); } diff --git a/test/CodeGenObjCXX/message-reference.mm b/test/CodeGenObjCXX/message-reference.mm new file mode 100644 index 0000000000..b7cf98d88c --- /dev/null +++ b/test/CodeGenObjCXX/message-reference.mm @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s +// rdar://8604515 + +@interface I {} +-(unsigned int&)referenceCount; +@end + +@interface MyClass ++(int)writeBlip:(I*)srcBlip; +@end + +@implementation MyClass ++(int)writeBlip:(I*)srcBlip{ + return ([srcBlip referenceCount] == 0); +} +@end + +// CHECK: [[T:%.*]] = call i32* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend +// CHECK: [[U:%.*]] = load i32* [[T]] +// CHECK [[V:%.*]] = icmp eq i32 [[U]], 0 -- 2.40.0