]> granicus.if.org Git - clang/commitdiff
[analyzer] RetainCount: A function isn't a CFRetain if it takes no arguments.
authorArtem Dergachev <artem.dergachev@gmail.com>
Fri, 15 Mar 2019 00:26:17 +0000 (00:26 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Fri, 15 Mar 2019 00:26:17 +0000 (00:26 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356223 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/RetainSummaryManager.cpp
test/Analysis/retain-release.mm

index 2eee01ca6a62235f41306ae80d9ec51b3e5d71bd..ae8ccb13ca5021ffa03dc05bc85b71c9c579e2da 100644 (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,
index 97ea5607d2d28e0ccfb9cc1f27d9cd08403ed8f8..ba864f817c5e74ad8bc865f80b6e499f8d930e3c 100644 (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
+}
+
+}