From e1138b8165f43da9921b5545b4958431ba7c7195 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Sat, 15 Dec 2018 02:13:26 +0000 Subject: [PATCH] [analyzer] Fix unknown block calls to have zero parameters. 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 | 2 +- test/Analysis/osobject-retain-release.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/StaticAnalyzer/Core/CallEvent.cpp b/lib/StaticAnalyzer/Core/CallEvent.cpp index 767116630f..8d9338b21c 100644 --- a/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -837,7 +837,7 @@ const BlockDataRegion *BlockCall::getBlockRegion() const { ArrayRef BlockCall::parameters() const { const BlockDecl *D = getDecl(); if (!D) - return nullptr; + return None; return D->parameters(); } diff --git a/test/Analysis/osobject-retain-release.cpp b/test/Analysis/osobject-retain-release.cpp index b8eb462d20..c8bc4aeaa0 100644 --- a/test/Analysis/osobject-retain-release.cpp +++ b/test/Analysis/osobject-retain-release.cpp @@ -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 +} + -- 2.40.0