[cfe-commits] r170724 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp test/Analysis/retain-release.m
Ted Kremenek
kremenek at apple.com
Thu Dec 20 11:36:22 PST 2012
Author: kremenek
Date: Thu Dec 20 13:36:22 2012
New Revision: 170724
URL: http://llvm.org/viewvc/llvm-project?rev=170724&view=rev
Log:
Update RetainCountChecker to understand attribute ns_returns_autoreleased.
Fixes <rdar://problem/12887356>.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
cfe/trunk/test/Analysis/retain-release.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=170724&r1=170723&r2=170724&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Thu Dec 20 13:36:22 2012
@@ -1306,13 +1306,14 @@
else if (FD->getAttr<CFReturnsRetainedAttr>()) {
Template->setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true));
}
- else if (FD->getAttr<NSReturnsNotRetainedAttr>()) {
+ else if (FD->getAttr<NSReturnsNotRetainedAttr>() ||
+ FD->getAttr<NSReturnsAutoreleasedAttr>()) {
Template->setRetEffect(RetEffect::MakeNotOwned(RetEffect::ObjC));
}
- else if (FD->getAttr<CFReturnsNotRetainedAttr>()) {
+ else if (FD->getAttr<CFReturnsNotRetainedAttr>())
Template->setRetEffect(RetEffect::MakeNotOwned(RetEffect::CF));
}
- } else if (RetTy->getAs<PointerType>()) {
+ else if (RetTy->getAs<PointerType>()) {
if (FD->getAttr<CFReturnsRetainedAttr>()) {
Template->setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true));
}
@@ -1359,7 +1360,8 @@
Template->setRetEffect(ObjCAllocRetE);
return;
}
- if (MD->getAttr<NSReturnsNotRetainedAttr>()) {
+ if (MD->getAttr<NSReturnsNotRetainedAttr>() ||
+ MD->getAttr<NSReturnsAutoreleasedAttr>()) {
Template->setRetEffect(RetEffect::MakeNotOwned(RetEffect::ObjC));
return;
}
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=170724&r1=170723&r2=170724&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Dec 20 13:36:22 2012
@@ -25,6 +25,9 @@
#if __has_feature(attribute_cf_consumed)
#define CF_CONSUMED __attribute__((cf_consumed))
#endif
+#if __has_attribute(ns_returns_autoreleased)
+#define NS_RETURNS_AUTORELEASED __attribute__((ns_returns_autoreleased))
+#endif
//===----------------------------------------------------------------------===//
// The following code is reduced using delta-debugging from Mac OS X headers:
@@ -1300,6 +1303,7 @@
- (NSString*) returnsAnOwnedCFString CF_RETURNS_RETAINED; // no-warning
- (MyStringTy) returnsAnOwnedTypedString NS_RETURNS_RETAINED; // no-warning
- (NSString*) newString NS_RETURNS_NOT_RETAINED; // no-warning
+- (NSString*) newString_auto NS_RETURNS_AUTORELEASED; // no-warning
- (NSString*) newStringNoAttr;
- (int) returnsAnOwnedInt NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to methods that return an Objective-C object}}
- (id) pseudoInit NS_CONSUMES_SELF NS_RETURNS_RETAINED;
@@ -1320,6 +1324,8 @@
void test_attr1c(TestOwnershipAttr *X) {
NSString *str = [X newString]; // no-warning
NSString *str2 = [X newStringNoAttr]; // expected-warning{{leak}}
+ NSString *str3 = [X newString_auto]; // no-warning
+ NSString *str4 = [[X newString_auto] retain]; // expected-warning {{leak}}
}
void testattr2_a() {
More information about the cfe-commits
mailing list