r210706 - Objective-C. Accept '__attribute__((__ns_returns_retained__))'

Fariborz Jahanian fjahanian at apple.com
Wed Jun 11 14:22:54 PDT 2014


Author: fjahanian
Date: Wed Jun 11 16:22:53 2014
New Revision: 210706

URL: http://llvm.org/viewvc/llvm-project?rev=210706&view=rev
Log:
Objective-C. Accept '__attribute__((__ns_returns_retained__))' 
for function/methods returning block in MRR mode as well.
// rdar://17259812

Added:
    cfe/trunk/test/SemaObjC/ns_returns_retained_block_return.m
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=210706&r1=210705&r2=210706&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Jun 11 16:22:53 2014
@@ -3348,6 +3348,13 @@ static void handleTypeTagForDatatypeAttr
 // Checker-specific attribute handlers.
 //===----------------------------------------------------------------------===//
 
+static bool isValidSubjectOfNSReturnsRetainedAttribute(Sema &S, QualType type) {
+  return type->isDependentType() ||
+         type->isObjCObjectPointerType() ||
+         type->isBlockPointerType() ||
+         S.Context.isObjCNSObjectType(type);
+}
+
 static bool isValidSubjectOfNSAttribute(Sema &S, QualType type) {
   return type->isDependentType() || 
          type->isObjCObjectPointerType() || 
@@ -3412,8 +3419,12 @@ static void handleNSReturnsRetainedAttr(
   bool cf;
   switch (Attr.getKind()) {
   default: llvm_unreachable("invalid ownership attribute");
-  case AttributeList::AT_NSReturnsAutoreleased:
   case AttributeList::AT_NSReturnsRetained:
+    typeOK = isValidSubjectOfNSReturnsRetainedAttribute(S, returnType);
+    cf = false;
+    break;
+      
+  case AttributeList::AT_NSReturnsAutoreleased:
   case AttributeList::AT_NSReturnsNotRetained:
     typeOK = isValidSubjectOfNSAttribute(S, returnType);
     cf = false;

Added: cfe/trunk/test/SemaObjC/ns_returns_retained_block_return.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ns_returns_retained_block_return.m?rev=210706&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/ns_returns_retained_block_return.m (added)
+++ cfe/trunk/test/SemaObjC/ns_returns_retained_block_return.m Wed Jun 11 16:22:53 2014
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1  -fblocks -fsyntax-only -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fsyntax-only -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1  -fblocks -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s
+// expected-no-diagnostics
+// rdar://17259812
+
+typedef void (^BT) ();
+
+BT foo()  __attribute__((ns_returns_retained));
+
+ at interface I
+BT foo()  __attribute__((ns_returns_retained));
+ at end
+
+ at implementation I
+BT foo()  __attribute__((ns_returns_retained)) {return ^{}; }
+ at end





More information about the cfe-commits mailing list