2011-02-15 02:13:31 +08:00
|
|
|
//===--- CheckerRegistration.cpp - Registration for the Analyzer Checkers -===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-02-15 02:13:31 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Defines the registration function for the analyzer checkers.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-16 00:54:12 +08:00
|
|
|
#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
|
2011-02-15 02:13:31 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
[analyzer][NFC] Move CheckerRegistry from the Core directory to Frontend
ClangCheckerRegistry is a very non-obvious, poorly documented, weird concept.
It derives from CheckerRegistry, and is placed in lib/StaticAnalyzer/Frontend,
whereas it's base is located in lib/StaticAnalyzer/Core. It was, from what I can
imagine, used to circumvent the problem that the registry functions of the
checkers are located in the clangStaticAnalyzerCheckers library, but that
library depends on clangStaticAnalyzerCore. However, clangStaticAnalyzerFrontend
depends on both of those libraries.
One can make the observation however, that CheckerRegistry has no place in Core,
it isn't used there at all! The only place where it is used is Frontend, which
is where it ultimately belongs.
This move implies that since
include/clang/StaticAnalyzer/Checkers/ClangCheckers.h only contained a single function:
class CheckerRegistry;
void registerBuiltinCheckers(CheckerRegistry ®istry);
it had to re purposed, as CheckerRegistry is no longer available to
clangStaticAnalyzerCheckers. It was renamed to BuiltinCheckerRegistration.h,
which actually describes it a lot better -- it does not contain the registration
functions for checkers, but only those generated by the tblgen files.
Differential Revision: https://reviews.llvm.org/D54436
llvm-svn: 349275
2018-12-16 00:23:51 +08:00
|
|
|
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2011-02-25 08:09:51 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2014-03-09 19:36:40 +08:00
|
|
|
#include <memory>
|
2011-02-15 02:13:31 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace ento;
|
2011-08-17 12:56:03 +08:00
|
|
|
|
2018-06-27 22:56:12 +08:00
|
|
|
std::unique_ptr<CheckerManager> ento::createCheckerManager(
|
2018-08-07 07:09:07 +08:00
|
|
|
ASTContext &context,
|
|
|
|
AnalyzerOptions &opts,
|
2018-06-27 22:56:12 +08:00
|
|
|
ArrayRef<std::string> plugins,
|
|
|
|
ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns,
|
|
|
|
DiagnosticsEngine &diags) {
|
2018-08-07 07:09:07 +08:00
|
|
|
auto checkerMgr = llvm::make_unique<CheckerManager>(context, opts);
|
2011-02-15 02:13:31 +08:00
|
|
|
|
2019-01-27 01:27:40 +08:00
|
|
|
CheckerRegistry allCheckers(plugins, diags, opts, context.getLangOpts(),
|
|
|
|
checkerRegistrationFns);
|
2018-06-27 22:56:12 +08:00
|
|
|
|
2019-01-26 23:59:21 +08:00
|
|
|
allCheckers.initializeManager(*checkerMgr);
|
|
|
|
allCheckers.validateCheckerOptions();
|
2011-03-01 01:36:09 +08:00
|
|
|
checkerMgr->finishedCheckerRegistration();
|
|
|
|
|
2015-01-17 08:46:55 +08:00
|
|
|
return checkerMgr;
|
2011-02-15 02:13:31 +08:00
|
|
|
}
|
2011-02-25 08:09:51 +08:00
|
|
|
|
2018-12-16 02:11:49 +08:00
|
|
|
void ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins,
|
2019-01-26 23:59:21 +08:00
|
|
|
AnalyzerOptions &anopts,
|
2019-01-26 22:23:08 +08:00
|
|
|
DiagnosticsEngine &diags,
|
|
|
|
const LangOptions &langOpts) {
|
2011-08-17 05:24:21 +08:00
|
|
|
out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
|
|
|
|
out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";
|
2011-02-25 08:09:51 +08:00
|
|
|
|
2019-04-18 23:19:16 +08:00
|
|
|
CheckerRegistry(plugins, diags, anopts, langOpts)
|
|
|
|
.printCheckerWithDescList(out);
|
2011-02-25 08:09:51 +08:00
|
|
|
}
|
2016-08-08 21:41:04 +08:00
|
|
|
|
|
|
|
void ento::printEnabledCheckerList(raw_ostream &out,
|
|
|
|
ArrayRef<std::string> plugins,
|
2019-01-26 23:59:21 +08:00
|
|
|
AnalyzerOptions &anopts,
|
2019-01-26 22:23:08 +08:00
|
|
|
DiagnosticsEngine &diags,
|
|
|
|
const LangOptions &langOpts) {
|
2016-08-08 21:41:04 +08:00
|
|
|
out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
|
|
|
|
|
2019-04-18 23:19:16 +08:00
|
|
|
CheckerRegistry(plugins, diags, anopts, langOpts)
|
|
|
|
.printEnabledCheckerList(out);
|
2016-08-08 21:41:04 +08:00
|
|
|
}
|
2018-11-02 23:59:37 +08:00
|
|
|
|
2019-05-24 04:47:28 +08:00
|
|
|
void ento::printCheckerConfigList(raw_ostream &OS,
|
|
|
|
ArrayRef<std::string> plugins,
|
|
|
|
AnalyzerOptions &opts,
|
|
|
|
DiagnosticsEngine &diags,
|
|
|
|
const LangOptions &LangOpts) {
|
|
|
|
CheckerRegistry(plugins, diags, opts, LangOpts)
|
|
|
|
.printCheckerOptionList(OS);
|
|
|
|
}
|
|
|
|
|
2018-11-02 23:59:37 +08:00
|
|
|
void ento::printAnalyzerConfigList(raw_ostream &out) {
|
|
|
|
out << "OVERVIEW: Clang Static Analyzer -analyzer-config Option List\n\n";
|
2019-05-24 04:47:28 +08:00
|
|
|
out << "USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>\n\n";
|
|
|
|
out << " -analyzer-config OPTION1=VALUE, -analyzer-config "
|
|
|
|
"OPTION2=VALUE, ...\n\n";
|
2018-11-02 23:59:37 +08:00
|
|
|
out << "OPTIONS:\n\n";
|
|
|
|
|
|
|
|
using OptionAndDescriptionTy = std::pair<StringRef, std::string>;
|
|
|
|
OptionAndDescriptionTy PrintableOptions[] = {
|
|
|
|
#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \
|
|
|
|
{ \
|
|
|
|
CMDFLAG, \
|
|
|
|
llvm::Twine(llvm::Twine() + "(" + \
|
2018-11-03 03:48:56 +08:00
|
|
|
(StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \
|
|
|
|
") " DESC \
|
2018-11-02 23:59:37 +08:00
|
|
|
" (default: " #DEFAULT_VAL ")").str() \
|
|
|
|
},
|
|
|
|
|
|
|
|
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \
|
|
|
|
SHALLOW_VAL, DEEP_VAL) \
|
|
|
|
{ \
|
|
|
|
CMDFLAG, \
|
|
|
|
llvm::Twine(llvm::Twine() + "(" + \
|
2018-11-03 03:48:56 +08:00
|
|
|
(StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \
|
|
|
|
") " DESC \
|
2018-11-02 23:59:37 +08:00
|
|
|
" (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL \
|
|
|
|
" in deep mode)").str() \
|
|
|
|
},
|
|
|
|
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
|
|
|
|
#undef ANALYZER_OPTION
|
|
|
|
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
|
|
|
|
};
|
|
|
|
|
|
|
|
llvm::sort(PrintableOptions, [](const OptionAndDescriptionTy &LHS,
|
|
|
|
const OptionAndDescriptionTy &RHS) {
|
|
|
|
return LHS.first < RHS.first;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const auto &Pair : PrintableOptions) {
|
2019-05-24 04:47:28 +08:00
|
|
|
AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,
|
|
|
|
/*EntryWidth*/ 30,
|
|
|
|
/*MinLineWidth*/ 70);
|
|
|
|
out << "\n\n";
|
2018-11-02 23:59:37 +08:00
|
|
|
}
|
|
|
|
}
|