[cfe-commits] r70505 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/Analysis/retain-release.m

Ted Kremenek kremenek at apple.com
Thu Apr 30 12:18:04 PDT 2009


Author: kremenek
Date: Thu Apr 30 14:18:03 2009
New Revision: 70505

URL: http://llvm.org/viewvc/llvm-project?rev=70505&view=rev
Log:
Allow attributes 'objc_ownership_retain' and 'objc_ownership_release' to be
applied to ObjCMethodDecls, not just parameters. This allows one to specific
side-effects on the receiver of a message expression. No checker support yet.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Analysis/retain-release.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=70505&r1=70504&r2=70505&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 30 14:18:03 2009
@@ -408,7 +408,7 @@
   "'weak_import' attribute cannot be specified on a definition">;
 def warn_attribute_wrong_decl_type : Warning<
   "'%0' attribute only applies to %select{function|union|"
-  "variable and function|function or method|parameter}1 types">;
+  "variable and function|function or method|parameter|parameter or Objective-C method}1 types">;
 def warn_gnu_inline_attribute_requires_inline : Warning<
   "'gnu_inline' attribute requires function to be marked 'inline',"
   " attribute ignored">;

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=70505&r1=70504&r2=70505&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Apr 30 14:18:03 2009
@@ -1559,10 +1559,10 @@
   d->addAttr(::new (S.Context) ObjCOwnershipReturnsAttr());
 }
 
-static void HandleObjCOwnershipParmAttr(Decl *d, const AttributeList &Attr,
-                                        Sema &S) {
+static void HandleObjCOwnershipAttr(Decl *d, const AttributeList &Attr,
+                                    Sema &S, bool attachToMethodDecl = false) {
   
-  if (!isa<ParmVarDecl>(d)) {
+  if (!isa<ParmVarDecl>(d) && (!attachToMethodDecl || !isa<ObjCMethodDecl>(d))){
     const char *name;
     
     switch (Attr.getKind()) {
@@ -1582,7 +1582,8 @@
     };
 
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << name
-          << 4 /* parameter */;
+      << (attachToMethodDecl ? 5 /* parameter or method decl */ 
+                             : 4 /* parameter */);
     return;
   }
   
@@ -1643,10 +1644,11 @@
   // Checker-specific.
   case AttributeList::AT_objc_ownership_cfrelease:     
   case AttributeList::AT_objc_ownership_cfretain:
+      HandleObjCOwnershipAttr(D, Attr, S); break;
   case AttributeList::AT_objc_ownership_make_collectable:
   case AttributeList::AT_objc_ownership_release:
   case AttributeList::AT_objc_ownership_retain:
-    HandleObjCOwnershipParmAttr(D, Attr, S); break;
+      HandleObjCOwnershipAttr(D, Attr, S, true); break;
   case AttributeList::AT_objc_ownership_returns:
     HandleObjCOwnershipReturnsAttr(D, Attr, S); break;
 

Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=70505&r1=70504&r2=70505&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Apr 30 14:18:03 2009
@@ -440,6 +440,9 @@
 - (void) myCFRetain:(id)__attribute__((objc_ownership_cfretain))obj;
 - (void) myRelease:(id)__attribute__((objc_ownership_release))obj;
 - (void) myCFRelease:(id)__attribute__((objc_ownership_cfrelease))obj;
+
+- (void) myRetain __attribute__((objc_ownership_retain));
+- (void) myRelease __attribute__((objc_ownership_release));
 @end
 
 @interface TestAttrHelper : NSObject





More information about the cfe-commits mailing list