[cfe-commits] r70005 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Basic/DiagnosticSemaKinds.td include/clang/Parse/AttributeList.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp lib/Parse/AttributeList.cpp lib/Sema/SemaDeclAttr.cpp test/Analysis/retain-release.m
Ted Kremenek
kremenek at apple.com
Fri Apr 24 17:17:20 PDT 2009
Author: kremenek
Date: Fri Apr 24 19:17:17 2009
New Revision: 70005
URL: http://llvm.org/viewvc/llvm-project?rev=70005&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Parse/AttributeList.h
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/lib/Parse/AttributeList.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Analysis/retain-release.m
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=70005&r1=70004&r2=70005&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Fri Apr 24 19:17:17 2009
@@ -51,6 +51,7 @@
NonNull,
ObjCException,
ObjCNSObject,
+ ObjCOwnershipRetain, // Clang/Checker-specific.
ObjCOwnershipReturns, // Clang/Checker-specific.
Overloadable, // Clang-specific
Packed,
@@ -599,6 +600,7 @@
};
// Checker-specific attributes.
+DEF_SIMPLE_ATTR(ObjCOwnershipRetain)
DEF_SIMPLE_ATTR(ObjCOwnershipReturns)
#undef DEF_SIMPLE_ATTR
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=70005&r1=70004&r2=70005&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr 24 19:17:17 2009
@@ -410,7 +410,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}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">;
Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=70005&r1=70004&r2=70005&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Fri Apr 24 19:17:17 2009
@@ -75,9 +75,10 @@
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,
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=70005&r1=70004&r2=70005&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Apr 24 19:17:17 2009
@@ -3048,6 +3048,7 @@
SIMPLE_ATTR(ObjCException);
SIMPLE_ATTR(ObjCNSObject);
+ SIMPLE_ATTR(ObjCOwnershipRetain);
SIMPLE_ATTR(ObjCOwnershipReturns);
SIMPLE_ATTR(Overloadable);
UNSIGNED_ATTR(Packed);
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=70005&r1=70004&r2=70005&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Apr 24 19:17:17 2009
@@ -2181,6 +2181,7 @@
case Attr::ObjCException:
case Attr::ObjCNSObject:
+ case Attr::ObjCOwnershipRetain:
case Attr::ObjCOwnershipReturns:
case Attr::Overloadable:
break;
Modified: cfe/trunk/lib/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=70005&r1=70004&r2=70005&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/AttributeList.cpp (original)
+++ cfe/trunk/lib/Parse/AttributeList.cpp Fri Apr 24 19:17:17 2009
@@ -133,6 +133,9 @@
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;
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=70005&r1=70004&r2=70005&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr 24 19:17:17 2009
@@ -1533,6 +1533,18 @@
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 @@
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;
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=70005&r1=70004&r2=70005&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Fri Apr 24 19:17:17 2009
@@ -411,9 +411,17 @@
@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];
+}
+
+
More information about the cfe-commits
mailing list