aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-09-30 20:50:23 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-09-30 20:50:23 +0000
commitf2e5945e3a989e9d981c03c4a9cbbfb6232c8c07 (patch)
tree93c7b74df9150307ffd514eeddc97af7f460487c
parentf2cee5cbdaf6fc017ae35cc8ecabc3b607a5f7e4 (diff)
objc arc: allow objc_returns_inner_pointer on methods that return
a reference type, since inner reference is much like an inner pointer. // rdar://10139365 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140880 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclAttr.cpp4
-rw-r--r--test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm22
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 0ffb92f00f..5802aaad96 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -3250,7 +3250,9 @@ static void handleObjCReturnsInnerPointerAttr(Sema &S, Decl *D,
// Check that the method returns a normal pointer.
QualType resultType = method->getResultType();
- if (!resultType->isPointerType() || resultType->isObjCRetainableType()) {
+
+ if (!resultType->isReferenceType() &&
+ (!resultType->isPointerType() || resultType->isObjCRetainableType())) {
S.Diag(method->getLocStart(), diag::warn_ns_attribute_wrong_return_type)
<< SourceRange(loc)
<< attr.getName() << /*method*/ 1 << /*non-retainable pointer*/ 2;
diff --git a/test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm b/test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm
new file mode 100644
index 0000000000..06c83d8e70
--- /dev/null
+++ b/test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fobjc-arc -o - %s | FileCheck %s
+// rdar://10139365
+
+@interface Test58
+- (char* &) interior __attribute__((objc_returns_inner_pointer));
+- (int&)reference_to_interior_int __attribute__((objc_returns_inner_pointer));
+@end
+
+void foo() {
+ Test58 *ptr;
+ char *c = [(ptr) interior];
+
+ int i = [(ptr) reference_to_interior_int];
+}
+
+// CHECK: [[T0:%.*]] = load {{%.*}} {{%.*}}, align 8
+// CHECK: [[T1:%.*]] = bitcast {{%.*}} [[T0]] to i8*
+// call i8* @objc_retainAutorelease(i8* [[T1]]) nounwind
+// CHECK: [[T2:%.*]] = load {{%.*}} {{%.*}}, align 8
+// CHECK: [[T3:%.*]] = bitcast {{%.*}} [[T2]] to i8*
+// call i8* @objc_retainAutorelease(i8* [[T3]]) nounwind
+