1 //===- CheckerRegistry.cpp - Maintains all available checkers -------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
10 #include "clang/Basic/Diagnostic.h"
11 #include "clang/Basic/LLVM.h"
12 #include "clang/Driver/DriverDiagnostic.h"
13 #include "clang/Frontend/FrontendDiagnostic.h"
14 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
15 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
16 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SetVector.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/DynamicLibrary.h"
22 #include "llvm/Support/Path.h"
23 #include "llvm/Support/raw_ostream.h"
24 #include <algorithm>
25 
26 using namespace clang;
27 using namespace ento;
28 using llvm::sys::DynamicLibrary;
29 
30 using RegisterCheckersFn = void (*)(CheckerRegistry &);
31 
32 static bool isCompatibleAPIVersion(const char *VersionString) {
33   // If the version string is null, its not an analyzer plugin.
34   if (!VersionString)
35     return false;
36 
37   // For now, none of the static analyzer API is considered stable.
38   // Versions must match exactly.
39   return strcmp(VersionString, CLANG_ANALYZER_API_VERSION_STRING) == 0;
40 }
41 
42 namespace {
43 template <class T> struct FullNameLT {
44   bool operator()(const T &Lhs, const T &Rhs) {
45     return Lhs.FullName < Rhs.FullName;
46   }
47 };
48 
49 using PackageNameLT = FullNameLT<CheckerRegistry::PackageInfo>;
50 using CheckerNameLT = FullNameLT<CheckerRegistry::CheckerInfo>;
51 } // end of anonymous namespace
52 
53 template <class CheckerOrPackageInfoList>
54 static std::conditional_t<std::is_const<CheckerOrPackageInfoList>::value,
55                           typename CheckerOrPackageInfoList::const_iterator,
56                           typename CheckerOrPackageInfoList::iterator>
57 binaryFind(CheckerOrPackageInfoList &Collection, StringRef FullName) {
58 
59   using CheckerOrPackage = typename CheckerOrPackageInfoList::value_type;
60   using CheckerOrPackageFullNameLT = FullNameLT<CheckerOrPackage>;
61 
62   assert(llvm::is_sorted(Collection, CheckerOrPackageFullNameLT{}) &&
63          "In order to efficiently gather checkers/packages, this function "
64          "expects them to be already sorted!");
65 
66   return llvm::lower_bound(Collection, CheckerOrPackage(FullName),
67                            CheckerOrPackageFullNameLT{});
68 }
69 
70 static constexpr char PackageSeparator = '.';
71 
72 static bool isInPackage(const CheckerRegistry::CheckerInfo &Checker,
73                         StringRef PackageName) {
74   // Does the checker's full name have the package as a prefix?
75   if (!Checker.FullName.startswith(PackageName))
76     return false;
77 
78   // Is the package actually just the name of a specific checker?
79   if (Checker.FullName.size() == PackageName.size())
80     return true;
81 
82   // Is the checker in the package (or a subpackage)?
83   if (Checker.FullName[PackageName.size()] == PackageSeparator)
84     return true;
85 
86   return false;
87 }
88 
89 CheckerRegistry::CheckerInfoListRange
90 CheckerRegistry::getMutableCheckersForCmdLineArg(StringRef CmdLineArg) {
91   auto It = binaryFind(Checkers, CmdLineArg);
92 
93   if (!isInPackage(*It, CmdLineArg))
94     return {Checkers.end(), Checkers.end()};
95 
96   // See how large the package is.
97   // If the package doesn't exist, assume the option refers to a single
98   // checker.
99   size_t Size = 1;
100   llvm::StringMap<size_t>::const_iterator PackageSize =
101       PackageSizes.find(CmdLineArg);
102 
103   if (PackageSize != PackageSizes.end())
104     Size = PackageSize->getValue();
105 
106   return {It, It + Size};
107 }
108 
109 CheckerRegistry::CheckerRegistry(
110     ArrayRef<std::string> Plugins, DiagnosticsEngine &Diags,
111     AnalyzerOptions &AnOpts,
112     ArrayRef<std::function<void(CheckerRegistry &)>> CheckerRegistrationFns)
113     : Diags(Diags), AnOpts(AnOpts) {
114 
115   // Register builtin checkers.
116 #define GET_CHECKERS
117 #define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN)                 \
118   addChecker(register##CLASS, shouldRegister##CLASS, FULLNAME, HELPTEXT,       \
119              DOC_URI, IS_HIDDEN);
120 
121 #define GET_PACKAGES
122 #define PACKAGE(FULLNAME) addPackage(FULLNAME);
123 
124 #include "clang/StaticAnalyzer/Checkers/Checkers.inc"
125 #undef CHECKER
126 #undef GET_CHECKERS
127 #undef PACKAGE
128 #undef GET_PACKAGES
129 
130   // Register checkers from plugins.
131   for (const std::string &Plugin : Plugins) {
132     // Get access to the plugin.
133     std::string ErrorMsg;
134     DynamicLibrary Lib =
135         DynamicLibrary::getPermanentLibrary(Plugin.c_str(), &ErrorMsg);
136     if (!Lib.isValid()) {
137       Diags.Report(diag::err_fe_unable_to_load_plugin) << Plugin << ErrorMsg;
138       continue;
139     }
140 
141     // See if its compatible with this build of clang.
142     const char *PluginAPIVersion = static_cast<const char *>(
143         Lib.getAddressOfSymbol("clang_analyzerAPIVersionString"));
144 
145     if (!isCompatibleAPIVersion(PluginAPIVersion)) {
146       Diags.Report(diag::warn_incompatible_analyzer_plugin_api)
147           << llvm::sys::path::filename(Plugin);
148       Diags.Report(diag::note_incompatible_analyzer_plugin_api)
149           << CLANG_ANALYZER_API_VERSION_STRING << PluginAPIVersion;
150       continue;
151     }
152 
153     // Register its checkers.
154     RegisterCheckersFn RegisterPluginCheckers =
155         reinterpret_cast<RegisterCheckersFn>(
156             Lib.getAddressOfSymbol("clang_registerCheckers"));
157     if (RegisterPluginCheckers)
158       RegisterPluginCheckers(*this);
159   }
160 
161   // Register statically linked checkers, that aren't generated from the tblgen
162   // file, but rather passed their registry function as a parameter in
163   // checkerRegistrationFns.
164 
165   for (const auto &Fn : CheckerRegistrationFns)
166     Fn(*this);
167 
168   // Sort checkers for efficient collection.
169   // FIXME: Alphabetical sort puts 'experimental' in the middle.
170   // Would it be better to name it '~experimental' or something else
171   // that's ASCIIbetically last?
172   llvm::sort(Packages, PackageNameLT{});
173   llvm::sort(Checkers, CheckerNameLT{});
174 
175 #define GET_CHECKER_DEPENDENCIES
176 
177 #define CHECKER_DEPENDENCY(FULLNAME, DEPENDENCY)                               \
178   addDependency(FULLNAME, DEPENDENCY);
179 
180 #define GET_CHECKER_OPTIONS
181 #define CHECKER_OPTION(TYPE, FULLNAME, CMDFLAG, DESC, DEFAULT_VAL,             \
182                        DEVELOPMENT_STATUS, IS_HIDDEN)                          \
183   addCheckerOption(TYPE, FULLNAME, CMDFLAG, DEFAULT_VAL, DESC,                 \
184                    DEVELOPMENT_STATUS, IS_HIDDEN);
185 
186 #define GET_PACKAGE_OPTIONS
187 #define PACKAGE_OPTION(TYPE, FULLNAME, CMDFLAG, DESC, DEFAULT_VAL,             \
188                        DEVELOPMENT_STATUS, IS_HIDDEN)                          \
189   addPackageOption(TYPE, FULLNAME, CMDFLAG, DEFAULT_VAL, DESC,                 \
190                    DEVELOPMENT_STATUS, IS_HIDDEN);
191 
192 #include "clang/StaticAnalyzer/Checkers/Checkers.inc"
193 #undef CHECKER_DEPENDENCY
194 #undef GET_CHECKER_DEPENDENCIES
195 #undef CHECKER_OPTION
196 #undef GET_CHECKER_OPTIONS
197 #undef PACKAGE_OPTION
198 #undef GET_PACKAGE_OPTIONS
199 
200   resolveDependencies();
201   resolveCheckerAndPackageOptions();
202 
203   // Parse '-analyzer-checker' and '-analyzer-disable-checker' options from the
204   // command line.
205   for (const std::pair<std::string, bool> &Opt : AnOpts.CheckersAndPackages) {
206     CheckerInfoListRange CheckerForCmdLineArg =
207         getMutableCheckersForCmdLineArg(Opt.first);
208 
209     if (CheckerForCmdLineArg.begin() == CheckerForCmdLineArg.end()) {
210       Diags.Report(diag::err_unknown_analyzer_checker_or_package) << Opt.first;
211       Diags.Report(diag::note_suggest_disabling_all_checkers);
212     }
213 
214     for (CheckerInfo &checker : CheckerForCmdLineArg) {
215       checker.State = Opt.second ? StateFromCmdLine::State_Enabled
216                                  : StateFromCmdLine::State_Disabled;
217     }
218   }
219   validateCheckerOptions();
220 }
221 
222 /// Collects dependenies in \p enabledCheckers. Return None on failure.
223 LLVM_NODISCARD
224 static llvm::Optional<CheckerRegistry::CheckerInfoSet>
225 collectDependencies(const CheckerRegistry::CheckerInfo &checker,
226                     const CheckerManager &Mgr);
227 
228 void CheckerRegistry::initializeRegistry(const CheckerManager &Mgr) {
229   for (const CheckerInfo &Checker : Checkers) {
230     if (!Checker.isEnabled(Mgr))
231       continue;
232 
233     // Recursively enable its dependencies.
234     llvm::Optional<CheckerInfoSet> Deps = collectDependencies(Checker, Mgr);
235 
236     if (!Deps) {
237       // If we failed to enable any of the dependencies, don't enable this
238       // checker.
239       continue;
240     }
241 
242     // Note that set_union also preserves the order of insertion.
243     EnabledCheckers.set_union(*Deps);
244 
245     // Enable the checker.
246     EnabledCheckers.insert(&Checker);
247   }
248 }
249 
250 /// Collects dependencies in \p ret, returns false on failure.
251 static bool
252 collectDependenciesImpl(const CheckerRegistry::ConstCheckerInfoList &Deps,
253                         const CheckerManager &Mgr,
254                         CheckerRegistry::CheckerInfoSet &Ret);
255 
256 /// Collects dependenies in \p enabledCheckers. Return None on failure.
257 LLVM_NODISCARD
258 static llvm::Optional<CheckerRegistry::CheckerInfoSet>
259 collectDependencies(const CheckerRegistry::CheckerInfo &checker,
260                     const CheckerManager &Mgr) {
261 
262   CheckerRegistry::CheckerInfoSet Ret;
263   // Add dependencies to the enabled checkers only if all of them can be
264   // enabled.
265   if (!collectDependenciesImpl(checker.Dependencies, Mgr, Ret))
266     return None;
267 
268   return Ret;
269 }
270 
271 static bool
272 collectDependenciesImpl(const CheckerRegistry::ConstCheckerInfoList &Deps,
273                         const CheckerManager &Mgr,
274                         CheckerRegistry::CheckerInfoSet &Ret) {
275 
276   for (const CheckerRegistry::CheckerInfo *Dependency : Deps) {
277 
278     if (Dependency->isDisabled(Mgr))
279       return false;
280 
281     // Collect dependencies recursively.
282     if (!collectDependenciesImpl(Dependency->Dependencies, Mgr, Ret))
283       return false;
284 
285     Ret.insert(Dependency);
286   }
287 
288   return true;
289 }
290 
291 void CheckerRegistry::resolveDependencies() {
292   for (const std::pair<StringRef, StringRef> &Entry : Dependencies) {
293     auto CheckerIt = binaryFind(Checkers, Entry.first);
294     assert(CheckerIt != Checkers.end() && CheckerIt->FullName == Entry.first &&
295            "Failed to find the checker while attempting to set up its "
296            "dependencies!");
297 
298     auto DependencyIt = binaryFind(Checkers, Entry.second);
299     assert(DependencyIt != Checkers.end() &&
300            DependencyIt->FullName == Entry.second &&
301            "Failed to find the dependency of a checker!");
302 
303     CheckerIt->Dependencies.emplace_back(&*DependencyIt);
304   }
305 }
306 
307 void CheckerRegistry::addDependency(StringRef FullName, StringRef Dependency) {
308   Dependencies.emplace_back(FullName, Dependency);
309 }
310 
311 /// Insert the checker/package option to AnalyzerOptions' config table, and
312 /// validate it, if the user supplied it on the command line.
313 static void insertAndValidate(StringRef FullName,
314                               const CheckerRegistry::CmdLineOption &Option,
315                               AnalyzerOptions &AnOpts,
316                               DiagnosticsEngine &Diags) {
317 
318   std::string FullOption = (FullName + ":" + Option.OptionName).str();
319 
320   auto It =
321       AnOpts.Config.insert({FullOption, std::string(Option.DefaultValStr)});
322 
323   // Insertation was successful -- CmdLineOption's constructor will validate
324   // whether values received from plugins or TableGen files are correct.
325   if (It.second)
326     return;
327 
328   // Insertion failed, the user supplied this package/checker option on the
329   // command line. If the supplied value is invalid, we'll restore the option
330   // to it's default value, and if we're in non-compatibility mode, we'll also
331   // emit an error.
332 
333   StringRef SuppliedValue = It.first->getValue();
334 
335   if (Option.OptionType == "bool") {
336     if (SuppliedValue != "true" && SuppliedValue != "false") {
337       if (AnOpts.ShouldEmitErrorsOnInvalidConfigValue) {
338         Diags.Report(diag::err_analyzer_checker_option_invalid_input)
339             << FullOption << "a boolean value";
340       }
341 
342       It.first->setValue(std::string(Option.DefaultValStr));
343     }
344     return;
345   }
346 
347   if (Option.OptionType == "int") {
348     int Tmp;
349     bool HasFailed = SuppliedValue.getAsInteger(0, Tmp);
350     if (HasFailed) {
351       if (AnOpts.ShouldEmitErrorsOnInvalidConfigValue) {
352         Diags.Report(diag::err_analyzer_checker_option_invalid_input)
353             << FullOption << "an integer value";
354       }
355 
356       It.first->setValue(std::string(Option.DefaultValStr));
357     }
358     return;
359   }
360 }
361 
362 template <class T>
363 static void
364 insertOptionToCollection(StringRef FullName, T &Collection,
365                          const CheckerRegistry::CmdLineOption &Option,
366                          AnalyzerOptions &AnOpts, DiagnosticsEngine &Diags) {
367   auto It = binaryFind(Collection, FullName);
368   assert(It != Collection.end() &&
369          "Failed to find the checker while attempting to add a command line "
370          "option to it!");
371 
372   insertAndValidate(FullName, Option, AnOpts, Diags);
373 
374   It->CmdLineOptions.emplace_back(Option);
375 }
376 
377 void CheckerRegistry::resolveCheckerAndPackageOptions() {
378   for (const std::pair<StringRef, CmdLineOption> &CheckerOptEntry :
379        CheckerOptions) {
380     insertOptionToCollection(CheckerOptEntry.first, Checkers,
381                              CheckerOptEntry.second, AnOpts, Diags);
382   }
383 
384   for (const std::pair<StringRef, CmdLineOption> &PackageOptEntry :
385        PackageOptions) {
386     insertOptionToCollection(PackageOptEntry.first, Packages,
387                              PackageOptEntry.second, AnOpts, Diags);
388   }
389 }
390 
391 void CheckerRegistry::addPackage(StringRef FullName) {
392   Packages.emplace_back(PackageInfo(FullName));
393 }
394 
395 void CheckerRegistry::addPackageOption(StringRef OptionType,
396                                        StringRef PackageFullName,
397                                        StringRef OptionName,
398                                        StringRef DefaultValStr,
399                                        StringRef Description,
400                                        StringRef DevelopmentStatus,
401                                        bool IsHidden) {
402   PackageOptions.emplace_back(
403       PackageFullName, CmdLineOption{OptionType, OptionName, DefaultValStr,
404                                      Description, DevelopmentStatus, IsHidden});
405 }
406 
407 void CheckerRegistry::addChecker(InitializationFunction Rfn,
408                                  ShouldRegisterFunction Sfn, StringRef Name,
409                                  StringRef Desc, StringRef DocsUri,
410                                  bool IsHidden) {
411   Checkers.emplace_back(Rfn, Sfn, Name, Desc, DocsUri, IsHidden);
412 
413   // Record the presence of the checker in its packages.
414   StringRef PackageName, LeafName;
415   std::tie(PackageName, LeafName) = Name.rsplit(PackageSeparator);
416   while (!LeafName.empty()) {
417     PackageSizes[PackageName] += 1;
418     std::tie(PackageName, LeafName) = PackageName.rsplit(PackageSeparator);
419   }
420 }
421 
422 void CheckerRegistry::addCheckerOption(StringRef OptionType,
423                                        StringRef CheckerFullName,
424                                        StringRef OptionName,
425                                        StringRef DefaultValStr,
426                                        StringRef Description,
427                                        StringRef DevelopmentStatus,
428                                        bool IsHidden) {
429   CheckerOptions.emplace_back(
430       CheckerFullName, CmdLineOption{OptionType, OptionName, DefaultValStr,
431                                      Description, DevelopmentStatus, IsHidden});
432 }
433 
434 void CheckerRegistry::initializeManager(CheckerManager &CheckerMgr) const {
435   // Initialize the CheckerManager with all enabled checkers.
436   for (const auto *Checker : EnabledCheckers) {
437     CheckerMgr.setCurrentCheckerName(CheckerNameRef(Checker->FullName));
438     Checker->Initialize(CheckerMgr);
439   }
440 }
441 
442 static void
443 isOptionContainedIn(const CheckerRegistry::CmdLineOptionList &OptionList,
444                     StringRef SuppliedChecker, StringRef SuppliedOption,
445                     const AnalyzerOptions &AnOpts, DiagnosticsEngine &Diags) {
446 
447   if (!AnOpts.ShouldEmitErrorsOnInvalidConfigValue)
448     return;
449 
450   using CmdLineOption = CheckerRegistry::CmdLineOption;
451 
452   auto SameOptName = [SuppliedOption](const CmdLineOption &Opt) {
453     return Opt.OptionName == SuppliedOption;
454   };
455 
456   auto OptionIt = llvm::find_if(OptionList, SameOptName);
457 
458   if (OptionIt == OptionList.end()) {
459     Diags.Report(diag::err_analyzer_checker_option_unknown)
460         << SuppliedChecker << SuppliedOption;
461     return;
462   }
463 }
464 
465 void CheckerRegistry::validateCheckerOptions() const {
466   for (const auto &Config : AnOpts.Config) {
467 
468     StringRef SuppliedCheckerOrPackage;
469     StringRef SuppliedOption;
470     std::tie(SuppliedCheckerOrPackage, SuppliedOption) =
471         Config.getKey().split(':');
472 
473     if (SuppliedOption.empty())
474       continue;
475 
476     // AnalyzerOptions' config table contains the user input, so an entry could
477     // look like this:
478     //
479     //   cor:NoFalsePositives=true
480     //
481     // Since lower_bound would look for the first element *not less* than "cor",
482     // it would return with an iterator to the first checker in the core, so we
483     // we really have to use find here, which uses operator==.
484     auto CheckerIt =
485         llvm::find(Checkers, CheckerInfo(SuppliedCheckerOrPackage));
486     if (CheckerIt != Checkers.end()) {
487       isOptionContainedIn(CheckerIt->CmdLineOptions, SuppliedCheckerOrPackage,
488                           SuppliedOption, AnOpts, Diags);
489       continue;
490     }
491 
492     auto PackageIt =
493         llvm::find(Packages, PackageInfo(SuppliedCheckerOrPackage));
494     if (PackageIt != Packages.end()) {
495       isOptionContainedIn(PackageIt->CmdLineOptions, SuppliedCheckerOrPackage,
496                           SuppliedOption, AnOpts, Diags);
497       continue;
498     }
499 
500     Diags.Report(diag::err_unknown_analyzer_checker_or_package)
501         << SuppliedCheckerOrPackage;
502   }
503 }
504 
505 //===----------------------------------------------------------------------===//
506 // Printing functions.
507 //===----------------------------------------------------------------------===//
508 
509 void CheckerRegistry::printCheckerWithDescList(raw_ostream &Out,
510                                                size_t MaxNameChars) const {
511   // FIXME: Print available packages.
512 
513   Out << "CHECKERS:\n";
514 
515   // Find the maximum option length.
516   size_t OptionFieldWidth = 0;
517   for (const auto &Checker : Checkers) {
518     // Limit the amount of padding we are willing to give up for alignment.
519     //   Package.Name     Description  [Hidden]
520     size_t NameLength = Checker.FullName.size();
521     if (NameLength <= MaxNameChars)
522       OptionFieldWidth = std::max(OptionFieldWidth, NameLength);
523   }
524 
525   const size_t InitialPad = 2;
526 
527   auto Print = [=](llvm::raw_ostream &Out, const CheckerInfo &Checker,
528                    StringRef Description) {
529     AnalyzerOptions::printFormattedEntry(Out, {Checker.FullName, Description},
530                                          InitialPad, OptionFieldWidth);
531     Out << '\n';
532   };
533 
534   for (const auto &Checker : Checkers) {
535     // The order of this if branches is significant, we wouldn't like to display
536     // developer checkers even in the alpha output. For example,
537     // alpha.cplusplus.IteratorModeling is a modeling checker, hence it's hidden
538     // by default, and users (even when the user is a developer of an alpha
539     // checker) shouldn't normally tinker with whether they should be enabled.
540 
541     if (Checker.IsHidden) {
542       if (AnOpts.ShowCheckerHelpDeveloper)
543         Print(Out, Checker, Checker.Desc);
544       continue;
545     }
546 
547     if (Checker.FullName.startswith("alpha")) {
548       if (AnOpts.ShowCheckerHelpAlpha)
549         Print(Out, Checker,
550               ("(Enable only for development!) " + Checker.Desc).str());
551       continue;
552     }
553 
554     if (AnOpts.ShowCheckerHelp)
555         Print(Out, Checker, Checker.Desc);
556   }
557 }
558 
559 void CheckerRegistry::printEnabledCheckerList(raw_ostream &Out) const {
560   for (const auto *i : EnabledCheckers)
561     Out << i->FullName << '\n';
562 }
563 
564 void CheckerRegistry::printCheckerOptionList(raw_ostream &Out) const {
565   Out << "OVERVIEW: Clang Static Analyzer Checker and Package Option List\n\n";
566   Out << "USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>\n\n";
567   Out << "       -analyzer-config OPTION1=VALUE, -analyzer-config "
568          "OPTION2=VALUE, ...\n\n";
569   Out << "OPTIONS:\n\n";
570 
571   std::multimap<StringRef, const CmdLineOption &> OptionMap;
572 
573   for (const CheckerInfo &Checker : Checkers) {
574     for (const CmdLineOption &Option : Checker.CmdLineOptions) {
575       OptionMap.insert({Checker.FullName, Option});
576     }
577   }
578 
579   for (const PackageInfo &Package : Packages) {
580     for (const CmdLineOption &Option : Package.CmdLineOptions) {
581       OptionMap.insert({Package.FullName, Option});
582     }
583   }
584 
585   auto Print = [] (llvm::raw_ostream &Out, StringRef FullOption, StringRef Desc) {
586     AnalyzerOptions::printFormattedEntry(Out, {FullOption, Desc},
587                                          /*InitialPad*/ 2,
588                                          /*EntryWidth*/ 50,
589                                          /*MinLineWidth*/ 90);
590     Out << "\n\n";
591   };
592   for (const std::pair<const StringRef, const CmdLineOption &> &Entry :
593        OptionMap) {
594     const CmdLineOption &Option = Entry.second;
595     std::string FullOption = (Entry.first + ":" + Option.OptionName).str();
596 
597     std::string Desc =
598         ("(" + Option.OptionType + ") " + Option.Description + " (default: " +
599          (Option.DefaultValStr.empty() ? "\"\"" : Option.DefaultValStr) + ")")
600             .str();
601 
602     // The list of these if branches is significant, we wouldn't like to
603     // display hidden alpha checker options for
604     // -analyzer-checker-option-help-alpha.
605 
606     if (Option.IsHidden) {
607       if (AnOpts.ShowCheckerOptionDeveloperList)
608         Print(Out, FullOption, Desc);
609       continue;
610     }
611 
612     if (Option.DevelopmentStatus == "alpha" ||
613         Entry.first.startswith("alpha")) {
614       if (AnOpts.ShowCheckerOptionAlphaList)
615         Print(Out, FullOption,
616               llvm::Twine("(Enable only for development!) " + Desc).str());
617       continue;
618     }
619 
620     if (AnOpts.ShowCheckerOptionList)
621       Print(Out, FullOption, Desc);
622   }
623 }
624