[cfe-commits] r72968 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis/retain-release-gc-only.m test/Analysis/retain-release.m
Ted Kremenek
kremenek at apple.com
Fri Jun 5 16:00:33 PDT 2009
Author: kremenek
Date: Fri Jun 5 18:00:33 2009
New Revision: 72968
URL: http://llvm.org/viewvc/llvm-project?rev=72968&view=rev
Log:
Enhance attribute cf_returns_retained to also work (in the analyzer)
for non-Objctive-C pointer types. This implicitly documents that the
return type is a CF object reference.
Modified:
cfe/trunk/lib/Analysis/CFRefCount.cpp
cfe/trunk/test/Analysis/retain-release-gc-only.m
cfe/trunk/test/Analysis/retain-release.m
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=72968&r1=72967&r2=72968&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Jun 5 18:00:33 2009
@@ -1168,12 +1168,19 @@
if (!FD)
return;
+ QualType RetTy = FD->getResultType();
+
// Determine if there is a special return effect for this method.
- if (isTrackedObjCObjectType(FD->getResultType())) {
+ if (isTrackedObjCObjectType(RetTy)) {
if (FD->getAttr<NSReturnsRetainedAttr>()) {
Summ.setRetEffect(ObjCAllocRetE);
}
- else if (FD->getAttr<CFReturnsRetainedAttr>()) {
+ else if (FD->getAttr<CFReturnsRetainedAttr>()) {
+ Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true));
+ }
+ }
+ else if (RetTy->getAsPointerType()) {
+ if (FD->getAttr<CFReturnsRetainedAttr>()) {
Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true));
}
}
Modified: cfe/trunk/test/Analysis/retain-release-gc-only.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release-gc-only.m?rev=72968&r1=72967&r2=72968&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release-gc-only.m (original)
+++ cfe/trunk/test/Analysis/retain-release-gc-only.m Fri Jun 5 18:00:33 2009
@@ -189,3 +189,27 @@
NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}}
}
+ at interface MyClassTestCFAttr : NSObject {}
+- (NSDate*) returnsCFRetained __attribute__((cf_returns_retained));
+- (NSDate*) alsoReturnsRetained;
+- (NSDate*) returnsNSRetained __attribute__((ns_returns_retained));
+ at end
+
+__attribute__((cf_returns_retained))
+CFDateRef returnsRetainedCFDate() {
+ return CFDateCreate(0, CFAbsoluteTimeGetCurrent());
+}
+
+ at implementation MyClassTestCFAttr
+- (NSDate*) returnsCFRetained {
+ return (NSDate*) returnsRetainedCFDate(); // No leak.
+}
+
+- (NSDate*) alsoReturnsRetained {
+ return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}}
+}
+
+- (NSDate*) returnsNSRetained {
+ return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}}
+}
+ at end
\ No newline at end of file
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=72968&r1=72967&r2=72968&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Fri Jun 5 18:00:33 2009
@@ -704,5 +704,31 @@
void test_attr_1b(TestOwnershipAttr *X) {
NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}}
}
-//<<SLICER
+
+ at interface MyClassTestCFAttr : NSObject {}
+- (NSDate*) returnsCFRetained __attribute__((cf_returns_retained));
+- (NSDate*) alsoReturnsRetained;
+- (NSDate*) returnsNSRetained __attribute__((ns_returns_retained));
+ at end
+
+__attribute__((cf_returns_retained))
+CFDateRef returnsRetainedCFDate() {
+ return CFDateCreate(0, CFAbsoluteTimeGetCurrent());
+}
+
+ at implementation MyClassTestCFAttr
+- (NSDate*) returnsCFRetained {
+ return (NSDate*) returnsRetainedCFDate(); // No leak.
+}
+
+- (NSDate*) alsoReturnsRetained {
+ return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}}
+}
+
+- (NSDate*) returnsNSRetained {
+ return (NSDate*) returnsRetainedCFDate(); // no-warning
+}
+ at end
+
+
More information about the cfe-commits
mailing list