Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
910
    DiagnosticsEngine &diags) {
33
910
  auto checkerMgr = llvm::make_unique<CheckerManager>(context, opts);
34
910
35
910
  CheckerRegistry allCheckers(plugins, diags, opts, context.getLangOpts(),
36
910
                              checkerRegistrationFns);
37
910
38
910
  allCheckers.initializeManager(*checkerMgr);
39
910
  allCheckers.validateCheckerOptions();
40
910
  checkerMgr->finishedCheckerRegistration();
41
910
42
910
  return checkerMgr;
43
910
}
44
45
void ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins,
46
                            AnalyzerOptions &anopts,
47
                            DiagnosticsEngine &diags,
48
7
                            const LangOptions &langOpts) {
49
7
  out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
50
7
  out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";
51
7
52
7
  CheckerRegistry(plugins, diags, anopts, langOpts)
53
7
      .printCheckerWithDescList(out);
54
7
}
55
56
void ento::printEnabledCheckerList(raw_ostream &out,
57
                                   ArrayRef<std::string> plugins,
58
                                   AnalyzerOptions &anopts,
59
                                   DiagnosticsEngine &diags,
60
5
                                   const LangOptions &langOpts) {
61
5
  out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
62
5
63
5
  CheckerRegistry(plugins, diags, anopts, langOpts)
64
5
      .printEnabledCheckerList(out);
65
5
}
66
67
void ento::printCheckerConfigList(raw_ostream &OS,
68
                                  ArrayRef<std::string> plugins,
69
                                  AnalyzerOptions &opts,
70
                                  DiagnosticsEngine &diags,
71
8
                                  const LangOptions &LangOpts) {
72
8
  CheckerRegistry(plugins, diags, opts, LangOpts)
73
8
      .printCheckerOptionList(OS);
74
8
}
75
76
1
void ento::printAnalyzerConfigList(raw_ostream &out) {
77
1
  out << "OVERVIEW: Clang Static Analyzer -analyzer-config Option List\n\n";
78
1
  out << "USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>\n\n";
79
1
  out << "       -analyzer-config OPTION1=VALUE, -analyzer-config "
80
1
         "OPTION2=VALUE, ...\n\n";
81
1
  out << "OPTIONS:\n\n";
82
1
83
1
  using OptionAndDescriptionTy = std::pair<StringRef, std::string>;
84
1
  OptionAndDescriptionTy PrintableOptions[] = {
85
1
#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)                \
86
50
    {                                                                          \
87
50
      CMDFLAG,                                                                 \
88
50
      llvm::Twine(llvm::Twine() + "(" +                                        \
89
50
                  (StringRef(#TYPE) == "StringRef" ? 
"string"6
: #TYPE ) + \
90
50
                  ") " DESC                                                    \
91
50
                  " (default: " #DEFAULT_VAL ")").str()                        \
92
50
    },
93
1
94
1
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,        \
95
1
                                             SHALLOW_VAL, DEEP_VAL)            \
96
3
    {                                                                          \
97
3
      CMDFLAG,                                                                 \
98
3
      llvm::Twine(llvm::Twine() + "(" +                                        \
99
3
                  (StringRef(#TYPE) == "StringRef" ? 
"string"1
: #TYPE ) + \
100
3
                  ") " DESC                                                    \
101
3
                  " (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL    \
102
3
                  " in deep mode)").str()                                      \
103
3
    },
104
1
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
105
1
#undef ANALYZER_OPTION
106
1
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
107
1
  };
108
1
109
1
  llvm::sort(PrintableOptions, [](const OptionAndDescriptionTy &LHS,
110
313
                                  const OptionAndDescriptionTy &RHS) {
111
313
    return LHS.first < RHS.first;
112
313
  });
113
1
114
53
  for (const auto &Pair : PrintableOptions) {
115
53
    AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,
116
53
                                         /*EntryWidth*/ 30,
117
53
                                         /*MinLineWidth*/ 70);
118
53
    out << "\n\n";
119
53
  }
120
1
}