From: Ted Kremenek Date: Mon, 6 Jul 2009 18:30:43 +0000 (+0000) Subject: Fix . The CF_RETURNS_RETAINED attribute should work if the... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6d4b76d93cbc5ad05af4cd2815c86febbfd5e798;p=clang Fix . The CF_RETURNS_RETAINED attribute should work if the return type on an Objective-C method is a CF type reference, not just an Objective-C object reference. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74841 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index c8919c38cb..d3d0545e99 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -1267,15 +1267,23 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ, if (!MD) return; + bool isTrackedLoc = false; + // Determine if there is a special return effect for this method. if (isTrackedObjCObjectType(MD->getResultType())) { if (MD->getAttr()) { Summ.setRetEffect(ObjCAllocRetE); + return; } - else if (MD->getAttr()) { - Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); - } + + isTrackedLoc = true; } + + if (!isTrackedLoc) + isTrackedLoc = MD->getResultType()->getAsPointerType() != NULL; + + if (isTrackedLoc && MD->getAttr()) + Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); } RetainSummary* diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index da0ae801da..63470146bb 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -815,7 +815,9 @@ void test_attr_1b(TestOwnershipAttr *X) { @interface MyClassTestCFAttr : NSObject {} - (NSDate*) returnsCFRetained __attribute__((cf_returns_retained)); +- (CFDateRef) returnsCFRetainedAsCF __attribute__((cf_returns_retained)); - (NSDate*) alsoReturnsRetained; +- (CFDateRef) alsoReturnsRetainedAsCF; - (NSDate*) returnsNSRetained __attribute__((ns_returns_retained)); @end @@ -829,10 +831,20 @@ CFDateRef returnsRetainedCFDate() { return (NSDate*) returnsRetainedCFDate(); // No leak. } +- (CFDateRef) returnsCFRetainedAsCF { + return returnsRetainedCFDate(); // No leak. +} + + - (NSDate*) alsoReturnsRetained { return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}} } +- (CFDateRef) alsoReturnsRetainedAsCF { + return returnsRetainedCFDate(); // expected-warning{{leak}} +} + + - (NSDate*) returnsNSRetained { return (NSDate*) returnsRetainedCFDate(); // no-warning }