From d1081ec5082ba6ba26809c66e410b127ca5819a8 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. llvm-svn: 348821 --- .../Checkers/RetainCountChecker/RetainCountChecker.cpp | 14 +++++++++++++- clang/test/Analysis/test-separate-retaincount.cpp | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp index 8d0d407..488cf6d 100644 --- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp +++ b/clang/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/clang/test/Analysis/test-separate-retaincount.cpp b/clang/test/Analysis/test-separate-retaincount.cpp index 36bcc48..be6534f 100644 --- a/clang/test/Analysis/test-separate-retaincount.cpp +++ b/clang/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.7.4