summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/CheckerRegistry.cpp
diff options
context:
space:
mode:
authorKristof Umann <dkszelethus@gmail.com>2018-11-18 12:47:03 +0000
committerKristof Umann <dkszelethus@gmail.com>2018-11-18 12:47:03 +0000
commit45beaa0bb9330ec1a519f001a54555bee1638840 (patch)
tree3ef33217ca790e3c9ab2af581bac95fef108ae48 /clang/lib/StaticAnalyzer/Core/CheckerRegistry.cpp
parent83aabf43eacedee77725fee2b6b2d1b625fe1422 (diff)
downloadbcm5719-llvm-45beaa0bb9330ec1a519f001a54555bee1638840.tar.gz
bcm5719-llvm-45beaa0bb9330ec1a519f001a54555bee1638840.zip
[analyzer][NFC] Move CheckerOptInfo to CheckerRegistry.cpp, and make it local
CheckerOptInfo feels very much out of place in CheckerRegistration.cpp, so I moved it to CheckerRegistry.h. Differential Revision: https://reviews.llvm.org/D54397 llvm-svn: 347157
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/CheckerRegistry.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/CheckerRegistry.cpp59
1 files changed, 53 insertions, 6 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/CheckerRegistry.cpp b/clang/lib/StaticAnalyzer/Core/CheckerRegistry.cpp
index 89adea2cffe..00475c04fdf 100644
--- a/clang/lib/StaticAnalyzer/Core/CheckerRegistry.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CheckerRegistry.cpp
@@ -12,7 +12,6 @@
#include "clang/Basic/LLVM.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
-#include "clang/StaticAnalyzer/Core/CheckerOptInfo.h"
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
@@ -30,6 +29,41 @@ static const char PackageSeparator = '.';
using CheckerInfoSet = llvm::SetVector<const CheckerRegistry::CheckerInfo *>;
+namespace {
+/// Represents a request to include or exclude a checker or package from a
+/// specific analysis run.
+///
+/// \sa CheckerRegistry::initializeManager
+class CheckerOptInfo {
+ StringRef Name;
+ bool Enable;
+ bool Claimed;
+
+public:
+ CheckerOptInfo(StringRef name, bool enable)
+ : Name(name), Enable(enable), Claimed(false) { }
+
+ StringRef getName() const { return Name; }
+ bool isEnabled() const { return Enable; }
+ bool isDisabled() const { return !isEnabled(); }
+
+ bool isClaimed() const { return Claimed; }
+ bool isUnclaimed() const { return !isClaimed(); }
+ void claim() { Claimed = true; }
+};
+
+} // end of anonymous namespace
+
+static SmallVector<CheckerOptInfo, 8>
+getCheckerOptList(const AnalyzerOptions &opts) {
+ SmallVector<CheckerOptInfo, 8> checkerOpts;
+ for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {
+ const std::pair<std::string, bool> &opt = opts.CheckersControlList[i];
+ checkerOpts.push_back(CheckerOptInfo(opt.first, opt.second));
+ }
+ return checkerOpts;
+}
+
static bool checkerNameLT(const CheckerRegistry::CheckerInfo &a,
const CheckerRegistry::CheckerInfo &b) {
return a.FullName < b.FullName;
@@ -52,6 +86,7 @@ static bool isInPackage(const CheckerRegistry::CheckerInfo &checker,
return false;
}
+/// Collects the checkers for the supplied \p opt option into \p collected.
static void collectCheckers(const CheckerRegistry::CheckerInfoList &checkers,
const llvm::StringMap<size_t> &packageSizes,
CheckerOptInfo &opt, CheckerInfoSet &collected) {
@@ -101,13 +136,15 @@ void CheckerRegistry::addChecker(InitializationFunction fn, StringRef name,
}
void CheckerRegistry::initializeManager(CheckerManager &checkerMgr,
- SmallVectorImpl<CheckerOptInfo> &opts) const {
+ const AnalyzerOptions &Opts,
+ DiagnosticsEngine &diags) const {
// Sort checkers for efficient collection.
llvm::sort(Checkers, checkerNameLT);
+ llvm::SmallVector<CheckerOptInfo, 8> checkerOpts = getCheckerOptList(Opts);
// Collect checkers enabled by the options.
CheckerInfoSet enabledCheckers;
- for (auto &i : opts)
+ for (auto &i : checkerOpts)
collectCheckers(Checkers, Packages, i, enabledCheckers);
// Initialize the CheckerManager with all enabled checkers.
@@ -115,6 +152,15 @@ void CheckerRegistry::initializeManager(CheckerManager &checkerMgr,
checkerMgr.setCurrentCheckName(CheckName(i->FullName));
i->Initialize(checkerMgr);
}
+
+ for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) {
+ if (checkerOpts[i].isUnclaimed()) {
+ diags.Report(diag::err_unknown_analyzer_checker)
+ << checkerOpts[i].getName();
+ diags.Report(diag::note_suggest_disabling_all_checkers);
+ }
+
+ }
}
void CheckerRegistry::validateCheckerOptions(const AnalyzerOptions &opts,
@@ -176,13 +222,14 @@ void CheckerRegistry::printHelp(raw_ostream &out,
}
}
-void CheckerRegistry::printList(
- raw_ostream &out, SmallVectorImpl<CheckerOptInfo> &opts) const {
+void CheckerRegistry::printList(raw_ostream &out,
+ const AnalyzerOptions &opts) const {
llvm::sort(Checkers, checkerNameLT);
+ llvm::SmallVector<CheckerOptInfo, 8> checkerOpts = getCheckerOptList(opts);
// Collect checkers enabled by the options.
CheckerInfoSet enabledCheckers;
- for (auto &i : opts)
+ for (auto &i : checkerOpts)
collectCheckers(Checkers, Packages, i, enabledCheckers);
for (const auto *i : enabledCheckers)
OpenPOWER on IntegriCloud