mirror of
https://github.com/intel/llvm.git
synced 2026-01-27 14:50:42 +08:00
[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:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user