Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
Line
Count
Source
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
13
#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
14
#include "clang/Basic/Diagnostic.h"
15
#include "clang/Frontend/FrontendDiagnostic.h"
16
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
17
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
18
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
19
#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
20
#include "llvm/ADT/SmallVector.h"
21
#include "llvm/Support/raw_ostream.h"
22
#include <memory>
23
24
using namespace clang;
25
using namespace ento;
26
27
std::unique_ptr<CheckerManager> ento::createCheckerManager(
28
    ASTContext &context,
29
    AnalyzerOptions &opts,
30
    ArrayRef<std::string> plugins,
31
    ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns,
32
1.25k
    DiagnosticsEngine &diags) {
33
1.25k
  auto checkerMgr = std::make_unique<CheckerManager>(context, opts);
34
1.25k
35
1.25k
  CheckerRegistry allCheckers(plugins, diags, opts, context.getLangOpts(),
36
1.25k
                              checkerRegistrationFns);
37
1.25k
38
1.25k
  allCheckers.initializeManager(*checkerMgr);
39
1.25k
  allCheckers.validateCheckerOptions();
40
1.25k
  checkerMgr->finishedCheckerRegistration();
41
1.25k
42
1.25k
  return checkerMgr;
43
1.25k
}
44
45
void ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins,
46
                            AnalyzerOptions &anopts,
47
                            DiagnosticsEngine &diags,
48
9
                            const LangOptions &langOpts) {
49
9
  out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
50
9
  out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";
51
9
52
9
  CheckerRegistry(plugins, diags, anopts, langOpts)
53
9
      .printCheckerWithDescList(out);
54
9
}
55
56
void ento::printEnabledCheckerList(raw_ostream &out,
57
                                   ArrayRef<std::string> plugins,
58
                                   AnalyzerOptions &anopts,
59
                                   DiagnosticsEngine &diags,
60
3
                                   const LangOptions &langOpts) {
61
3
  out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
62
3
63
3
  CheckerRegistry(plugins, diags, anopts, langOpts)
64
3
      .printEnabledCheckerList(out);
65
3
}
66
67
void ento::printCheckerConfigList(raw_ostream &OS,
68
                                  ArrayRef<std::string> plugins,
69
                                  AnalyzerOptions &opts,
70
                                  DiagnosticsEngine &diags,
71
7
                                  const LangOptions &LangOpts) {
72
7
  CheckerRegistry(plugins, diags, opts, LangOpts)
73
7
      .printCheckerOptionList(OS);
74
7
}
75
76
1
void ento::printAnalyzerConfigList(raw_ostream &out) {
77
1
  // FIXME: This message sounds scary, should be scary, but incorrectly states
78
1
  // that all configs are super dangerous. In reality, many of them should be
79
1
  // accessible to the user. We should create a user-facing subset of config
80
1
  // options under a different frontend flag.
81
1
  out << R"(
82
1
OVERVIEW: Clang Static Analyzer -analyzer-config Option List
83
1
84
1
The following list of configurations are meant for development purposes only, as
85
1
some of the variables they define are set to result in the most optimal
86
1
analysis. Setting them to other values may drastically change how the analyzer
87
1
behaves, and may even result in instabilities, crashes!
88
1
89
1
USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>
90
1
       -analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ...
91
1
OPTIONS:
92
1
)";
93
1
94
1
  using OptionAndDescriptionTy = std::pair<StringRef, std::string>;
95
1
  OptionAndDescriptionTy PrintableOptions[] = {
96
1
#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)                \
97
53
    {                                                                          \
98
53
      CMDFLAG,                                                                 \
99
53
      llvm::Twine(llvm::Twine() + "(" +                                        \
100
53
                  (StringRef(#TYPE) == "StringRef" ? 
"string"7
: #TYPE ) + \
101
53
                  ") " DESC                                                    \
102
53
                  " (default: " #DEFAULT_VAL ")").str()                        \
103
53
    },
104
1
105
1
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,        \
106
1
                                             SHALLOW_VAL, DEEP_VAL)            \
107
3
    {                                                                          \
108
3
      CMDFLAG,                                                                 \
109
3
      llvm::Twine(llvm::Twine() + "(" +                                        \
110
3
                  (StringRef(#TYPE) == "StringRef" ? 
"string"1
: #TYPE ) + \
111
3
                  ") " DESC                                                    \
112
3
                  " (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL    \
113
3
                  " in deep mode)").str()                                      \
114
3
    },
115
1
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
116
1
#undef ANALYZER_OPTION
117
1
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
118
1
  };
119
1
120
1
  llvm::sort(PrintableOptions, [](const OptionAndDescriptionTy &LHS,
121
315
                                  const OptionAndDescriptionTy &RHS) {
122
315
    return LHS.first < RHS.first;
123
315
  });
124
1
125
56
  for (const auto &Pair : PrintableOptions) {
126
56
    AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,
127
56
                                         /*EntryWidth*/ 30,
128
56
                                         /*MinLineWidth*/ 70);
129
56
    out << "\n\n";
130
56
  }
131
1
}