summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
diff options
context:
space:
mode:
authorKristof Umann <dkszelethus@gmail.com>2018-11-30 20:44:00 +0000
committerKristof Umann <dkszelethus@gmail.com>2018-11-30 20:44:00 +0000
commit549f9cd46f912a1b9e49fa88e348496fe9299382 (patch)
tree0a35dc5634c3772301011d780d190a173702324a /clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
parentbe3f4bd36bc95163088b63063e157e54c99a5b53 (diff)
downloadbcm5719-llvm-549f9cd46f912a1b9e49fa88e348496fe9299382.tar.gz
bcm5719-llvm-549f9cd46f912a1b9e49fa88e348496fe9299382.zip
[analyzer] Evaluate all non-checker config options before analysis
In earlier patches regarding AnalyzerOptions, a lot of effort went into gathering all config options, and changing the interface so that potential misuse can be eliminited. Up until this point, AnalyzerOptions only evaluated an option when it was querried. For example, if we had a "-no-false-positives" flag, AnalyzerOptions would store an Optional field for it that would be None up until somewhere in the code until the flag's getter function is called. However, now that we're confident that we've gathered all configs, we can evaluate off of them before analysis, so we can emit a error on invalid input even if that prticular flag will not matter in that particular run of the analyzer. Another very big benefit of this is that debug.ConfigDumper will now show the value of all configs every single time. Also, almost all options related class have a similar interface, so uniformity is also a benefit. The implementation for errors on invalid input will be commited shorty. Differential Revision: https://reviews.llvm.org/D53692 llvm-svn: 348031
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp100
1 files changed, 9 insertions, 91 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
index 025deda0029..d9b63c209d4 100644
--- a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -49,28 +49,11 @@ AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental /* = false */) {
return Result;
}
-UserModeKind AnalyzerOptions::getUserMode() {
- if (!UserMode.hasValue()) {
- UserMode = getStringOption("mode", "deep");
- }
-
- auto K = llvm::StringSwitch<llvm::Optional<UserModeKind>>(*UserMode)
- .Case("shallow", UMK_Shallow)
- .Case("deep", UMK_Deep)
- .Default(None);
- assert(UserMode.hasValue() && "User mode is invalid.");
- return K.getValue();
-}
-
ExplorationStrategyKind
-AnalyzerOptions::getExplorationStrategy() {
- if (!ExplorationStrategy.hasValue()) {
- ExplorationStrategy = getStringOption("exploration_strategy",
- "unexplored_first_queue");
- }
+AnalyzerOptions::getExplorationStrategy() const {
auto K =
llvm::StringSwitch<llvm::Optional<ExplorationStrategyKind>>(
- *ExplorationStrategy)
+ ExplorationStrategy)
.Case("dfs", ExplorationStrategyKind::DFS)
.Case("bfs", ExplorationStrategyKind::BFS)
.Case("unexplored_first",
@@ -86,18 +69,8 @@ AnalyzerOptions::getExplorationStrategy() {
return K.getValue();
}
-IPAKind AnalyzerOptions::getIPAMode() {
- if (!IPAMode.hasValue()) {
- switch (getUserMode()) {
- case UMK_Shallow:
- IPAMode = getStringOption("ipa", "inlining");
- break;
- case UMK_Deep:
- IPAMode = getStringOption("ipa", "dynamic-bifurcate");
- break;
- }
- }
- auto K = llvm::StringSwitch<llvm::Optional<IPAKind>>(*IPAMode)
+IPAKind AnalyzerOptions::getIPAMode() const {
+ auto K = llvm::StringSwitch<llvm::Optional<IPAKind>>(IPAMode)
.Case("none", IPAK_None)
.Case("basic-inlining", IPAK_BasicInlining)
.Case("inlining", IPAK_Inlining)
@@ -110,17 +83,14 @@ IPAKind AnalyzerOptions::getIPAMode() {
}
bool
-AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind Param) {
- if (!CXXMemberInliningMode.hasValue()) {
- CXXMemberInliningMode = getStringOption("c++-inlining", "destructors");
- }
-
+AnalyzerOptions::mayInlineCXXMemberFunction(
+ CXXInlineableMemberKind Param) const {
if (getIPAMode() < IPAK_Inlining)
return false;
auto K =
llvm::StringSwitch<llvm::Optional<CXXInlineableMemberKind>>(
- *CXXMemberInliningMode)
+ CXXMemberInliningMode)
.Case("constructors", CIMK_Constructors)
.Case("destructors", CIMK_Destructors)
.Case("methods", CIMK_MemberFunctions)
@@ -132,50 +102,6 @@ AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind Param) {
return *K >= Param;
}
-StringRef AnalyzerOptions::getStringOption(StringRef OptionName,
- StringRef DefaultVal) {
- return Config.insert({OptionName, DefaultVal}).first->second;
-}
-
-static StringRef toString(bool B) { return (B ? "true" : "false"); }
-
-template <typename T>
-static StringRef toString(T) = delete;
-
-void AnalyzerOptions::initOption(Optional<StringRef> &V, StringRef Name,
- StringRef DefaultVal) {
- if (V.hasValue())
- return;
-
- V = getStringOption(Name, DefaultVal);
-}
-
-void AnalyzerOptions::initOption(Optional<bool> &V, StringRef Name,
- bool DefaultVal) {
- if (V.hasValue())
- return;
-
- // FIXME: We should emit a warning here if the value is something other than
- // "true", "false", or the empty string (meaning the default value),
- // but the AnalyzerOptions doesn't have access to a diagnostic engine.
- V = llvm::StringSwitch<bool>(getStringOption(Name, toString(DefaultVal)))
- .Case("true", true)
- .Case("false", false)
- .Default(DefaultVal);
-}
-
-void AnalyzerOptions::initOption(Optional<unsigned> &V, StringRef Name,
- unsigned DefaultVal) {
- if (V.hasValue())
- return;
-
- V = DefaultVal;
- bool HasFailed = getStringOption(Name, std::to_string(DefaultVal))
- .getAsInteger(10, *V);
- assert(!HasFailed && "analyzer-config option should be numeric");
- (void)HasFailed;
-}
-
StringRef AnalyzerOptions::getCheckerStringOption(StringRef OptionName,
StringRef DefaultVal,
const CheckerBase *C,
@@ -210,7 +136,8 @@ bool AnalyzerOptions::getCheckerBooleanOption(StringRef Name, bool DefaultVal,
// but the AnalyzerOptions doesn't have access to a diagnostic engine.
assert(C);
return llvm::StringSwitch<bool>(
- getCheckerStringOption(Name, toString(DefaultVal), C, SearchInParents))
+ getCheckerStringOption(Name, DefaultVal ? "true" : "false", C,
+ SearchInParents))
.Case("true", true)
.Case("false", false)
.Default(DefaultVal);
@@ -227,12 +154,3 @@ int AnalyzerOptions::getCheckerIntegerOption(StringRef Name, int DefaultVal,
(void)HasFailed;
return Ret;
}
-
-StringRef AnalyzerOptions::getCTUDir() {
- if (!CTUDir.hasValue()) {
- CTUDir = getStringOption("ctu-dir", "");
- if (!llvm::sys::fs::is_directory(*CTUDir))
- CTUDir = "";
- }
- return CTUDir.getValue();
-}
OpenPOWER on IntegriCloud