17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/ADT/StringSwitch.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/raw_ostream.h"
22 using namespace clang;
27 if (UserMode == UMK_NotSet) {
29 Config.insert(std::make_pair(
"mode",
"deep")).first->second;
30 UserMode = llvm::StringSwitch<UserModeKind>(ModeStr)
31 .Case(
"shallow", UMK_Shallow)
32 .Case(
"deep", UMK_Deep)
34 assert(UserMode != UMK_NotSet &&
"User mode is invalid.");
45 const char *DefaultIPA =
nullptr;
46 UserModeKind HighLevelMode = getUserMode();
47 if (HighLevelMode == UMK_Shallow)
48 DefaultIPA =
"inlining";
49 else if (HighLevelMode == UMK_Deep)
50 DefaultIPA =
"dynamic-bifurcate";
55 Config.insert(std::make_pair(
"ipa", DefaultIPA)).first->second;
56 IPAKind IPAConfig = llvm::StringSwitch<IPAKind>(ModeStr)
63 assert(IPAConfig !=
IPAK_NotSet &&
"IPA Mode is invalid.");
77 if (!CXXMemberInliningMode) {
78 static const char *ModeKey =
"c++-inlining";
81 Config.insert(std::make_pair(ModeKey,
"destructors")).first->second;
86 MutableMode = llvm::StringSwitch<CXXInlineableMemberKind>(ModeStr)
100 return CXXMemberInliningMode >= K;
103 static StringRef
toString(
bool b) {
return b ?
"true" :
"false"; }
105 StringRef AnalyzerOptions::getCheckerOption(StringRef CheckerName,
106 StringRef OptionName,
108 bool SearchInParents) {
111 ConfigTable::const_iterator
E = Config.end();
113 ConfigTable::const_iterator
I =
114 Config.find((Twine(CheckerName) +
":" + OptionName).str());
116 return StringRef(I->getValue());
117 size_t Pos = CheckerName.rfind(
'.');
118 if (Pos == StringRef::npos)
120 CheckerName = CheckerName.substr(0, Pos);
121 }
while (!CheckerName.empty() && SearchInParents);
127 bool SearchInParents) {
131 StringRef Default =
toString(DefaultVal);
135 : StringRef(Config.insert(std::make_pair(Name, Default)).first->second);
136 return llvm::StringSwitch<bool>(V)
138 .Case(
"false",
false)
139 .Default(DefaultVal);
144 bool SearchInParents) {
146 V = getBooleanOption(Name, DefaultVal, C, SearchInParents);
151 return getBooleanOption(IncludeTemporaryDtorsInCFG,
152 "cfg-temporary-dtors",
157 return getBooleanOption(InlineCXXStandardLibrary,
158 "c++-stdlib-inlining",
163 return getBooleanOption(InlineTemplateFunctions,
164 "c++-template-inlining",
169 return getBooleanOption(InlineCXXAllocator,
170 "c++-allocator-inlining",
175 return getBooleanOption(InlineCXXContainerMethods,
176 "c++-container-inlining",
181 return getBooleanOption(InlineCXXSharedPtrDtor,
182 "c++-shared_ptr-inlining",
188 return getBooleanOption(ObjCInliningMode,
194 return getBooleanOption(SuppressNullReturnPaths,
195 "suppress-null-return-paths",
200 return getBooleanOption(AvoidSuppressingNullArgumentPaths,
201 "avoid-suppressing-null-argument-paths",
206 return getBooleanOption(SuppressInlinedDefensiveChecks,
207 "suppress-inlined-defensive-checks",
212 return getBooleanOption(SuppressFromCXXStandardLibrary,
213 "suppress-c++-stdlib",
218 return getBooleanOption(ReportIssuesInMainSourceFile,
219 "report-in-main-source-file",
225 return getBooleanOption(StableReportFilename,
226 "stable-report-filename",
232 bool SearchInParents) {
234 llvm::raw_svector_ostream OS(StrBuf);
239 : StringRef(Config.insert(std::make_pair(Name, OS.str()))
242 int Res = DefaultVal;
243 bool b = V.getAsInteger(10, Res);
244 assert(!b &&
"analyzer-config option should be numeric");
250 StringRef DefaultVal,
252 bool SearchInParents) {
256 Config.insert(std::make_pair(Name, DefaultVal)).first->second);
260 if (!AlwaysInlineSize.hasValue())
261 AlwaysInlineSize = getOptionAsInteger(
"ipa-always-inline-size", 3);
262 return AlwaysInlineSize.getValue();
266 if (!MaxInlinableSize.hasValue()) {
268 int DefaultValue = 0;
269 UserModeKind HighLevelMode = getUserMode();
270 switch (HighLevelMode) {
272 llvm_unreachable(
"Invalid mode.");
281 MaxInlinableSize = getOptionAsInteger(
"max-inlinable-size", DefaultValue);
283 return MaxInlinableSize.getValue();
287 if (!GraphTrimInterval.hasValue())
288 GraphTrimInterval = getOptionAsInteger(
"graph-trim-interval", 1000);
289 return GraphTrimInterval.getValue();
293 if (!MaxTimesInlineLarge.hasValue())
294 MaxTimesInlineLarge = getOptionAsInteger(
"max-times-inline-large", 32);
295 return MaxTimesInlineLarge.getValue();
299 if (!MinCFGSizeTreatFunctionsAsLarge.hasValue())
300 MinCFGSizeTreatFunctionsAsLarge = getOptionAsInteger(
301 "min-cfg-size-treat-functions-as-large", 14);
302 return MinCFGSizeTreatFunctionsAsLarge.getValue();
306 if (!MaxNodesPerTopLevelFunction.hasValue()) {
307 int DefaultValue = 0;
308 UserModeKind HighLevelMode = getUserMode();
309 switch (HighLevelMode) {
311 llvm_unreachable(
"Invalid mode.");
313 DefaultValue = 75000;
316 DefaultValue = 150000;
319 MaxNodesPerTopLevelFunction = getOptionAsInteger(
"max-nodes", DefaultValue);
321 return MaxNodesPerTopLevelFunction.getValue();
325 return getBooleanOption(
"faux-bodies",
true);
329 return getBooleanOption(
"prune-paths",
true);
333 return getBooleanOption(
"cfg-conditional-static-initializers",
true);
337 if (!InlineLambdas.hasValue())
338 InlineLambdas = getBooleanOption(
"inline-lambdas",
true);
339 return InlineLambdas.getValue();
343 if (!WidenLoops.hasValue())
344 WidenLoops = getBooleanOption(
"widen-loops",
false);
345 return WidenLoops.getValue();
Inline C functions and blocks when their definitions are available.
IPAKind
Describes the different modes of inter-procedural analysis.
bool shouldSuppressNullReturnPaths()
Returns whether or not paths that go through null returns should be suppressed.
bool shouldPrunePaths()
Returns whether irrelevant parts of a bug report path should be pruned out of the final output...
bool shouldAvoidSuppressingNullArgumentPaths()
Returns whether a bug report should not be suppressed if its path includes a call with a null argumen...
bool shouldWidenLoops()
Returns true if the analysis should try to widen loops.
Perform only intra-procedural analysis.
A dummy mode in which no C++ inlining is enabled.
bool mayInlineTemplateFunctions()
Returns whether or not templated functions may be considered for inlining.
Inline callees(C, C++, ObjC) when their definitions are available.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
StringRef getOptionAsString(StringRef Name, StringRef DefaultVal, const ento::CheckerBase *C=nullptr, bool SearchInParents=false)
Query an option's string value.
StringRef getTagDescription() const override
bool mayInlineCXXContainerMethods()
Returns whether or not methods of C++ container objects may be considered for inlining.
unsigned getMinCFGSizeTreatFunctionsAsLarge()
Returns the number of basic blocks a function needs to have to be considered large for the 'max-times...
detail::InMemoryDirectory::const_iterator I
unsigned getMaxInlinableSize()
UserModeKind getUserMode()
Retrieves and sets the UserMode.
bool shouldSuppressInlinedDefensiveChecks()
Returns whether or not diagnostics containing inlined defensive NULL checks should be suppressed...
bool shouldWriteStableReportFilename()
Returns whether or not the report filename should be random or not.
IPAKind getIPAMode()
Returns the inter-procedural analysis mode.
Refers to regular member function and operator calls.
bool mayInlineObjCMethod()
Returns true if ObjectiveC inlining is enabled, false otherwise.
bool shouldConditionalizeStaticInitializers()
Returns true if 'static' initializers should be in conditional logic in the CFG.
Refers to constructors (implicit or explicit).
Enable inlining of dynamically dispatched methods.
bool getBooleanOption(StringRef Name, bool DefaultVal, const ento::CheckerBase *C=nullptr, bool SearchInParents=false)
Interprets an option's string value as a boolean.
unsigned getAlwaysInlineSize()
unsigned getMaxNodesPerTopLevelFunction()
Returns the maximum number of nodes the analyzer can generate while exploring a top level function (f...
bool mayInlineCXXStandardLibrary()
Returns whether or not C++ standard library functions may be considered for inlining.
Refers to destructors (implicit or explicit).
unsigned getGraphTrimInterval()
Returns how often nodes in the ExplodedGraph should be recycled to save memory.
detail::InMemoryDirectory::const_iterator E
bool includeTemporaryDtorsInCFG()
Returns whether or not the destructors for C++ temporary objects should be included in the CFG...
bool shouldSuppressFromCXXStandardLibrary()
Returns whether or not diagnostics reported within the C++ standard library should be suppressed...
bool shouldSynthesizeBodies()
Returns true if the analyzer engine should synthesize fake bodies for well-known functions.
bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K)
Returns the option controlling which C++ member functions will be considered for inlining.
unsigned getMaxTimesInlineLarge()
Returns the maximum times a large function could be inlined.
CXXInlineableMemberKind
Describes the different kinds of C++ member functions which can be considered for inlining by the ana...
int getOptionAsInteger(StringRef Name, int DefaultVal, const ento::CheckerBase *C=nullptr, bool SearchInParents=false)
Interprets an option's string value as an integer value.
bool mayInlineCXXAllocator()
Returns whether or not allocator call may be considered for inlining.
Enable inlining of dynamically dispatched methods, bifurcate paths when exact type info is unavailabl...
bool mayInlineCXXSharedPtrDtor()
Returns whether or not the destructor of C++ 'shared_ptr' may be considered for inlining.
bool shouldReportIssuesInMainSourceFile()
Returns whether or not the diagnostic report should be always reported in the main source file and no...
bool shouldInlineLambdas()
Returns true if lambdas should be inlined.
static StringRef toString(bool b)