]> granicus.if.org Git - clang/commitdiff
Objective-C. Accept '__attribute__((__ns_returns_retained__))'
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 11 Jun 2014 21:22:53 +0000 (21:22 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 11 Jun 2014 21:22:53 +0000 (21:22 +0000)
for function/methods returning block in MRR mode as well.
// rdar://17259812

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210706 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/SemaObjC/ns_returns_retained_block_return.m [new file with mode: 0644]

index da9b8faaa7dd179abf308d8eda9551efd41a810b..6db2127bd31d7977ee7133cd9ede313f4c931c7f 100644 (file)
@@ -3348,6 +3348,13 @@ static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D,
 // 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(Sema &S, Decl *D,
   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;
diff --git a/test/SemaObjC/ns_returns_retained_block_return.m b/test/SemaObjC/ns_returns_retained_block_return.m
new file mode 100644 (file)
index 0000000..b7ce429
--- /dev/null
@@ -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));
+
+@interface I
+BT foo()  __attribute__((ns_returns_retained));
+@end
+
+@implementation I
+BT foo()  __attribute__((ns_returns_retained)) {return ^{}; }
+@end