From f35a356878c6c32af246f2ab6fdf1cd907b7a56f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 19 Sep 2013 17:18:55 +0000 Subject: [PATCH] Refinement to my previous patch for objc_returns_inner_pointer on properties. // rdar://14990439 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191016 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Attr.td | 2 +- lib/Sema/SemaDeclAttr.cpp | 8 +++++++- test/SemaObjC/arc-property-lifetime.m | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 161e9c87d8..5681dafc30 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -571,7 +571,7 @@ def ObjCPreciseLifetime : InheritableAttr { def ObjCReturnsInnerPointer : InheritableAttr { let Spellings = [GNU<"objc_returns_inner_pointer">]; - let Subjects = [ObjCMethod]; + let Subjects = [ObjCMethod, ObjCProperty]; } def ObjCRequiresSuper : InheritableAttr { diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index d9e9972449..8a2d126dd6 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -4145,6 +4145,11 @@ static void handleNSReturnsRetainedAttr(Sema &S, Decl *D, static void handleObjCReturnsInnerPointerAttr(Sema &S, Decl *D, const AttributeList &attr) { + enum { + EP_ObjCMethod = 1, + EP_ObjCProperty + }; + SourceLocation loc = attr.getLoc(); QualType resultType; @@ -4167,7 +4172,8 @@ static void handleObjCReturnsInnerPointerAttr(Sema &S, Decl *D, (!resultType->isPointerType() || resultType->isObjCRetainableType())) { S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_return_type) << SourceRange(loc) - << attr.getName() << (method ? /*method*/ 1 : /*property*/ 2) << /*non-retainable pointer*/ 2; + << attr.getName() << (method ? EP_ObjCMethod : EP_ObjCProperty) + << /*non-retainable pointer*/ 2; // Drop the attribute. return; diff --git a/test/SemaObjC/arc-property-lifetime.m b/test/SemaObjC/arc-property-lifetime.m index 766a6141be..962154438b 100644 --- a/test/SemaObjC/arc-property-lifetime.m +++ b/test/SemaObjC/arc-property-lifetime.m @@ -174,6 +174,8 @@ void foo(Baz *f) { { const void * innerPointerIvar __attribute__((objc_returns_inner_pointer)); // expected-error {{'objc_returns_inner_pointer' attribute only applies to methods and properties}} } +@property (readonly) Boom * NotInnerPointer __attribute__((objc_returns_inner_pointer)); // expected-warning {{'objc_returns_inner_pointer' attribute only applies to properties that return a non-retainable pointer}} +- (Boom *) NotInnerPointerMethod __attribute__((objc_returns_inner_pointer)); // expected-warning {{'objc_returns_inner_pointer' attribute only applies to methods that return a non-retainable pointer}} @property (readonly) const void * innerPointer __attribute__((objc_returns_inner_pointer)); @end -- 2.50.1