1 //===--- CheckerRegistration.cpp - Registration for the Analyzer Checkers -===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Defines the registration function for the analyzer checkers.
11 //===----------------------------------------------------------------------===//
13 #include "clang/StaticAnalyzer/Frontend/AnalyzerHelpFlags.h"
14 #include "clang/Basic/Diagnostic.h"
15 #include "clang/Frontend/CompilerInstance.h"
16 #include "clang/Frontend/FrontendDiagnostic.h"
17 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
18 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
19 #include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
20 #include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/Support/raw_ostream.h"
25 using namespace clang
;
28 void ento::printCheckerHelp(raw_ostream
&out
, CompilerInstance
&CI
) {
29 out
<< "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
30 out
<< "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";
32 auto CheckerMgr
= std::make_unique
<CheckerManager
>(
33 CI
.getAnalyzerOpts(), CI
.getLangOpts(), CI
.getDiagnostics(),
34 CI
.getFrontendOpts().Plugins
);
36 CheckerMgr
->getCheckerRegistryData().printCheckerWithDescList(
37 CI
.getAnalyzerOpts(), out
);
40 void ento::printEnabledCheckerList(raw_ostream
&out
, CompilerInstance
&CI
) {
41 out
<< "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
43 auto CheckerMgr
= std::make_unique
<CheckerManager
>(
44 CI
.getAnalyzerOpts(), CI
.getLangOpts(), CI
.getDiagnostics(),
45 CI
.getFrontendOpts().Plugins
);
47 CheckerMgr
->getCheckerRegistryData().printEnabledCheckerList(out
);
50 void ento::printCheckerConfigList(raw_ostream
&out
, CompilerInstance
&CI
) {
52 auto CheckerMgr
= std::make_unique
<CheckerManager
>(
53 CI
.getAnalyzerOpts(), CI
.getLangOpts(), CI
.getDiagnostics(),
54 CI
.getFrontendOpts().Plugins
);
56 CheckerMgr
->getCheckerRegistryData().printCheckerOptionList(
57 CI
.getAnalyzerOpts(), out
);
60 void ento::printAnalyzerConfigList(raw_ostream
&out
) {
61 // FIXME: This message sounds scary, should be scary, but incorrectly states
62 // that all configs are super dangerous. In reality, many of them should be
63 // accessible to the user. We should create a user-facing subset of config
64 // options under a different frontend flag.
66 OVERVIEW: Clang Static Analyzer -analyzer-config Option List
68 The following list of configurations are meant for development purposes only, as
69 some of the variables they define are set to result in the most optimal
70 analysis. Setting them to other values may drastically change how the analyzer
71 behaves, and may even result in instabilities, crashes!
73 USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>
74 -analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ...
78 using OptionAndDescriptionTy
= std::pair
<StringRef
, std::string
>;
79 OptionAndDescriptionTy PrintableOptions
[] = {
80 #define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \
83 llvm::Twine(llvm::Twine() + "(" + \
84 (StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \
86 " (default: " #DEFAULT_VAL ")").str() \
89 #define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \
90 SHALLOW_VAL, DEEP_VAL) \
93 llvm::Twine(llvm::Twine() + "(" + \
94 (StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \
96 " (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL \
97 " in deep mode)").str() \
99 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
100 #undef ANALYZER_OPTION
101 #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
104 llvm::sort(PrintableOptions
, llvm::less_first());
106 for (const auto &Pair
: PrintableOptions
) {
107 AnalyzerOptions::printFormattedEntry(out
, Pair
, /*InitialPad*/ 2,
109 /*MinLineWidth*/ 70);