clang  10.0.0svn
AnalyzerOptions.cpp
Go to the documentation of this file.
1 //===- AnalyzerOptions.cpp - Analysis Engine Options ----------------------===//
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 // This file contains special accessors for analyzer configuration options
10 // with string representations.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/FileSystem.h"
22 #include "llvm/Support/FormattedStream.h"
23 #include "llvm/Support/raw_ostream.h"
24 #include <cassert>
25 #include <cstddef>
26 #include <utility>
27 #include <vector>
28 
29 using namespace clang;
30 using namespace ento;
31 using namespace llvm;
32 
34  llvm::raw_ostream &Out,
35  std::pair<StringRef, StringRef> EntryDescPair,
36  size_t InitialPad, size_t EntryWidth, size_t MinLineWidth) {
37 
38  llvm::formatted_raw_ostream FOut(Out);
39 
40  const size_t PadForDesc = InitialPad + EntryWidth;
41 
42  FOut.PadToColumn(InitialPad) << EntryDescPair.first;
43  // If the buffer's length is greater then PadForDesc, print a newline.
44  if (FOut.getColumn() > PadForDesc)
45  FOut << '\n';
46 
47  FOut.PadToColumn(PadForDesc);
48 
49  if (MinLineWidth == 0) {
50  FOut << EntryDescPair.second;
51  return;
52  }
53 
54  for (char C : EntryDescPair.second) {
55  if (FOut.getColumn() > MinLineWidth && C == ' ') {
56  FOut << '\n';
57  FOut.PadToColumn(PadForDesc);
58  continue;
59  }
60  FOut << C;
61  }
62 }
63 
66  auto K =
67  llvm::StringSwitch<llvm::Optional<ExplorationStrategyKind>>(
68  ExplorationStrategy)
69  .Case("dfs", ExplorationStrategyKind::DFS)
70  .Case("bfs", ExplorationStrategyKind::BFS)
71  .Case("unexplored_first",
73  .Case("unexplored_first_queue",
75  .Case("unexplored_first_location_queue",
77  .Case("bfs_block_dfs_contents",
79  .Default(None);
80  assert(K.hasValue() && "User mode is invalid.");
81  return K.getValue();
82 }
83 
85  auto K = llvm::StringSwitch<llvm::Optional<IPAKind>>(IPAMode)
86  .Case("none", IPAK_None)
87  .Case("basic-inlining", IPAK_BasicInlining)
88  .Case("inlining", IPAK_Inlining)
89  .Case("dynamic", IPAK_DynamicDispatch)
90  .Case("dynamic-bifurcate", IPAK_DynamicDispatchBifurcate)
91  .Default(None);
92  assert(K.hasValue() && "IPA Mode is invalid.");
93 
94  return K.getValue();
95 }
96 
97 bool
99  CXXInlineableMemberKind Param) const {
100  if (getIPAMode() < IPAK_Inlining)
101  return false;
102 
103  auto K =
104  llvm::StringSwitch<llvm::Optional<CXXInlineableMemberKind>>(
105  CXXMemberInliningMode)
106  .Case("constructors", CIMK_Constructors)
107  .Case("destructors", CIMK_Destructors)
108  .Case("methods", CIMK_MemberFunctions)
109  .Case("none", CIMK_None)
110  .Default(None);
111 
112  assert(K.hasValue() && "Invalid c++ member function inlining mode.");
113 
114  return *K >= Param;
115 }
116 
117 StringRef AnalyzerOptions::getCheckerStringOption(StringRef CheckerName,
118  StringRef OptionName,
119  bool SearchInParents) const {
120  assert(!CheckerName.empty() &&
121  "Empty checker name! Make sure the checker object (including it's "
122  "bases!) if fully initialized before calling this function!");
123 
124  ConfigTable::const_iterator E = Config.end();
125  do {
126  ConfigTable::const_iterator I =
127  Config.find((Twine(CheckerName) + ":" + OptionName).str());
128  if (I != E)
129  return StringRef(I->getValue());
130  size_t Pos = CheckerName.rfind('.');
131  if (Pos == StringRef::npos)
132  break;
133 
134  CheckerName = CheckerName.substr(0, Pos);
135  } while (!CheckerName.empty() && SearchInParents);
136 
137  llvm_unreachable("Unknown checker option! Did you call getChecker*Option "
138  "with incorrect parameters? User input must've been "
139  "verified by CheckerRegistry.");
140 
141  return "";
142 }
143 
145  StringRef OptionName,
146  bool SearchInParents) const {
147  return getCheckerStringOption(
148  C->getTagDescription(), OptionName, SearchInParents);
149 }
150 
151 bool AnalyzerOptions::getCheckerBooleanOption(StringRef CheckerName,
152  StringRef OptionName,
153  bool SearchInParents) const {
154  auto Ret = llvm::StringSwitch<llvm::Optional<bool>>(
155  getCheckerStringOption(CheckerName, OptionName,
156  SearchInParents))
157  .Case("true", true)
158  .Case("false", false)
159  .Default(None);
160 
161  assert(Ret &&
162  "This option should be either 'true' or 'false', and should've been "
163  "validated by CheckerRegistry!");
164 
165  return *Ret;
166 }
167 
169  StringRef OptionName,
170  bool SearchInParents) const {
171  return getCheckerBooleanOption(
172  C->getTagDescription(), OptionName, SearchInParents);
173 }
174 
176  StringRef OptionName,
177  bool SearchInParents) const {
178  int Ret = 0;
179  bool HasFailed = getCheckerStringOption(CheckerName, OptionName,
180  SearchInParents)
181  .getAsInteger(0, Ret);
182  assert(!HasFailed &&
183  "This option should be numeric, and should've been validated by "
184  "CheckerRegistry!");
185  (void)HasFailed;
186  return Ret;
187 }
188 
190  StringRef OptionName,
191  bool SearchInParents) const {
192  return getCheckerIntegerOption(
193  C->getTagDescription(), OptionName, SearchInParents);
194 }
Inline C functions and blocks when their definitions are available.
IPAKind
Describes the different modes of inter-procedural analysis.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
StringRef getCheckerStringOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const
Query an option&#39;s string value.
Perform only intra-procedural analysis.
A dummy mode in which no C++ inlining is enabled.
static void printFormattedEntry(llvm::raw_ostream &Out, std::pair< StringRef, StringRef > EntryDescPair, size_t EntryWidth, size_t InitialPad, size_t MinLineWidth=0)
Convenience function for printing options or checkers and their description in a formatted manner...
Inline callees(C, C++, ObjC) when their definitions are available.
StringRef getTagDescription() const override
Definition: Checker.cpp:21
ExplorationStrategyKind
Refers to regular member function and operator calls.
Refers to constructors (implicit or explicit).
Enable inlining of dynamically dispatched methods.
IPAKind getIPAMode() const
Returns the inter-procedural analysis mode.
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.cpp:34
Refers to destructors (implicit or explicit).
ExplorationStrategyKind getExplorationStrategy() const
bool getCheckerBooleanOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const
Interprets an option&#39;s string value as a boolean.
Dataflow Directional Tag Classes.
bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const
Returns the option controlling which C++ member functions will be considered for inlining.
int getCheckerIntegerOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const
Interprets an option&#39;s string value as an integer value.
CXXInlineableMemberKind
Describes the different kinds of C++ member functions which can be considered for inlining by the ana...
Enable inlining of dynamically dispatched methods, bifurcate paths when exact type info is unavailabl...