NonNull,
ObjCException,
ObjCNSObject,
+ ObjCOwnershipRetain, // Clang/Checker-specific.
ObjCOwnershipReturns, // Clang/Checker-specific.
Overloadable, // Clang-specific
Packed,
};
// Checker-specific attributes.
+DEF_SIMPLE_ATTR(ObjCOwnershipRetain)
DEF_SIMPLE_ATTR(ObjCOwnershipReturns)
#undef DEF_SIMPLE_ATTR
"'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">;
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,
SIMPLE_ATTR(ObjCException);
SIMPLE_ATTR(ObjCNSObject);
+ SIMPLE_ATTR(ObjCOwnershipRetain);
SIMPLE_ATTR(ObjCOwnershipReturns);
SIMPLE_ATTR(Overloadable);
UNSIGNED_ATTR(Packed);
case Attr::ObjCException:
case Attr::ObjCNSObject:
+ case Attr::ObjCOwnershipRetain:
case Attr::ObjCOwnershipReturns:
case Attr::Overloadable:
break;
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;
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
//===----------------------------------------------------------------------===//
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;
@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];
+}
+
+