From: Ted Kremenek Date: Thu, 20 Dec 2012 19:36:22 +0000 (+0000) Subject: Update RetainCountChecker to understand attribute ns_returns_autoreleased. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbf4d53343c2bbd082b7c1488f34650a7d07ae3b;p=clang Update RetainCountChecker to understand attribute ns_returns_autoreleased. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170724 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index b38894ccfa..b57c6e2b4f 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -1306,13 +1306,14 @@ RetainSummaryManager::updateSummaryFromAnnotations(const RetainSummary *&Summ, else if (FD->getAttr()) { Template->setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); } - else if (FD->getAttr()) { + else if (FD->getAttr() || + FD->getAttr()) { Template->setRetEffect(RetEffect::MakeNotOwned(RetEffect::ObjC)); } - else if (FD->getAttr()) { + else if (FD->getAttr()) Template->setRetEffect(RetEffect::MakeNotOwned(RetEffect::CF)); } - } else if (RetTy->getAs()) { + else if (RetTy->getAs()) { if (FD->getAttr()) { Template->setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); } @@ -1359,7 +1360,8 @@ RetainSummaryManager::updateSummaryFromAnnotations(const RetainSummary *&Summ, Template->setRetEffect(ObjCAllocRetE); return; } - if (MD->getAttr()) { + if (MD->getAttr() || + MD->getAttr()) { Template->setRetEffect(RetEffect::MakeNotOwned(RetEffect::ObjC)); return; } diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index ef2566b961..2b5a4adced 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -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 @@ typedef NSString* MyStringTy; - (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_attr_1b(TestOwnershipAttr *X) { 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() {