clang 22.0.0git
AnalyzerHelpFlags.cpp
Go to the documentation of this file.
1//===--- CheckerRegistration.cpp - Registration for the Analyzer 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// Defines the registration function for the analyzer checkers.
10//
11//===----------------------------------------------------------------------===//
12
18#include <memory>
19
20using namespace clang;
21using namespace ento;
22
23void ento::printCheckerHelp(raw_ostream &out, CompilerInstance &CI) {
24 out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
25 out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";
26
27 auto CheckerMgr = std::make_unique<CheckerManager>(
30
31 CheckerMgr->getCheckerRegistryData().printCheckerWithDescList(
32 CI.getAnalyzerOpts(), out);
33}
34
36 out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
37
38 auto CheckerMgr = std::make_unique<CheckerManager>(
41
42 CheckerMgr->getCheckerRegistryData().printEnabledCheckerList(out);
43}
44
46
47 auto CheckerMgr = std::make_unique<CheckerManager>(
50
51 CheckerMgr->getCheckerRegistryData().printCheckerOptionList(
52 CI.getAnalyzerOpts(), out);
53}
54
55void ento::printAnalyzerConfigList(raw_ostream &out) {
56 // FIXME: This message sounds scary, should be scary, but incorrectly states
57 // that all configs are super dangerous. In reality, many of them should be
58 // accessible to the user. We should create a user-facing subset of config
59 // options under a different frontend flag.
60 out << R"(
61OVERVIEW: Clang Static Analyzer -analyzer-config Option List
62
63The following list of configurations are meant for development purposes only, as
64some of the variables they define are set to result in the most optimal
65analysis. Setting them to other values may drastically change how the analyzer
66behaves, and may even result in instabilities, crashes!
67
68USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>
69 -analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ...
70OPTIONS:
71)";
72
73 using OptionAndDescriptionTy = std::pair<StringRef, std::string>;
74 OptionAndDescriptionTy PrintableOptions[] = {
75#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \
76 { \
77 CMDFLAG, \
78 llvm::Twine(llvm::Twine() + "(" + \
79 (StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \
80 ") " DESC \
81 " (default: " #DEFAULT_VAL ")").str() \
82 },
83
84#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \
85 SHALLOW_VAL, DEEP_VAL) \
86 { \
87 CMDFLAG, \
88 llvm::Twine(llvm::Twine() + "(" + \
89 (StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \
90 ") " DESC \
91 " (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL \
92 " in deep mode)").str() \
93 },
94#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
95#undef ANALYZER_OPTION
96#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
97 };
98
99 llvm::sort(PrintableOptions, llvm::less_first());
100
101 for (const auto &Pair : PrintableOptions) {
102 AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,
103 /*EntryWidth*/ 30,
104 /*MinLineWidth*/ 70);
105 out << "\n\n";
106 }
107}
static void printFormattedEntry(llvm::raw_ostream &Out, std::pair< StringRef, StringRef > EntryDescPair, size_t InitialPad, size_t EntryWidth, size_t MinLineWidth=0)
Convenience function for printing options or checkers and their description in a formatted manner.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
AnalyzerOptions & getAnalyzerOpts()
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
FrontendOptions & getFrontendOpts()
std::vector< std::string > Plugins
The list of plugins to load.
void printEnabledCheckerList(llvm::raw_ostream &OS, CompilerInstance &CI)
void printCheckerHelp(llvm::raw_ostream &OS, CompilerInstance &CI)
void printAnalyzerConfigList(llvm::raw_ostream &OS)
void printCheckerConfigList(llvm::raw_ostream &OS, CompilerInstance &CI)
The JSON file list parser is used to communicate input to InstallAPI.