]> granicus.if.org Git - clang/commitdiff
Add back Parse/Sema support for attributes cf_returns_retained and
authorTed Kremenek <kremenek@apple.com>
Sat, 9 May 2009 02:44:38 +0000 (02:44 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 9 May 2009 02:44:38 +0000 (02:44 +0000)
ns_returns_retained, but do not include the other ownership attributes
we previously had.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71308 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Attr.h
include/clang/Parse/AttributeList.h
lib/Frontend/PCHReaderDecl.cpp
lib/Frontend/PCHWriter.cpp
lib/Sema/SemaDeclAttr.cpp

index 63705e3d688d8d68aad7957f5c63dab2b5a5cba1..287d80f93f4941932ace60e075c634f4c13400f9 100644 (file)
@@ -59,6 +59,8 @@ public:
     NonNull,
     ObjCException,
     ObjCNSObject,
+    CFReturnsRetained,   // Clang/Checker-specific.
+    NSReturnsRetained,   // Clang/Checker-specific.
     Overloadable, // Clang-specific
     Packed,
     Pure,
@@ -459,6 +461,10 @@ public:
   static bool classof(const RegparmAttr *A) { return true; }
 };
 
+// Checker-specific attributes.
+DEF_SIMPLE_ATTR(CFReturnsRetained);
+DEF_SIMPLE_ATTR(NSReturnsRetained);
+
 #undef DEF_SIMPLE_ATTR
   
 }  // end namespace clang
index 8f7c8f5f44cd7308aaf8acc279c7964dc7edb739..7f67213ae972b4c978abda5d2f4a1f447237d439 100644 (file)
@@ -76,6 +76,8 @@ public:
     AT_nothrow,
     AT_nsobject,
     AT_objc_exception,
+    AT_cf_returns_retained,   // Clang-specific.
+    AT_ns_returns_retained,   // Clang-specific.
     AT_objc_gc,
     AT_overloadable,       // Clang-specific.
     AT_packed,
index d47a008f1fcbabb8eacaba7787fe3677af7c2168..e623b6f1d7d6eb8c54b293c77b58d44ad30d7a4f 100644 (file)
@@ -475,6 +475,8 @@ Attr *PCHReader::ReadAttributes() {
 
     SIMPLE_ATTR(ObjCException);
     SIMPLE_ATTR(ObjCNSObject);
+    SIMPLE_ATTR(CFReturnsRetained);
+    SIMPLE_ATTR(NSReturnsRetained);
     SIMPLE_ATTR(Overloadable);
     UNSIGNED_ATTR(Packed);
     SIMPLE_ATTR(Pure);
index 688cedc524fc8028acb8595fecc67a76889116ab..4b9ca5c41a4ad9dcd996cc633b302b31ced84070 100644 (file)
@@ -1544,6 +1544,8 @@ void PCHWriter::WriteAttributeRecord(const Attr *Attr) {
 
     case Attr::ObjCException:
     case Attr::ObjCNSObject:
+    case Attr::CFReturnsRetained:
+    case Attr::NSReturnsRetained:
     case Attr::Overloadable:
       break;
 
index a5365fc654517242b1ca8db4073e515dd06d96fd..919f28ffec7868396602fe2171947b41b3fb75bf 100644 (file)
@@ -1543,6 +1543,44 @@ static void HandleRegparmAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   d->addAttr(::new (S.Context) RegparmAttr(NumParams.getZExtValue()));
 }
 
+//===----------------------------------------------------------------------===//
+// Checker-specific attribute handlers.
+//===----------------------------------------------------------------------===//
+
+static void HandleNSReturnsRetainedAttr(Decl *d, const AttributeList &Attr,
+                                        Sema &S) {
+
+  if (!isa<ObjCMethodDecl>(d) && !isa<FunctionDecl>(d)) {
+    const char *name;
+    
+    switch (Attr.getKind()) {
+      default:
+        assert(0 && "invalid ownership attribute");
+        return;
+      case AttributeList::AT_cf_returns_retained:
+        name = "cf_returns_retained"; break;
+      case AttributeList::AT_ns_returns_retained:
+        name = "ns_returns_retained"; break;
+    };
+
+    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) <<
+      name << 3 /* function or method */;
+    return;
+  }
+  
+  switch (Attr.getKind()) {
+    default:
+      assert(0 && "invalid ownership attribute");
+      return;
+    case AttributeList::AT_cf_returns_retained:
+      d->addAttr(::new (S.Context) CFReturnsRetainedAttr());
+      return;
+    case AttributeList::AT_ns_returns_retained:
+      d->addAttr(::new (S.Context) NSReturnsRetainedAttr());
+      return;
+  };
+}
+
 //===----------------------------------------------------------------------===//
 // Top Level Sema Entry Points
 //===----------------------------------------------------------------------===//
@@ -1579,6 +1617,12 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) {
   case AttributeList::AT_nonnull:     HandleNonNullAttr   (D, Attr, S); break;
   case AttributeList::AT_noreturn:    HandleNoReturnAttr  (D, Attr, S); break;
   case AttributeList::AT_nothrow:     HandleNothrowAttr   (D, Attr, S); break;
+
+  // Checker-specific.
+  case AttributeList::AT_ns_returns_retained:
+  case AttributeList::AT_cf_returns_retained:
+    HandleNSReturnsRetainedAttr(D, Attr, S); break;
+
   case AttributeList::AT_packed:      HandlePackedAttr    (D, Attr, S); break;
   case AttributeList::AT_section:     HandleSectionAttr   (D, Attr, S); break;
   case AttributeList::AT_stdcall:     HandleStdCallAttr   (D, Attr, S); break;