diff options
author | Kristof Umann <kristof.umann@ericsson.com> | 2019-05-17 15:52:13 +0000 |
---|---|---|
committer | Kristof Umann <kristof.umann@ericsson.com> | 2019-05-17 15:52:13 +0000 |
commit | 83cc1b35d1871847bdb959d613abcb8bce15ffb2 (patch) | |
tree | cb59337e488501c5e4dcafdea0248660ec977ca3 /clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | |
parent | 3a02b12439f8ac9e459a34ad4d02d5bcf1a5540b (diff) | |
download | bcm5719-llvm-83cc1b35d1871847bdb959d613abcb8bce15ffb2.tar.gz bcm5719-llvm-83cc1b35d1871847bdb959d613abcb8bce15ffb2.zip |
[analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.
By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.
This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!
Differential Revision: https://reviews.llvm.org/D59195
llvm-svn: 361042
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 1ac1cc214f0..68b2c052305 100644 --- a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -103,8 +103,7 @@ AnalyzerOptions::mayInlineCXXMemberFunction( StringRef AnalyzerOptions::getCheckerStringOption(StringRef CheckerName, StringRef OptionName, - StringRef DefaultVal, - bool SearchInParents ) const { + bool SearchInParents) const { assert(!CheckerName.empty() && "Empty checker name! Make sure the checker object (including it's " "bases!) if fully initialized before calling this function!"); @@ -117,62 +116,66 @@ StringRef AnalyzerOptions::getCheckerStringOption(StringRef CheckerName, return StringRef(I->getValue()); size_t Pos = CheckerName.rfind('.'); if (Pos == StringRef::npos) - return DefaultVal; + break; + CheckerName = CheckerName.substr(0, Pos); } while (!CheckerName.empty() && SearchInParents); - return DefaultVal; + + llvm_unreachable("Unknown checker option! Did you call getChecker*Option " + "with incorrect parameters? User input must've been " + "verified by CheckerRegistry."); + + return ""; } StringRef AnalyzerOptions::getCheckerStringOption(const ento::CheckerBase *C, StringRef OptionName, - StringRef DefaultVal, - bool SearchInParents ) const { + bool SearchInParents) const { return getCheckerStringOption( - C->getTagDescription(), OptionName, DefaultVal, SearchInParents); + C->getTagDescription(), OptionName, SearchInParents); } bool AnalyzerOptions::getCheckerBooleanOption(StringRef CheckerName, StringRef OptionName, - bool DefaultVal, - bool SearchInParents ) const { - // 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. - return llvm::StringSwitch<bool>( + bool SearchInParents) const { + auto Ret = llvm::StringSwitch<llvm::Optional<bool>>( getCheckerStringOption(CheckerName, OptionName, - DefaultVal ? "true" : "false", SearchInParents)) .Case("true", true) .Case("false", false) - .Default(DefaultVal); + .Default(None); + + assert(Ret && + "This option should be either 'true' or 'false', and should've been " + "validated by CheckerRegistry!"); + + return *Ret; } bool AnalyzerOptions::getCheckerBooleanOption(const ento::CheckerBase *C, StringRef OptionName, - bool DefaultVal, - bool SearchInParents ) const { + bool SearchInParents) const { return getCheckerBooleanOption( - C->getTagDescription(), OptionName, DefaultVal, SearchInParents); + C->getTagDescription(), OptionName, SearchInParents); } int AnalyzerOptions::getCheckerIntegerOption(StringRef CheckerName, StringRef OptionName, - int DefaultVal, - bool SearchInParents ) const { - int Ret = DefaultVal; + bool SearchInParents) const { + int Ret = 0; bool HasFailed = getCheckerStringOption(CheckerName, OptionName, - std::to_string(DefaultVal), SearchInParents) .getAsInteger(0, Ret); - assert(!HasFailed && "analyzer-config option should be numeric"); + assert(!HasFailed && + "This option should be numeric, and should've been validated by " + "CheckerRegistry!"); (void)HasFailed; return Ret; } int AnalyzerOptions::getCheckerIntegerOption(const ento::CheckerBase *C, StringRef OptionName, - int DefaultVal, - bool SearchInParents ) const { + bool SearchInParents) const { return getCheckerIntegerOption( - C->getTagDescription(), OptionName, DefaultVal, SearchInParents); + C->getTagDescription(), OptionName, SearchInParents); } |