forked from OSchip/llvm-project
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. llvm-svn: 70005
This commit is contained in:
parent
12bdebbbf7
commit
2cfd264636
|
@ -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
|
||||
|
|
|
@ -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">;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue