From fc78b59f920c3c076668decb5bf3792a621833a1 Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Tue, 11 Dec 2018 01:13:58 +0000 Subject: [PATCH] [analyzer] Hack for backwards compatibility for options for RetainCountChecker. To be removed once the clients update. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348821 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../RetainCountChecker/RetainCountChecker.cpp | 14 +++++++++++++- test/Analysis/test-separate-retaincount.cpp | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp index 8d0d407eab..488cf6d3eb 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp @@ -1530,7 +1530,19 @@ void ento::registerRetainCountChecker(CheckerManager &Mgr) { Chk->TrackObjCAndCFObjects = true; } +// FIXME: remove this, hack for backwards compatibility: +// it should be possible to enable the NS/CF retain count checker as +// osx.cocoa.RetainCount, and it should be possible to disable +// osx.OSObjectRetainCount using osx.cocoa.RetainCount:CheckOSObject=false. +static bool hasPrevCheckOSObjectOptionDisabled(AnalyzerOptions &Options) { + auto I = Options.Config.find("osx.cocoa.RetainCount:CheckOSObject"); + if (I != Options.Config.end()) + return I->getValue() == "false"; + return false; +} + void ento::registerOSObjectRetainCountChecker(CheckerManager &Mgr) { auto *Chk = Mgr.registerChecker(); - Chk->TrackOSObjects = true; + if (!hasPrevCheckOSObjectOptionDisabled(Mgr.getAnalyzerOptions())) + Chk->TrackOSObjects = true; } diff --git a/test/Analysis/test-separate-retaincount.cpp b/test/Analysis/test-separate-retaincount.cpp index 36bcc48df2..be6534f544 100644 --- a/test/Analysis/test-separate-retaincount.cpp +++ b/test/Analysis/test-separate-retaincount.cpp @@ -1,5 +1,6 @@ // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-disable-checker osx.cocoa.RetainCount -DNO_CF_OBJECT -verify %s // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-disable-checker osx.OSObjectRetainCount -DNO_OS_OBJECT -verify %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-config "osx.cocoa.RetainCount:CheckOSObject=false" -DNO_OS_OBJECT -verify %s typedef const void * CFTypeRef; extern CFTypeRef CFRetain(CFTypeRef cf); -- 2.40.0