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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72968 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ted Kremenek 2009-06-05 23:00:33 +00:00
Родитель 2968b7741d
Коммит b9d8db86ab
3 изменённых файлов: 60 добавлений и 3 удалений

Просмотреть файл

@ -1168,8 +1168,10 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ,
if (!FD) if (!FD)
return; return;
QualType RetTy = FD->getResultType();
// Determine if there is a special return effect for this method. // Determine if there is a special return effect for this method.
if (isTrackedObjCObjectType(FD->getResultType())) { if (isTrackedObjCObjectType(RetTy)) {
if (FD->getAttr<NSReturnsRetainedAttr>()) { if (FD->getAttr<NSReturnsRetainedAttr>()) {
Summ.setRetEffect(ObjCAllocRetE); Summ.setRetEffect(ObjCAllocRetE);
} }
@ -1177,6 +1179,11 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ,
Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true));
} }
} }
else if (RetTy->getAsPointerType()) {
if (FD->getAttr<CFReturnsRetainedAttr>()) {
Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true));
}
}
} }
void void

Просмотреть файл

@ -189,3 +189,27 @@ void test_attr_1b(TestOwnershipAttr *X) {
NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}} NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}}
} }
@interface MyClassTestCFAttr : NSObject {}
- (NSDate*) returnsCFRetained __attribute__((cf_returns_retained));
- (NSDate*) alsoReturnsRetained;
- (NSDate*) returnsNSRetained __attribute__((ns_returns_retained));
@end
__attribute__((cf_returns_retained))
CFDateRef returnsRetainedCFDate() {
return CFDateCreate(0, CFAbsoluteTimeGetCurrent());
}
@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}}
}
@end

Просмотреть файл

@ -704,5 +704,31 @@ void test_attr_1(TestOwnershipAttr *X) {
void test_attr_1b(TestOwnershipAttr *X) { void test_attr_1b(TestOwnershipAttr *X) {
NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}} NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}}
} }
//<<SLICER
@interface MyClassTestCFAttr : NSObject {}
- (NSDate*) returnsCFRetained __attribute__((cf_returns_retained));
- (NSDate*) alsoReturnsRetained;
- (NSDate*) returnsNSRetained __attribute__((ns_returns_retained));
@end
__attribute__((cf_returns_retained))
CFDateRef returnsRetainedCFDate() {
return CFDateCreate(0, CFAbsoluteTimeGetCurrent());
}
@implementation MyClassTestCFAttr
- (NSDate*) returnsCFRetained {
return (NSDate*) returnsRetainedCFDate(); // No leak.
}
- (NSDate*) alsoReturnsRetained {
return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}}
}
- (NSDate*) returnsNSRetained {
return (NSDate*) returnsRetainedCFDate(); // no-warning
}
@end