зеркало из https://github.com/microsoft/clang-1.git
Teach the static analyzer that NSLog() and friends do not hold on to object references (thus extending their lifetime).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156346 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
9b79fc9c57
Коммит
c91fdf662d
|
@ -648,6 +648,10 @@ public:
|
|||
return getPersistentSummary(Summ);
|
||||
}
|
||||
|
||||
const RetainSummary *getDoNothingSummary() {
|
||||
return getPersistentSummary(RetEffect::MakeNoRet(), DoNothing, DoNothing);
|
||||
}
|
||||
|
||||
const RetainSummary *getDefaultSummary() {
|
||||
return getPersistentSummary(RetEffect::MakeNoRet(),
|
||||
DoNothing, MayEscape);
|
||||
|
@ -997,6 +1001,8 @@ RetainSummaryManager::getSummary(const FunctionDecl *FD,
|
|||
// libdispatch finalizers.
|
||||
ScratchArgs = AF.add(ScratchArgs, 1, StopTracking);
|
||||
S = getPersistentSummary(RetEffect::MakeNoRet(), DoNothing, DoNothing);
|
||||
} else if (FName.startswith("NSLog")) {
|
||||
S = getDoNothingSummary();
|
||||
} else if (FName.startswith("NS") &&
|
||||
(FName.find("Insert") != StringRef::npos)) {
|
||||
// Whitelist NSXXInsertXX, for example NSMapInsertIfAbsent, since they can
|
||||
|
|
|
@ -1784,3 +1784,17 @@ void test_objc_arrays() {
|
|||
}
|
||||
}
|
||||
|
||||
// Test NSLog doesn't escape tracked objects.
|
||||
void rdar11400885(int y)
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSString *printString;
|
||||
if(y > 2)
|
||||
printString = [[NSString alloc] init];
|
||||
else
|
||||
printString = [[NSString alloc] init];
|
||||
NSLog(@"Once %@", printString);
|
||||
[printString release];
|
||||
NSLog(@"Again: %@", printString); // expected-warning {{Reference-counted object is used after it is released}}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче