[analyzer][NFC] Clang-format CheckerRegistry
Differential Revision: https://reviews.llvm.org/D59458 llvm-svn: 358694
This commit is contained in:
parent
f2293a95de
commit
a57d4ea33f
|
@ -81,8 +81,7 @@ namespace ento {
|
||||||
/// "core.builtin", or the full name "core.builtin.NoReturnFunctionChecker".
|
/// "core.builtin", or the full name "core.builtin.NoReturnFunctionChecker".
|
||||||
class CheckerRegistry {
|
class CheckerRegistry {
|
||||||
public:
|
public:
|
||||||
CheckerRegistry(
|
CheckerRegistry(ArrayRef<std::string> plugins, DiagnosticsEngine &diags,
|
||||||
ArrayRef<std::string> plugins, DiagnosticsEngine &diags,
|
|
||||||
AnalyzerOptions &AnOpts, const LangOptions &LangOpts,
|
AnalyzerOptions &AnOpts, const LangOptions &LangOpts,
|
||||||
ArrayRef<std::function<void(CheckerRegistry &)>>
|
ArrayRef<std::function<void(CheckerRegistry &)>>
|
||||||
checkerRegistrationFns = {});
|
checkerRegistrationFns = {});
|
||||||
|
@ -135,14 +134,11 @@ public:
|
||||||
using StateFromCmdLine = CheckerInfo::StateFromCmdLine;
|
using StateFromCmdLine = CheckerInfo::StateFromCmdLine;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T>
|
template <typename T> static void initializeManager(CheckerManager &mgr) {
|
||||||
static void initializeManager(CheckerManager &mgr) {
|
|
||||||
mgr.registerChecker<T>();
|
mgr.registerChecker<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> static bool returnTrue(const LangOptions &LO) {
|
||||||
template <typename T>
|
|
||||||
static bool returnTrue(const LangOptions &LO) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
#include "clang/Basic/LLVM.h"
|
#include "clang/Basic/LLVM.h"
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
#include "clang/Frontend/FrontendDiagnostic.h"
|
||||||
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
|
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
|
||||||
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
|
||||||
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
|
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
|
||||||
|
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/ADT/SetVector.h"
|
#include "llvm/ADT/SetVector.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
|
@ -39,8 +39,7 @@ static bool isCompatibleAPIVersion(const char *VersionString) {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template <class T>
|
template <class T> struct FullNameLT {
|
||||||
struct FullNameLT {
|
|
||||||
bool operator()(const T &Lhs, const T &Rhs) {
|
bool operator()(const T &Lhs, const T &Rhs) {
|
||||||
return Lhs.FullName < Rhs.FullName;
|
return Lhs.FullName < Rhs.FullName;
|
||||||
}
|
}
|
||||||
|
@ -76,13 +75,13 @@ CheckerRegistry::getMutableCheckersForCmdLineArg(StringRef CmdLineArg) {
|
||||||
"to be already sorted!");
|
"to be already sorted!");
|
||||||
|
|
||||||
// Use a binary search to find the possible start of the package.
|
// Use a binary search to find the possible start of the package.
|
||||||
CheckerRegistry::CheckerInfo
|
CheckerRegistry::CheckerInfo PackageInfo(nullptr, nullptr, CmdLineArg, "",
|
||||||
PackageInfo(nullptr, nullptr, CmdLineArg, "", "");
|
"");
|
||||||
auto It = std::lower_bound(Checkers.begin(), Checkers.end(),
|
auto It = std::lower_bound(Checkers.begin(), Checkers.end(), PackageInfo,
|
||||||
PackageInfo, CheckerNameLT{});
|
CheckerNameLT{});
|
||||||
|
|
||||||
if (!isInPackage(*It, CmdLineArg))
|
if (!isInPackage(*It, CmdLineArg))
|
||||||
return { Checkers.end(), Checkers.end() };
|
return {Checkers.end(), Checkers.end()};
|
||||||
|
|
||||||
// See how large the package is.
|
// See how large the package is.
|
||||||
// If the package doesn't exist, assume the option refers to a single
|
// If the package doesn't exist, assume the option refers to a single
|
||||||
|
@ -94,14 +93,13 @@ CheckerRegistry::getMutableCheckersForCmdLineArg(StringRef CmdLineArg) {
|
||||||
if (PackageSize != PackageSizes.end())
|
if (PackageSize != PackageSizes.end())
|
||||||
Size = PackageSize->getValue();
|
Size = PackageSize->getValue();
|
||||||
|
|
||||||
return { It, It + Size };
|
return {It, It + Size};
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckerRegistry::CheckerRegistry(
|
CheckerRegistry::CheckerRegistry(
|
||||||
ArrayRef<std::string> Plugins, DiagnosticsEngine &Diags,
|
ArrayRef<std::string> Plugins, DiagnosticsEngine &Diags,
|
||||||
AnalyzerOptions &AnOpts, const LangOptions &LangOpts,
|
AnalyzerOptions &AnOpts, const LangOptions &LangOpts,
|
||||||
ArrayRef<std::function<void(CheckerRegistry &)>>
|
ArrayRef<std::function<void(CheckerRegistry &)>> CheckerRegistrationFns)
|
||||||
CheckerRegistrationFns)
|
|
||||||
: Diags(Diags), AnOpts(AnOpts), LangOpts(LangOpts) {
|
: Diags(Diags), AnOpts(AnOpts), LangOpts(LangOpts) {
|
||||||
|
|
||||||
// Register builtin checkers.
|
// Register builtin checkers.
|
||||||
|
@ -135,15 +133,14 @@ CheckerRegistry::CheckerRegistry(
|
||||||
Diags.Report(diag::warn_incompatible_analyzer_plugin_api)
|
Diags.Report(diag::warn_incompatible_analyzer_plugin_api)
|
||||||
<< llvm::sys::path::filename(Plugin);
|
<< llvm::sys::path::filename(Plugin);
|
||||||
Diags.Report(diag::note_incompatible_analyzer_plugin_api)
|
Diags.Report(diag::note_incompatible_analyzer_plugin_api)
|
||||||
<< CLANG_ANALYZER_API_VERSION_STRING
|
<< CLANG_ANALYZER_API_VERSION_STRING << PluginAPIVersion;
|
||||||
<< PluginAPIVersion;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register its checkers.
|
// Register its checkers.
|
||||||
RegisterCheckersFn RegisterPluginCheckers =
|
RegisterCheckersFn RegisterPluginCheckers =
|
||||||
reinterpret_cast<RegisterCheckersFn>(Lib.getAddressOfSymbol(
|
reinterpret_cast<RegisterCheckersFn>(
|
||||||
"clang_registerCheckers"));
|
Lib.getAddressOfSymbol("clang_registerCheckers"));
|
||||||
if (RegisterPluginCheckers)
|
if (RegisterPluginCheckers)
|
||||||
RegisterPluginCheckers(*this);
|
RegisterPluginCheckers(*this);
|
||||||
}
|
}
|
||||||
|
@ -182,22 +179,23 @@ CheckerRegistry::CheckerRegistry(
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CheckerInfo &checker : CheckerForCmdLineArg) {
|
for (CheckerInfo &checker : CheckerForCmdLineArg) {
|
||||||
checker.State = Opt.second ? StateFromCmdLine::State_Enabled :
|
checker.State = Opt.second ? StateFromCmdLine::State_Enabled
|
||||||
StateFromCmdLine::State_Disabled;
|
: StateFromCmdLine::State_Disabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collects dependencies in \p ret, returns false on failure.
|
/// Collects dependencies in \p ret, returns false on failure.
|
||||||
static bool collectDependenciesImpl(
|
static bool
|
||||||
const CheckerRegistry::ConstCheckerInfoList &Deps,
|
collectDependenciesImpl(const CheckerRegistry::ConstCheckerInfoList &Deps,
|
||||||
const LangOptions &LO,
|
const LangOptions &LO,
|
||||||
CheckerRegistry::CheckerInfoSet &Ret);
|
CheckerRegistry::CheckerInfoSet &Ret);
|
||||||
|
|
||||||
/// Collects dependenies in \p enabledCheckers. Return None on failure.
|
/// Collects dependenies in \p enabledCheckers. Return None on failure.
|
||||||
LLVM_NODISCARD
|
LLVM_NODISCARD
|
||||||
static llvm::Optional<CheckerRegistry::CheckerInfoSet> collectDependencies(
|
static llvm::Optional<CheckerRegistry::CheckerInfoSet>
|
||||||
const CheckerRegistry::CheckerInfo &checker, const LangOptions &LO) {
|
collectDependencies(const CheckerRegistry::CheckerInfo &checker,
|
||||||
|
const LangOptions &LO) {
|
||||||
|
|
||||||
CheckerRegistry::CheckerInfoSet Ret;
|
CheckerRegistry::CheckerInfoSet Ret;
|
||||||
// Add dependencies to the enabled checkers only if all of them can be
|
// Add dependencies to the enabled checkers only if all of them can be
|
||||||
|
@ -208,8 +206,8 @@ static llvm::Optional<CheckerRegistry::CheckerInfoSet> collectDependencies(
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool collectDependenciesImpl(
|
static bool
|
||||||
const CheckerRegistry::ConstCheckerInfoList &Deps,
|
collectDependenciesImpl(const CheckerRegistry::ConstCheckerInfoList &Deps,
|
||||||
const LangOptions &LO,
|
const LangOptions &LO,
|
||||||
CheckerRegistry::CheckerInfoSet &Ret) {
|
CheckerRegistry::CheckerInfoSet &Ret) {
|
||||||
|
|
||||||
|
@ -271,10 +269,10 @@ void CheckerRegistry::addChecker(InitializationFunction Rfn,
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckerRegistry::addDependency(StringRef FullName, StringRef dependency) {
|
void CheckerRegistry::addDependency(StringRef FullName, StringRef dependency) {
|
||||||
auto CheckerThatNeedsDeps =
|
auto CheckerThatNeedsDeps = [&FullName](const CheckerInfo &Chk) {
|
||||||
[&FullName](const CheckerInfo &Chk) { return Chk.FullName == FullName; };
|
return Chk.FullName == FullName;
|
||||||
auto Dependency =
|
};
|
||||||
[&dependency](const CheckerInfo &Chk) {
|
auto Dependency = [&dependency](const CheckerInfo &Chk) {
|
||||||
return Chk.FullName == dependency;
|
return Chk.FullName == dependency;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue