blob: 3ee35b4aeea98a1c570695600cd29418af956d08 [file] [log] [blame]
Eugene Zelenko88f40cf2018-04-03 21:31:50 +00001//===- CheckerRegistry.cpp - Maintains all available checkers -------------===//
Jordy Rose59cce712011-08-16 21:24:21 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Jordy Rose59cce712011-08-16 21:24:21 +00006//
7//===----------------------------------------------------------------------===//
8
Kristof Umann76a21502018-12-15 16:23:51 +00009#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
Gabor Horvathfc4c4d42015-07-09 21:43:45 +000010#include "clang/Basic/Diagnostic.h"
Eugene Zelenko88f40cf2018-04-03 21:31:50 +000011#include "clang/Basic/LLVM.h"
Kristof Umannb0be2ab2018-12-15 18:11:49 +000012#include "clang/Frontend/FrontendDiagnostic.h"
13#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
Gabor Horvathfc4c4d42015-07-09 21:43:45 +000014#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
Kristof Umanna57d4ea2019-04-18 17:32:51 +000015#include "clang/StaticAnalyzer/Core/CheckerManager.h"
Eugene Zelenko88f40cf2018-04-03 21:31:50 +000016#include "llvm/ADT/STLExtras.h"
Anna Zaks30373152011-12-15 01:36:04 +000017#include "llvm/ADT/SetVector.h"
Eugene Zelenko88f40cf2018-04-03 21:31:50 +000018#include "llvm/ADT/StringMap.h"
19#include "llvm/ADT/StringRef.h"
Kristof Umannb0be2ab2018-12-15 18:11:49 +000020#include "llvm/Support/DynamicLibrary.h"
21#include "llvm/Support/Path.h"
Benjamin Kramer444a1302012-12-01 17:12:56 +000022#include "llvm/Support/raw_ostream.h"
Eugene Zelenko88f40cf2018-04-03 21:31:50 +000023#include <algorithm>
Jordy Rose59cce712011-08-16 21:24:21 +000024
25using namespace clang;
26using namespace ento;
Kristof Umannb0be2ab2018-12-15 18:11:49 +000027using llvm::sys::DynamicLibrary;
28
29using RegisterCheckersFn = void (*)(CheckerRegistry &);
30
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000031static bool isCompatibleAPIVersion(const char *VersionString) {
32 // If the version string is null, its not an analyzer plugin.
33 if (!VersionString)
Kristof Umannb0be2ab2018-12-15 18:11:49 +000034 return false;
35
36 // For now, none of the static analyzer API is considered stable.
37 // Versions must match exactly.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000038 return strcmp(VersionString, CLANG_ANALYZER_API_VERSION_STRING) == 0;
Kristof Umannb0be2ab2018-12-15 18:11:49 +000039}
40
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000041namespace {
Kristof Umanna57d4ea2019-04-18 17:32:51 +000042template <class T> struct FullNameLT {
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000043 bool operator()(const T &Lhs, const T &Rhs) {
44 return Lhs.FullName < Rhs.FullName;
45 }
46};
47
48using CheckerNameLT = FullNameLT<CheckerRegistry::CheckerInfo>;
49} // end of anonymous namespace
Kristof Umann3daa2452019-01-26 16:35:33 +000050
Kristof Umann640f7b52019-04-18 17:34:45 +000051template <class CheckerOrPackageInfoList>
52static
53 typename std::conditional<std::is_const<CheckerOrPackageInfoList>::value,
54 typename CheckerOrPackageInfoList::const_iterator,
55 typename CheckerOrPackageInfoList::iterator>::type
56 binaryFind(CheckerOrPackageInfoList &Collection, StringRef FullName) {
57
58 using CheckerOrPackage = typename CheckerOrPackageInfoList::value_type;
59 using CheckerOrPackageFullNameLT = FullNameLT<CheckerOrPackage>;
60
61 assert(std::is_sorted(Collection.begin(), Collection.end(),
62 CheckerOrPackageFullNameLT{}) &&
63 "In order to efficiently gather checkers/packages, this function "
64 "expects them to be already sorted!");
65
Fangrui Song92063352019-04-19 01:54:36 +000066 return llvm::lower_bound(Collection, CheckerOrPackage(FullName),
67 CheckerOrPackageFullNameLT{});
Kristof Umann640f7b52019-04-18 17:34:45 +000068}
69
Kristof Umann3daa2452019-01-26 16:35:33 +000070static constexpr char PackageSeparator = '.';
71
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000072static bool isInPackage(const CheckerRegistry::CheckerInfo &Checker,
73 StringRef PackageName) {
Kristof Umann3daa2452019-01-26 16:35:33 +000074 // Does the checker's full name have the package as a prefix?
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000075 if (!Checker.FullName.startswith(PackageName))
Kristof Umann3daa2452019-01-26 16:35:33 +000076 return false;
77
78 // Is the package actually just the name of a specific checker?
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000079 if (Checker.FullName.size() == PackageName.size())
Kristof Umann3daa2452019-01-26 16:35:33 +000080 return true;
81
82 // Is the checker in the package (or a subpackage)?
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000083 if (Checker.FullName[PackageName.size()] == PackageSeparator)
Kristof Umann3daa2452019-01-26 16:35:33 +000084 return true;
85
86 return false;
87}
88
89CheckerRegistry::CheckerInfoListRange
90CheckerRegistry::getMutableCheckersForCmdLineArg(StringRef CmdLineArg) {
Kristof Umann640f7b52019-04-18 17:34:45 +000091 auto It = binaryFind(Checkers, CmdLineArg);
Kristof Umann3daa2452019-01-26 16:35:33 +000092
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000093 if (!isInPackage(*It, CmdLineArg))
Kristof Umanna57d4ea2019-04-18 17:32:51 +000094 return {Checkers.end(), Checkers.end()};
Kristof Umann3daa2452019-01-26 16:35:33 +000095
96 // See how large the package is.
97 // If the package doesn't exist, assume the option refers to a single
98 // checker.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +000099 size_t Size = 1;
100 llvm::StringMap<size_t>::const_iterator PackageSize =
101 PackageSizes.find(CmdLineArg);
Kristof Umann3daa2452019-01-26 16:35:33 +0000102
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000103 if (PackageSize != PackageSizes.end())
104 Size = PackageSize->getValue();
Kristof Umann3daa2452019-01-26 16:35:33 +0000105
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000106 return {It, It + Size};
Kristof Umann3daa2452019-01-26 16:35:33 +0000107}
108
Kristof Umann98217ad2019-01-26 17:27:40 +0000109CheckerRegistry::CheckerRegistry(
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000110 ArrayRef<std::string> Plugins, DiagnosticsEngine &Diags,
111 AnalyzerOptions &AnOpts, const LangOptions &LangOpts,
112 ArrayRef<std::function<void(CheckerRegistry &)>> CheckerRegistrationFns)
113 : Diags(Diags), AnOpts(AnOpts), LangOpts(LangOpts) {
Kristof Umann058a7a42019-01-26 14:23:08 +0000114
Kristof Umann3daa2452019-01-26 16:35:33 +0000115 // Register builtin checkers.
Kristof Umannb0be2ab2018-12-15 18:11:49 +0000116#define GET_CHECKERS
Aaron Ballman2f234cb2018-12-20 20:20:20 +0000117#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI) \
Kristof Umann058a7a42019-01-26 14:23:08 +0000118 addChecker(register##CLASS, shouldRegister##CLASS, FULLNAME, HELPTEXT, \
119 DOC_URI);
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000120
Kristof Umannb0be2ab2018-12-15 18:11:49 +0000121#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
122#undef CHECKER
123#undef GET_CHECKERS
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000124#undef PACKAGE
125#undef GET_PACKAGES
Kristof Umannb0be2ab2018-12-15 18:11:49 +0000126
Kristof Umann3daa2452019-01-26 16:35:33 +0000127 // Register checkers from plugins.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000128 for (const std::string &Plugin : Plugins) {
Kristof Umannb0be2ab2018-12-15 18:11:49 +0000129 // Get access to the plugin.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000130 std::string ErrorMsg;
131 DynamicLibrary Lib =
132 DynamicLibrary::getPermanentLibrary(Plugin.c_str(), &ErrorMsg);
133 if (!Lib.isValid()) {
134 Diags.Report(diag::err_fe_unable_to_load_plugin) << Plugin << ErrorMsg;
Kristof Umannb0be2ab2018-12-15 18:11:49 +0000135 continue;
136 }
137
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000138 // See if its compatible with this build of clang.
139 const char *PluginAPIVersion = static_cast<const char *>(
140 Lib.getAddressOfSymbol("clang_analyzerAPIVersionString"));
141
142 if (!isCompatibleAPIVersion(PluginAPIVersion)) {
Kristof Umannb0be2ab2018-12-15 18:11:49 +0000143 Diags.Report(diag::warn_incompatible_analyzer_plugin_api)
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000144 << llvm::sys::path::filename(Plugin);
Kristof Umannb0be2ab2018-12-15 18:11:49 +0000145 Diags.Report(diag::note_incompatible_analyzer_plugin_api)
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000146 << CLANG_ANALYZER_API_VERSION_STRING << PluginAPIVersion;
Kristof Umannb0be2ab2018-12-15 18:11:49 +0000147 continue;
148 }
149
150 // Register its checkers.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000151 RegisterCheckersFn RegisterPluginCheckers =
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000152 reinterpret_cast<RegisterCheckersFn>(
153 Lib.getAddressOfSymbol("clang_registerCheckers"));
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000154 if (RegisterPluginCheckers)
155 RegisterPluginCheckers(*this);
Kristof Umannb0be2ab2018-12-15 18:11:49 +0000156 }
Jordy Rose59cce712011-08-16 21:24:21 +0000157
Kristof Umann98217ad2019-01-26 17:27:40 +0000158 // Register statically linked checkers, that aren't generated from the tblgen
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000159 // file, but rather passed their registry function as a parameter in
160 // checkerRegistrationFns.
Kristof Umann98217ad2019-01-26 17:27:40 +0000161
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000162 for (const auto &Fn : CheckerRegistrationFns)
Kristof Umann98217ad2019-01-26 17:27:40 +0000163 Fn(*this);
164
Kristof Umann3daa2452019-01-26 16:35:33 +0000165 // Sort checkers for efficient collection.
166 // FIXME: Alphabetical sort puts 'experimental' in the middle.
167 // Would it be better to name it '~experimental' or something else
168 // that's ASCIIbetically last?
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000169 llvm::sort(Checkers, CheckerNameLT{});
Kristof Umann45beaa02018-11-18 12:47:03 +0000170
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000171#define GET_CHECKER_DEPENDENCIES
172
173#define CHECKER_DEPENDENCY(FULLNAME, DEPENDENCY) \
174 addDependency(FULLNAME, DEPENDENCY);
175
176#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
177#undef CHECKER_DEPENDENCY
178#undef GET_CHECKER_DEPENDENCIES
179
Kristof Umann3daa2452019-01-26 16:35:33 +0000180 // Parse '-analyzer-checker' and '-analyzer-disable-checker' options from the
181 // command line.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000182 for (const std::pair<std::string, bool> &Opt : AnOpts.CheckersControlList) {
183 CheckerInfoListRange CheckerForCmdLineArg =
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000184 getMutableCheckersForCmdLineArg(Opt.first);
Jordy Rose59cce712011-08-16 21:24:21 +0000185
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000186 if (CheckerForCmdLineArg.begin() == CheckerForCmdLineArg.end()) {
187 Diags.Report(diag::err_unknown_analyzer_checker) << Opt.first;
Kristof Umann3daa2452019-01-26 16:35:33 +0000188 Diags.Report(diag::note_suggest_disabling_all_checkers);
189 }
Jordy Rose59cce712011-08-16 21:24:21 +0000190
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000191 for (CheckerInfo &checker : CheckerForCmdLineArg) {
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000192 checker.State = Opt.second ? StateFromCmdLine::State_Enabled
193 : StateFromCmdLine::State_Disabled;
Kristof Umann3daa2452019-01-26 16:35:33 +0000194 }
195 }
Jordy Rose59cce712011-08-16 21:24:21 +0000196}
197
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000198/// Collects dependencies in \p ret, returns false on failure.
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000199static bool
200collectDependenciesImpl(const CheckerRegistry::ConstCheckerInfoList &Deps,
201 const LangOptions &LO,
202 CheckerRegistry::CheckerInfoSet &Ret);
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000203
204/// Collects dependenies in \p enabledCheckers. Return None on failure.
205LLVM_NODISCARD
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000206static llvm::Optional<CheckerRegistry::CheckerInfoSet>
207collectDependencies(const CheckerRegistry::CheckerInfo &checker,
208 const LangOptions &LO) {
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000209
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000210 CheckerRegistry::CheckerInfoSet Ret;
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000211 // Add dependencies to the enabled checkers only if all of them can be
212 // enabled.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000213 if (!collectDependenciesImpl(checker.Dependencies, LO, Ret))
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000214 return None;
215
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000216 return Ret;
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000217}
218
Kristof Umanna57d4ea2019-04-18 17:32:51 +0000219static bool
220collectDependenciesImpl(const CheckerRegistry::ConstCheckerInfoList &Deps,
221 const LangOptions &LO,
222 CheckerRegistry::CheckerInfoSet &Ret) {
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000223
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000224 for (const CheckerRegistry::CheckerInfo *Dependency : Deps) {
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000225
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000226 if (Dependency->isDisabled(LO))
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000227 return false;
228
229 // Collect dependencies recursively.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000230 if (!collectDependenciesImpl(Dependency->Dependencies, LO, Ret))
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000231 return false;
232
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000233 Ret.insert(Dependency);
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000234 }
235
236 return true;
237}
238
Kristof Umanndd9c86e2019-01-26 15:59:21 +0000239CheckerRegistry::CheckerInfoSet CheckerRegistry::getEnabledCheckers() const {
Jordy Rose59cce712011-08-16 21:24:21 +0000240
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000241 CheckerInfoSet EnabledCheckers;
Jordy Rose59cce712011-08-16 21:24:21 +0000242
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000243 for (const CheckerInfo &Checker : Checkers) {
244 if (!Checker.isEnabled(LangOpts))
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000245 continue;
246
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000247 // Recursively enable its dependencies.
248 llvm::Optional<CheckerInfoSet> Deps =
249 collectDependencies(Checker, LangOpts);
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000250
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000251 if (!Deps) {
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000252 // If we failed to enable any of the dependencies, don't enable this
253 // checker.
254 continue;
255 }
256
257 // Note that set_union also preserves the order of insertion.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000258 EnabledCheckers.set_union(*Deps);
Kristof Umann8fd74eb2019-01-26 20:06:54 +0000259
260 // Enable the checker.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000261 EnabledCheckers.insert(&Checker);
Kristof Umannf282d272018-12-15 15:44:05 +0000262 }
263
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000264 return EnabledCheckers;
Jordy Rose59cce712011-08-16 21:24:21 +0000265}
266
Kristof Umann058a7a42019-01-26 14:23:08 +0000267void CheckerRegistry::addChecker(InitializationFunction Rfn,
268 ShouldRegisterFunction Sfn, StringRef Name,
Aaron Ballman2f234cb2018-12-20 20:20:20 +0000269 StringRef Desc, StringRef DocsUri) {
Kristof Umann058a7a42019-01-26 14:23:08 +0000270 Checkers.emplace_back(Rfn, Sfn, Name, Desc, DocsUri);
Jordy Rose59cce712011-08-16 21:24:21 +0000271
272 // Record the presence of the checker in its packages.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000273 StringRef PackageName, LeafName;
274 std::tie(PackageName, LeafName) = Name.rsplit(PackageSeparator);
275 while (!LeafName.empty()) {
276 PackageSizes[PackageName] += 1;
277 std::tie(PackageName, LeafName) = PackageName.rsplit(PackageSeparator);
Jordy Rose59cce712011-08-16 21:24:21 +0000278 }
279}
280
Kristof Umann640f7b52019-04-18 17:34:45 +0000281void CheckerRegistry::addDependency(StringRef FullName, StringRef Dependency) {
282 auto CheckerIt = binaryFind(Checkers, FullName);
283 assert(CheckerIt != Checkers.end() && CheckerIt->FullName == FullName &&
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000284 "Failed to find the checker while attempting to set up its "
285 "dependencies!");
286
Kristof Umann640f7b52019-04-18 17:34:45 +0000287 auto DependencyIt = binaryFind(Checkers, Dependency);
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000288 assert(DependencyIt != Checkers.end() &&
Kristof Umann640f7b52019-04-18 17:34:45 +0000289 DependencyIt->FullName == Dependency &&
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000290 "Failed to find the dependency of a checker!");
291
Kristof Umann640f7b52019-04-18 17:34:45 +0000292 CheckerIt->Dependencies.emplace_back(&*DependencyIt);
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000293}
294
295void CheckerRegistry::initializeManager(CheckerManager &CheckerMgr) const {
Jordy Rose59cce712011-08-16 21:24:21 +0000296 // Collect checkers enabled by the options.
Kristof Umanndd9c86e2019-01-26 15:59:21 +0000297 CheckerInfoSet enabledCheckers = getEnabledCheckers();
Jordy Rose59cce712011-08-16 21:24:21 +0000298
299 // Initialize the CheckerManager with all enabled checkers.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000300 for (const auto *Checker : enabledCheckers) {
301 CheckerMgr.setCurrentCheckName(CheckName(Checker->FullName));
302 Checker->Initialize(CheckerMgr);
Jordy Rose59cce712011-08-16 21:24:21 +0000303 }
304}
305
Kristof Umanndd9c86e2019-01-26 15:59:21 +0000306void CheckerRegistry::validateCheckerOptions() const {
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000307 for (const auto &Config : AnOpts.Config) {
308 size_t Pos = Config.getKey().find(':');
309 if (Pos == StringRef::npos)
Gabor Horvathfc4c4d42015-07-09 21:43:45 +0000310 continue;
311
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000312 bool HasChecker = false;
313 StringRef CheckerName = Config.getKey().substr(0, Pos);
314 for (const auto &Checker : Checkers) {
315 if (Checker.FullName.startswith(CheckerName) &&
316 (Checker.FullName.size() == Pos || Checker.FullName[Pos] == '.')) {
317 HasChecker = true;
Gabor Horvathfc4c4d42015-07-09 21:43:45 +0000318 break;
319 }
320 }
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000321 if (!HasChecker)
322 Diags.Report(diag::err_unknown_analyzer_checker) << CheckerName;
Gabor Horvathfc4c4d42015-07-09 21:43:45 +0000323 }
324}
325
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000326void CheckerRegistry::printCheckerWithDescList(raw_ostream &Out,
327 size_t MaxNameChars) const {
Jordy Rose59cce712011-08-16 21:24:21 +0000328 // FIXME: Print available packages.
329
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000330 Out << "CHECKERS:\n";
Jordy Rose59cce712011-08-16 21:24:21 +0000331
332 // Find the maximum option length.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000333 size_t OptionFieldWidth = 0;
334 for (const auto &Checker : Checkers) {
Jordy Rose59cce712011-08-16 21:24:21 +0000335 // Limit the amount of padding we are willing to give up for alignment.
336 // Package.Name Description [Hidden]
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000337 size_t NameLength = Checker.FullName.size();
338 if (NameLength <= MaxNameChars)
339 OptionFieldWidth = std::max(OptionFieldWidth, NameLength);
Jordy Rose59cce712011-08-16 21:24:21 +0000340 }
341
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000342 const size_t InitialPad = 2;
343 for (const auto &Checker : Checkers) {
344 Out.indent(InitialPad) << Checker.FullName;
Jordy Rose59cce712011-08-16 21:24:21 +0000345
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000346 int Pad = OptionFieldWidth - Checker.FullName.size();
Jordy Rose59cce712011-08-16 21:24:21 +0000347
348 // Break on long option names.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000349 if (Pad < 0) {
350 Out << '\n';
351 Pad = OptionFieldWidth + InitialPad;
Jordy Rose59cce712011-08-16 21:24:21 +0000352 }
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000353 Out.indent(Pad + 2) << Checker.Desc;
Jordy Rose59cce712011-08-16 21:24:21 +0000354
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000355 Out << '\n';
Jordy Rose59cce712011-08-16 21:24:21 +0000356 }
357}
Gabor Horvathc4309902016-08-08 13:41:04 +0000358
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000359void CheckerRegistry::printEnabledCheckerList(raw_ostream &Out) const {
Gabor Horvathc4309902016-08-08 13:41:04 +0000360 // Collect checkers enabled by the options.
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000361 CheckerInfoSet EnabledCheckers = getEnabledCheckers();
Gabor Horvathc4309902016-08-08 13:41:04 +0000362
Kristof Umannb9bc7ec2019-04-18 15:19:16 +0000363 for (const auto *i : EnabledCheckers)
364 Out << i->FullName << '\n';
Gabor Horvathc4309902016-08-08 13:41:04 +0000365}