[cfe-commits] r140880 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm
Fariborz Jahanian
fjahanian at apple.com
Fri Sep 30 13:50:24 PDT 2011
Author: fjahanian
Date: Fri Sep 30 15:50:23 2011
New Revision: 140880
URL: http://llvm.org/viewvc/llvm-project?rev=140880&view=rev
Log:
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
Added:
cfe/trunk/test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm
Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=140880&r1=140879&r2=140880&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Sep 30 15:50:23 2011
@@ -3250,7 +3250,9 @@
// 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;
Added: cfe/trunk/test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm?rev=140880&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/arc-returns-inner-reference-ptr.mm Fri Sep 30 15:50:23 2011
@@ -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
+
+ at interface Test58
+- (char* &) interior __attribute__((objc_returns_inner_pointer));
+- (int&)reference_to_interior_int __attribute__((objc_returns_inner_pointer));
+ at 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
+
More information about the cfe-commits
mailing list