Coverage Report

Created: 2020-10-24 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/StaticAnalyzer/Frontend/AnalyzerHelpFlags.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/AnalyzerHelpFlags.h"
14
#include "clang/Basic/Diagnostic.h"
15
#include "clang/Frontend/CompilerInstance.h"
16
#include "clang/Frontend/FrontendDiagnostic.h"
17
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
18
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
19
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
20
#include "clang/StaticAnalyzer/Frontend/FrontendActions.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
9
void ento::printCheckerHelp(raw_ostream &out, CompilerInstance &CI) {
29
9
  out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
30
9
  out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";
31
32
9
  auto CheckerMgr = std::make_unique<CheckerManager>(
33
9
      *CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(),
34
9
      CI.getFrontendOpts().Plugins);
35
36
9
  CheckerMgr->getCheckerRegistryData().printCheckerWithDescList(
37
9
      *CI.getAnalyzerOpts(), out);
38
9
}
39
40
4
void ento::printEnabledCheckerList(raw_ostream &out, CompilerInstance &CI) {
41
4
  out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
42
43
4
  auto CheckerMgr = std::make_unique<CheckerManager>(
44
4
      *CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(),
45
4
      CI.getFrontendOpts().Plugins);
46
47
4
  CheckerMgr->getCheckerRegistryData().printEnabledCheckerList(out);
48
4
}
49
50
7
void ento::printCheckerConfigList(raw_ostream &out, CompilerInstance &CI) {
51
52
7
  auto CheckerMgr = std::make_unique<CheckerManager>(
53
7
      *CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(),
54
7
      CI.getFrontendOpts().Plugins);
55
56
7
  CheckerMgr->getCheckerRegistryData().printCheckerOptionList(
57
7
      *CI.getAnalyzerOpts(), out);
58
7
}
59
60
1
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
1
  out << R"(
66
1
OVERVIEW: Clang Static Analyzer -analyzer-config Option List
67
1
68
1
The following list of configurations are meant for development purposes only, as
69
1
some of the variables they define are set to result in the most optimal
70
1
analysis. Setting them to other values may drastically change how the analyzer
71
1
behaves, and may even result in instabilities, crashes!
72
1
73
1
USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>
74
1
       -analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ...
75
1
OPTIONS:
76
1
)";
77
78
1
  using OptionAndDescriptionTy = std::pair<StringRef, std::string>;
79
1
  OptionAndDescriptionTy PrintableOptions[] = {
80
1
#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)                \
81
56
    {                                                                          \
82
56
      CMDFLAG,                                                                 \
83
56
      llvm::Twine(llvm::Twine() + "(" +                                        \
84
8
                  (StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) +      \
85
56
                  ") " DESC                                                    \
86
56
                  " (default: " #DEFAULT_VAL ")").str()                        \
87
56
    },
88
89
1
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,        \
90
1
                                             SHALLOW_VAL, DEEP_VAL)            \
91
3
    {                                                                          \
92
3
      CMDFLAG,                                                                 \
93
3
      llvm::Twine(llvm::Twine() + "(" +                                        \
94
1
                  (StringRef(#TYPE) == "StringRef" ? "string" : #TYPE ) +      \
95
3
                  ") " DESC                                                    \
96
3
                  " (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL    \
97
3
                  " in deep mode)").str()                                      \
98
3
    },
99
1
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
100
1
#undef ANALYZER_OPTION
101
1
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
102
1
  };
103
104
1
  llvm::sort(PrintableOptions, [](const OptionAndDescriptionTy &LHS,
105
353
                                  const OptionAndDescriptionTy &RHS) {
106
353
    return LHS.first < RHS.first;
107
353
  });
108
109
59
  for (const auto &Pair : PrintableOptions) {
110
59
    AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,
111
59
                                         /*EntryWidth*/ 30,
112
59
                                         /*MinLineWidth*/ 70);
113
59
    out << "\n\n";
114
59
  }
115
1
}