1 //===-- AnalyzerOptions.cpp - Analysis Engine Options -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains special accessors for analyzer configuration options
11 // with string representations.
13 //===----------------------------------------------------------------------===//
15 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/Support/raw_ostream.h"
20 using namespace clang;
24 AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind K) {
25 if (IPAMode < Inlining)
28 if (!CXXMemberInliningMode) {
29 static const char *ModeKey = "c++-inlining";
31 StringRef ModeStr(Config.GetOrCreateValue(ModeKey,
32 "methods").getValue());
34 CXXInlineableMemberKind &MutableMode =
35 const_cast<CXXInlineableMemberKind &>(CXXMemberInliningMode);
37 MutableMode = llvm::StringSwitch<CXXInlineableMemberKind>(ModeStr)
38 .Case("constructors", CIMK_Constructors)
39 .Case("destructors", CIMK_Destructors)
40 .Case("none", CIMK_None)
41 .Case("methods", CIMK_MemberFunctions)
42 .Default(CXXInlineableMemberKind());
45 // FIXME: We should emit a warning here about an unknown inlining kind,
46 // but the AnalyzerOptions doesn't have access to a diagnostic engine.
47 MutableMode = CIMK_None;
51 return CXXMemberInliningMode >= K;
54 static StringRef toString(bool b) { return b ? "true" : "false"; }
56 bool AnalyzerOptions::getBooleanOption(StringRef Name, bool DefaultVal) {
57 // FIXME: We should emit a warning here if the value is something other than
58 // "true", "false", or the empty string (meaning the default value),
59 // but the AnalyzerOptions doesn't have access to a diagnostic engine.
60 StringRef V(Config.GetOrCreateValue(Name, toString(DefaultVal)).getValue());
61 return llvm::StringSwitch<bool>(V)
67 bool AnalyzerOptions::getBooleanOption(llvm::Optional<bool> &V,
71 V = getBooleanOption(Name, DefaultVal);
75 bool AnalyzerOptions::includeTemporaryDtorsInCFG() {
76 return getBooleanOption(IncludeTemporaryDtorsInCFG,
77 "cfg-temporary-dtors",
78 /* Default = */ false);
81 bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
82 return getBooleanOption(InlineCXXStandardLibrary,
83 "c++-stdlib-inlining",
87 bool AnalyzerOptions::mayInlineTemplateFunctions() {
88 return getBooleanOption(InlineTemplateFunctions,
89 "c++-template-inlining",
93 bool AnalyzerOptions::mayInlineObjCMethod() {
94 return getBooleanOption(ObjCInliningMode,
96 /* Default = */ true);
99 bool AnalyzerOptions::shouldPruneNullReturnPaths() {
100 return getBooleanOption(PruneNullReturnPaths,
101 "suppress-null-return-paths",
102 /* Default = */ true);
105 bool AnalyzerOptions::shouldAvoidSuppressingNullArgumentPaths() {
106 return getBooleanOption(AvoidSuppressingNullArgumentPaths,
107 "avoid-suppressing-null-argument-paths",
108 /* Default = */ false);
111 int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) {
112 llvm::SmallString<10> StrBuf;
113 llvm::raw_svector_ostream OS(StrBuf);
116 StringRef V(Config.GetOrCreateValue(Name, OS.str()).getValue());
117 int Res = DefaultVal;
118 bool b = V.getAsInteger(10, Res);
119 assert(!b && "analyzer-config option should be numeric");
124 unsigned AnalyzerOptions::getAlwaysInlineSize() {
125 if (!AlwaysInlineSize.hasValue())
126 AlwaysInlineSize = getOptionAsInteger("ipa-always-inline-size", 3);
127 return AlwaysInlineSize.getValue();
130 unsigned AnalyzerOptions::getGraphTrimInterval() {
131 if (!GraphTrimInterval.hasValue())
132 GraphTrimInterval = getOptionAsInteger("graph-trim-interval", 1000);
133 return GraphTrimInterval.getValue();
136 bool AnalyzerOptions::shouldSynthesizeBodies() {
137 return getBooleanOption("faux-bodies", true);