]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix unknown block calls to have zero parameters.
authorArtem Dergachev <artem.dergachev@gmail.com>
Sat, 15 Dec 2018 02:13:26 +0000 (02:13 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Sat, 15 Dec 2018 02:13:26 +0000 (02:13 +0000)
Right now they report to have one parameter with null decl,
because initializing an ArrayRef of pointers with a nullptr
yields an ArrayRef to an array of one null pointer.

Fixes a crash in the OSObject section of RetainCountChecker.

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

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

lib/StaticAnalyzer/Core/CallEvent.cpp
test/Analysis/osobject-retain-release.cpp

index 767116630f40c673db16268f2965ab520f7fac5c..8d9338b21c1d9e938d11a53124a5a65b0c500861 100644 (file)
@@ -837,7 +837,7 @@ const BlockDataRegion *BlockCall::getBlockRegion() const {
 ArrayRef<ParmVarDecl*> BlockCall::parameters() const {
   const BlockDecl *D = getDecl();
   if (!D)
-    return nullptr;
+    return None;
   return D->parameters();
 }
 
index b8eb462d20eaedafacc2021cd0e8ca081edc09fd..c8bc4aeaa0a3c3dc72310fdcc3bfea35622d7647 100644 (file)
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core,osx -analyzer-output=text -verify %s
+// RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-output=text\
+// RUN:                    -analyzer-checker=core,osx -verify %s
 
 struct OSMetaClass;
 
@@ -399,3 +400,11 @@ unsigned int ok_release_with_unknown_source(ArrayOwner *owner) {
   arr->release(); // +0
   return arr->getCount();
 }
+
+OSObject *getObject();
+typedef bool (^Blk)(OSObject *);
+
+void test_escape_to_unknown_block(Blk blk) {
+  blk(getObject()); // no-crash
+}
+