diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 13 | ||||
| -rw-r--r-- | clang/test/SemaObjC/ns_returns_retained_block_return.m | 18 |
2 files changed, 30 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index da9b8faaa7d..6db2127bd31 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/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/clang/test/SemaObjC/ns_returns_retained_block_return.m b/clang/test/SemaObjC/ns_returns_retained_block_return.m new file mode 100644 index 00000000000..b7ce429ffb0 --- /dev/null +++ b/clang/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 |

