summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Frontend
diff options
context:
space:
mode:
authorKristof Umann <dkszelethus@gmail.com>2019-01-26 14:23:08 +0000
committerKristof Umann <dkszelethus@gmail.com>2019-01-26 14:23:08 +0000
commit058a7a450aac183d28451191333b3eb33814f62a (patch)
tree07c0f89710aea1f833e3b0dd15cabc0f79e93b32 /clang/lib/StaticAnalyzer/Frontend
parentdb07683d866bdd0c1d2b651066081b64f9563333 (diff)
downloadbcm5719-llvm-058a7a450aac183d28451191333b3eb33814f62a.tar.gz
bcm5719-llvm-058a7a450aac183d28451191333b3eb33814f62a.zip
[analyzer] Supply all checkers with a shouldRegister function
Introduce the boolean ento::shouldRegister##CHECKERNAME(const LangOptions &LO) function very similarly to ento::register##CHECKERNAME. This will force every checker to implement this function, but maybe it isn't that bad: I saw a lot of ObjC or C++ specific checkers that should probably not register themselves based on some LangOptions (mine too), but they do anyways. A big benefit of this is that all registry functions now register their checker, once it is called, registration is guaranteed. This patch is a part of a greater effort to reinvent checker registration, more info here: D54438#1315953 Differential Revision: https://reviews.llvm.org/D55424 llvm-svn: 352277
Diffstat (limited to 'clang/lib/StaticAnalyzer/Frontend')
-rw-r--r--clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp12
-rw-r--r--clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp24
2 files changed, 23 insertions, 13 deletions
diff --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
index 562d245a99b..b753ec36504 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
@@ -33,7 +33,7 @@ std::unique_ptr<CheckerManager> ento::createCheckerManager(
DiagnosticsEngine &diags) {
auto checkerMgr = llvm::make_unique<CheckerManager>(context, opts);
- CheckerRegistry allCheckers(plugins, diags);
+ CheckerRegistry allCheckers(plugins, diags, context.getLangOpts());
for (const auto &Fn : checkerRegistrationFns)
Fn(allCheckers);
@@ -46,20 +46,22 @@ std::unique_ptr<CheckerManager> ento::createCheckerManager(
}
void ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins,
- DiagnosticsEngine &diags) {
+ DiagnosticsEngine &diags,
+ const LangOptions &langOpts) {
out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";
- CheckerRegistry(plugins, diags).printHelp(out);
+ CheckerRegistry(plugins, diags, langOpts).printHelp(out);
}
void ento::printEnabledCheckerList(raw_ostream &out,
ArrayRef<std::string> plugins,
const AnalyzerOptions &opts,
- DiagnosticsEngine &diags) {
+ DiagnosticsEngine &diags,
+ const LangOptions &langOpts) {
out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
- CheckerRegistry(plugins, diags).printList(out, opts);
+ CheckerRegistry(plugins, diags, langOpts).printList(out, opts);
}
void ento::printAnalyzerConfigList(raw_ostream &out) {
diff --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
index 4d415e2cb5c..3ad5d81702a 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -39,10 +39,14 @@ static bool isCompatibleAPIVersion(const char *versionString) {
}
CheckerRegistry::CheckerRegistry(ArrayRef<std::string> plugins,
- DiagnosticsEngine &diags) : Diags(diags) {
+ DiagnosticsEngine &diags,
+ const LangOptions &LangOpts)
+ : Diags(diags), LangOpts(LangOpts) {
+
#define GET_CHECKERS
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI) \
- addChecker(register##CLASS, FULLNAME, HELPTEXT, DOC_URI);
+ addChecker(register##CLASS, shouldRegister##CLASS, FULLNAME, HELPTEXT, \
+ DOC_URI);
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
#undef CHECKER
#undef GET_CHECKERS
@@ -114,7 +118,8 @@ CheckerRegistry::CheckerInfoSet CheckerRegistry::getEnabledCheckers(
for (const std::pair<std::string, bool> &opt : Opts.CheckersControlList) {
// Use a binary search to find the possible start of the package.
- CheckerRegistry::CheckerInfo packageInfo(nullptr, opt.first, "", "");
+ CheckerRegistry::CheckerInfo
+ packageInfo(nullptr, nullptr, opt.first, "", "");
auto firstRelatedChecker =
std::lower_bound(Checkers.cbegin(), end, packageInfo, checkerNameLT);
@@ -137,18 +142,21 @@ CheckerRegistry::CheckerInfoSet CheckerRegistry::getEnabledCheckers(
// Step through all the checkers in the package.
for (auto lastRelatedChecker = firstRelatedChecker+size;
firstRelatedChecker != lastRelatedChecker; ++firstRelatedChecker)
- if (opt.second)
- enabledCheckers.insert(&*firstRelatedChecker);
- else
+ if (opt.second) {
+ if (firstRelatedChecker->ShouldRegister(LangOpts))
+ enabledCheckers.insert(&*firstRelatedChecker);
+ } else {
enabledCheckers.remove(&*firstRelatedChecker);
+ }
}
return enabledCheckers;
}
-void CheckerRegistry::addChecker(InitializationFunction Fn, StringRef Name,
+void CheckerRegistry::addChecker(InitializationFunction Rfn,
+ ShouldRegisterFunction Sfn, StringRef Name,
StringRef Desc, StringRef DocsUri) {
- Checkers.emplace_back(Fn, Name, Desc, DocsUri);
+ Checkers.emplace_back(Rfn, Sfn, Name, Desc, DocsUri);
// Record the presence of the checker in its packages.
StringRef packageName, leafName;
OpenPOWER on IntegriCloud