clang 20.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
21#include "llvm/ADT/SmallVector.h"
22#include "llvm/Support/raw_ostream.h"
23#include <memory>
24
25using namespace clang;
26using namespace ento;
27
28void 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";
31
32 auto CheckerMgr = std::make_unique<CheckerManager>(
35
36 CheckerMgr->getCheckerRegistryData().printCheckerWithDescList(
37 CI.getAnalyzerOpts(), out);
38}
39
40void ento::printEnabledCheckerList(raw_ostream &out, CompilerInstance &CI) {
41 out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
42
43 auto CheckerMgr = std::make_unique<CheckerManager>(
46
47 CheckerMgr->getCheckerRegistryData().printEnabledCheckerList(out);
48}
49
50void ento::printCheckerConfigList(raw_ostream &out, CompilerInstance &CI) {
51
52 auto CheckerMgr = std::make_unique<CheckerManager>(
55
56 CheckerMgr->getCheckerRegistryData().printCheckerOptionList(
57 CI.getAnalyzerOpts(), out);
58}
59
60void 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.
65 out << R"(
66OVERVIEW: Clang Static Analyzer -analyzer-config Option List
67
68The following list of configurations are meant for development purposes only, as
69some of the variables they define are set to result in the most optimal
70analysis. Setting them to other values may drastically change how the analyzer
71behaves, and may even result in instabilities, crashes!
72
73USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>
74 -analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ...
75OPTIONS:
76)";
77
78 using OptionAndDescriptionTy = std::pair<StringRef, std::string>;
79 OptionAndDescriptionTy PrintableOptions[] = {
80#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \
81 { \
82 CMDFLAG, \
83 llvm::Twine(llvm::Twine() + "(" + \
84 (StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \
85 ") " DESC \
86 " (default: " #DEFAULT_VAL ")").str() \
87 },
88
89#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \
90 SHALLOW_VAL, DEEP_VAL) \
91 { \
92 CMDFLAG, \
93 llvm::Twine(llvm::Twine() + "(" + \
94 (StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) + \
95 ") " DESC \
96 " (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL \
97 " in deep mode)").str() \
98 },
99#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
100#undef ANALYZER_OPTION
101#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
102 };
103
104 llvm::sort(PrintableOptions, llvm::less_first());
105
106 for (const auto &Pair : PrintableOptions) {
107 AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,
108 /*EntryWidth*/ 30,
109 /*MinLineWidth*/ 70);
110 out << "\n\n";
111 }
112}
Defines the Diagnostic-related interfaces.
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()
LangOptions & getLangOpts()
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.