[cfe-commits] r133849 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaObjCProperty.cpp test/SemaObjC/arc.m test/SemaObjC/property-ns-returns-not-retained-attr.m

Fariborz Jahanian fjahanian at apple.com
Fri Jun 24 17:17:47 PDT 2011


Author: fjahanian
Date: Fri Jun 24 19:17:46 2011
New Revision: 133849

URL: http://llvm.org/viewvc/llvm-project?rev=133849&view=rev
Log:
objc-arc/mrc: Allow ns_returns_not_retained attribute on properties
to turn off warning on those properties which follow Cocoa naming
convention for retaining objects and yet they were not meant for
such purposes. Also, perform consistancy checking for declared
getters of such methods. // rdar://9636091


Added:
    cfe/trunk/test/SemaObjC/property-ns-returns-not-retained-attr.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/arc.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=133849&r1=133848&r2=133849&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 24 19:17:46 2011
@@ -441,6 +441,9 @@
 def warn_ownin_getter_rule : Warning<
   "property's synthesized getter follows Cocoa naming"
   " convention for returning 'owned' objects">;
+def warn_property_getter_owning_mismatch : Warning<
+  "property declared as returning non-retained objects"
+  "; getter returning retained objects">;
 def err_ownin_getter_rule : Error<
   "property's synthesized getter follows Cocoa naming"
   " convention for returning 'owned' objects">;

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=133849&r1=133848&r2=133849&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Jun 24 19:17:46 2011
@@ -2716,6 +2716,8 @@
 
   if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(d))
     returnType = MD->getResultType();
+  else if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(d))
+    returnType = PD->getType();
   else if (S.getLangOptions().ObjCAutoRefCount && hasDeclarator(d) &&
            (attr.getKind() == AttributeList::AT_ns_returns_retained))
     return; // ignore: was handled as a type attribute

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=133849&r1=133848&r2=133849&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Fri Jun 24 19:17:46 2011
@@ -737,6 +737,12 @@
         PIDecl->setGetterCXXConstructor(ResExpr);
       }
     }
+    if (property->hasAttr<NSReturnsNotRetainedAttr>() &&
+        !getterMethod->hasAttr<NSReturnsNotRetainedAttr>()) {
+      Diag(getterMethod->getLocation(), 
+           diag::warn_property_getter_owning_mismatch);
+      Diag(property->getLocation(), diag::note_property_declare);
+    }
   }
   if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
     setterMethod->createImplicitParams(Context, IDecl);
@@ -1369,7 +1375,8 @@
       continue;
     
     const ObjCPropertyDecl *PD = PID->getPropertyDecl();
-    if (PD && !D->getInstanceMethod(PD->getGetterName())) {
+    if (PD && !PD->hasAttr<NSReturnsNotRetainedAttr>() &&
+        !D->getInstanceMethod(PD->getGetterName())) {
       ObjCMethodDecl *method = PD->getGetterMethodDecl();
       if (!method)
         continue;
@@ -1465,6 +1472,9 @@
     // and the real context should be the same.
     if (lexicalDC)
       GetterMethod->setLexicalDeclContext(lexicalDC);
+    if (property->hasAttr<NSReturnsNotRetainedAttr>())
+      GetterMethod->addAttr(
+        ::new (Context) NSReturnsNotRetainedAttr(Loc, Context));
   } else
     // A user declared getter will be synthesize when @synthesize of
     // the property with the same name is seen in the @implementation

Modified: cfe/trunk/test/SemaObjC/arc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc.m?rev=133849&r1=133848&r2=133849&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc.m (original)
+++ cfe/trunk/test/SemaObjC/arc.m Fri Jun 24 19:17:46 2011
@@ -572,3 +572,23 @@
   return (int)someid;
 }
 
+// rdar://9636091
+ at interface I34
+ at property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ;
+
+ at property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ;
+- (id) newName1 __attribute__((ns_returns_not_retained));
+
+ at property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}}
+- (id) newName2;   // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}}
+ at end
+
+ at implementation I34
+ at synthesize newName;
+
+ at synthesize newName1;
+- (id) newName1 { return 0; }
+
+ at synthesize newName2;
+ at end
+

Added: cfe/trunk/test/SemaObjC/property-ns-returns-not-retained-attr.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-ns-returns-not-retained-attr.m?rev=133849&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/property-ns-returns-not-retained-attr.m (added)
+++ cfe/trunk/test/SemaObjC/property-ns-returns-not-retained-attr.m Fri Jun 24 19:17:46 2011
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -verify %s
+// rdar://9636091
+
+ at interface I
+ at property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ;
+
+ at property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ;
+- (id) newName1 __attribute__((ns_returns_not_retained));
+
+ at property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}}
+- (id) newName2;   // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}}
+ at end
+
+ at implementation I
+ at synthesize newName;
+
+ at synthesize newName1;
+- (id) newName1 { return 0; }
+
+ at synthesize newName2;
+ at end





More information about the cfe-commits mailing list