зеркало из https://github.com/microsoft/clang-1.git
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:
Родитель
2968b7741d
Коммит
b9d8db86ab
|
@ -1168,12 +1168,19 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ,
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,3 +189,27 @@ void test_attr_1b(TestOwnershipAttr *X) {
|
|||
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) {
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче