[analyzer] RetainCount: A function isn't a CFRetain if it takes no arguments.

Don't crash when a function has a name that starts with "CF" and ends with
"Retain" but takes 0 arguments. In particular, don't try to treat it as if
it returns its first argument.

These problems are inevitable because the checker is naming-convention-based,
but at least we shouldn't crash.

Differential Revision: https://reviews.llvm.org/D59123

llvm-svn: 356223
This commit is contained in:
Artem Dergachev
2019-03-15 00:26:17 +00:00
parent 06451368d2
commit f2192b204f
2 changed files with 19 additions and 6 deletions

View File

@@ -722,12 +722,13 @@ RetainSummaryManager::canEval(const CallExpr *CE, const FunctionDecl *FD,
// These are not retain. They just return something and retain it.
return None;
}
if (cocoa::isRefType(ResultTy, "CF", FName) ||
cocoa::isRefType(ResultTy, "CG", FName) ||
cocoa::isRefType(ResultTy, "CV", FName))
if (isRetain(FD, FName) || isAutorelease(FD, FName) ||
isMakeCollectable(FName))
return BehaviorSummary::Identity;
if (CE->getNumArgs() == 1 &&
(cocoa::isRefType(ResultTy, "CF", FName) ||
cocoa::isRefType(ResultTy, "CG", FName) ||
cocoa::isRefType(ResultTy, "CV", FName)) &&
(isRetain(FD, FName) || isAutorelease(FD, FName) ||
isMakeCollectable(FName)))
return BehaviorSummary::Identity;
// safeMetaCast is called by OSDynamicCast.
// We assume that OSDynamicCast is either an identity (cast is OK,

View File

@@ -503,3 +503,15 @@ void test_cxx_method_escaping(S *s) {
}
}
namespace yet_another_unexpected_signature_crash {
CFTypeRef CFSomethingSomethingRetain();
CFTypeRef CFSomethingSomethingAutorelease();
void foo() {
CFSomethingSomethingRetain(); // no-crash
CFSomethingSomethingAutorelease(); // no-crash
}
}