From: Fariborz Jahanian Date: Wed, 11 Jun 2014 21:22:53 +0000 (+0000) Subject: Objective-C. Accept '__attribute__((__ns_returns_retained__))' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9b1c2f8934db8515f55033ae77470394a326d3c;p=clang Objective-C. Accept '__attribute__((__ns_returns_retained__))' 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 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index da9b8faaa7..6db2127bd3 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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 index 0000000000..b7ce429ffb --- /dev/null +++ b/test/SemaObjC/ns_returns_retained_block_return.m @@ -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