clang  15.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 
14 #include "clang/Basic/Diagnostic.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include <memory>
24 
25 using namespace clang;
26 using namespace ento;
27 
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";
31 
32  auto CheckerMgr = std::make_unique<CheckerManager>(
33  *CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(),
35 
36  CheckerMgr->getCheckerRegistryData().printCheckerWithDescList(
37  *CI.getAnalyzerOpts(), out);
38 }
39 
40 void 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>(
44  *CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(),
46 
47  CheckerMgr->getCheckerRegistryData().printEnabledCheckerList(out);
48 }
49 
50 void ento::printCheckerConfigList(raw_ostream &out, CompilerInstance &CI) {
51 
52  auto CheckerMgr = std::make_unique<CheckerManager>(
53  *CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(),
55 
56  CheckerMgr->getCheckerRegistryData().printCheckerOptionList(
57  *CI.getAnalyzerOpts(), out);
58 }
59 
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.
65  out << R"(
66 OVERVIEW: Clang Static Analyzer -analyzer-config Option List
67 
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!
72 
73 USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>
74  -analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ...
75 OPTIONS:
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, [](const OptionAndDescriptionTy &LHS,
105  const OptionAndDescriptionTy &RHS) {
106  return LHS.first < RHS.first;
107  });
108 
109  for (const auto &Pair : PrintableOptions) {
110  AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,
111  /*EntryWidth*/ 30,
112  /*MinLineWidth*/ 70);
113  out << "\n\n";
114  }
115 }
clang::ento::printAnalyzerConfigList
void printAnalyzerConfigList(llvm::raw_ostream &OS)
AnalyzerOptions.h
clang::CompilerInstance::getLangOpts
LangOptions & getLangOpts()
Definition: CompilerInstance.h:299
AnalyzerHelpFlags.h
clang::CompilerInstance::getAnalyzerOpts
AnalyzerOptionsRef getAnalyzerOpts()
Definition: CompilerInstance.h:250
CheckerManager.h
Diagnostic.h
clang::ento::printEnabledCheckerList
void printEnabledCheckerList(llvm::raw_ostream &OS, CompilerInstance &CI)
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:72
clang::ento::printCheckerConfigList
void printCheckerConfigList(llvm::raw_ostream &OS, CompilerInstance &CI)
clang::AnalyzerOptions::printFormattedEntry
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.
Definition: AnalyzerOptions.cpp:33
clang::ento::printCheckerHelp
void printCheckerHelp(llvm::raw_ostream &OS, CompilerInstance &CI)
clang::FrontendOptions::Plugins
std::vector< std::string > Plugins
The list of plugins to load.
Definition: FrontendOptions.h:461
FrontendActions.h
clang
Definition: CalledOnceCheck.h:17
FrontendDiagnostic.h
CompilerInstance.h
CheckerRegistry.h
clang::CompilerInstance::getFrontendOpts
FrontendOptions & getFrontendOpts()
Definition: CompilerInstance.h:282
clang::CompilerInstance::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
Definition: CompilerInstance.h:334