diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-04-25 00:17:17 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-04-25 00:17:17 +0000 |
commit | de9a81b92e9098daa8ca19df138e4807b4d8afe8 (patch) | |
tree | 44a81835e966ef6e2f3aa6f1a89fe85378a94ee0 | |
parent | b5f1562d7b57a3dbe27a39b45995f59862973820 (diff) |
Add new checker-specific attribute 'objc_ownership_retain'. This isn't hooked up
to the checker yet, but essentially it allows a user to specify that an
Objective-C method or C function increments the reference count of a passed
object.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70005 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Attr.h | 2 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | include/clang/Parse/AttributeList.h | 3 | ||||
-rw-r--r-- | lib/Frontend/PCHReader.cpp | 1 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 1 | ||||
-rw-r--r-- | lib/Parse/AttributeList.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 14 | ||||
-rw-r--r-- | test/Analysis/retain-release.m | 8 |
8 files changed, 32 insertions, 2 deletions
diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index 93a9edb807..549ba632a4 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -51,6 +51,7 @@ public: NonNull, ObjCException, ObjCNSObject, + ObjCOwnershipRetain, // Clang/Checker-specific. ObjCOwnershipReturns, // Clang/Checker-specific. Overloadable, // Clang-specific Packed, @@ -599,6 +600,7 @@ public:\ }; // Checker-specific attributes. +DEF_SIMPLE_ATTR(ObjCOwnershipRetain) DEF_SIMPLE_ATTR(ObjCOwnershipReturns) #undef DEF_SIMPLE_ATTR diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 071fcab437..b9310db762 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -410,7 +410,7 @@ def warn_attribute_weak_import_invalid_on_definition : Warning< "'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}1 types">; + "variable and function|function or method|parameter}1 types">; def warn_gnu_inline_attribute_requires_inline : Warning< "'gnu_inline' attribute requires function to be marked 'inline'," " attribute ignored">; diff --git a/include/clang/Parse/AttributeList.h b/include/clang/Parse/AttributeList.h index 9712cc896e..b585838df8 100644 --- a/include/clang/Parse/AttributeList.h +++ b/include/clang/Parse/AttributeList.h @@ -75,9 +75,10 @@ public: AT_nothrow, AT_nsobject, AT_objc_exception, + AT_objc_ownership_retain, // Clang-specific. AT_objc_ownership_returns, // Clang-specific. AT_objc_gc, - AT_overloadable, // Clang-specific. + AT_overloadable, // Clang-specific. AT_packed, AT_pure, AT_regparm, diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 66f65dbb0b..b10778a1e1 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -3048,6 +3048,7 @@ Attr *PCHReader::ReadAttributes() { SIMPLE_ATTR(ObjCException); SIMPLE_ATTR(ObjCNSObject); + SIMPLE_ATTR(ObjCOwnershipRetain); SIMPLE_ATTR(ObjCOwnershipReturns); SIMPLE_ATTR(Overloadable); UNSIGNED_ATTR(Packed); diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 4d2f4092ef..421c345e78 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -2181,6 +2181,7 @@ void PCHWriter::WriteAttributeRecord(const Attr *Attr) { case Attr::ObjCException: case Attr::ObjCNSObject: + case Attr::ObjCOwnershipRetain: case Attr::ObjCOwnershipReturns: case Attr::Overloadable: break; diff --git a/lib/Parse/AttributeList.cpp b/lib/Parse/AttributeList.cpp index 33715899c5..a205c0468a 100644 --- a/lib/Parse/AttributeList.cpp +++ b/lib/Parse/AttributeList.cpp @@ -133,6 +133,9 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { case 18: if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result; break; + case 21: + if (!memcmp(Str, "objc_ownership_retain", 21)) + return AT_objc_ownership_returns; case 22: if (!memcmp(Str, "objc_ownership_returns", 22)) return AT_objc_ownership_returns; diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 5a99fdccd1..add12e53c2 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1533,6 +1533,18 @@ static void HandleObjCOwnershipReturnsAttr(Decl *d, const AttributeList &Attr, d->addAttr(::new (S.Context) ObjCOwnershipReturnsAttr()); } +static void HandleObjCOwnershipRetainAttr(Decl *d, const AttributeList &Attr, + Sema &S) { + + if (!isa<ParmVarDecl>(d)) { + S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << + "objc_ownership_retain" << 4 /* parameter */; + return; + } + + d->addAttr(::new (S.Context) ObjCOwnershipRetainAttr()); +} + //===----------------------------------------------------------------------===// // Top Level Sema Entry Points //===----------------------------------------------------------------------===// @@ -1571,6 +1583,8 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) { case AttributeList::AT_nothrow: HandleNothrowAttr (D, Attr, S); break; // Checker-specific. + case AttributeList::AT_objc_ownership_retain: + HandleObjCOwnershipRetainAttr(D, Attr, S); break; case AttributeList::AT_objc_ownership_returns: HandleObjCOwnershipReturnsAttr(D, Attr, S); break; diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index f5f3142cfe..0de2025398 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -411,9 +411,17 @@ void rdar6704930(unsigned char *s, unsigned int length) { @interface TestOwnershipAttr : NSObject - (NSString*) returnsAnOwnedString __attribute__((objc_ownership_returns)); +- (void) myRetain:(id __attribute__((objc_ownership_retain)))obj; @end void test_attr_1(TestOwnershipAttr *X) { NSString *str = [X returnsAnOwnedString]; // expected-warning{{leak}} } +void test_attr_2(TestOwnershipAttr *X) { + NSString *str = [X returnsAnOwnedString]; // no-warning (yet) + [X myRetain:str]; + [str release]; +} + + |