aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-10-02 20:31:56 +0000
committerTed Kremenek <kremenek@apple.com>2012-10-02 20:31:56 +0000
commit94bb74cef72a33d77c5d6739abfc0840c781eb8e (patch)
tree5db9d2c02c1aae532b301917c03b7224d5dfd2a8 /lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
parent9e28fe60bbfa5de196ce4aa396210bf10fc5c266 (diff)
Tweak AnalyzerOptions::getOptionAsInteger() to populate the string
table, making it printable with the ConfigDump checker. Along the way, fix a really serious bug where the value was getting parsed from the string in code that was in an assert() call. This means in a Release-Asserts build this code wouldn't work as expected. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165041 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/AnalyzerOptions.cpp')
-rw-r--r--lib/StaticAnalyzer/Core/AnalyzerOptions.cpp28
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
index bb1acb0ce8..6fbd2e1c6d 100644
--- a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -14,6 +14,8 @@
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
using namespace clang;
using namespace llvm;
@@ -102,25 +104,21 @@ bool AnalyzerOptions::shouldPruneNullReturnPaths() {
return *PruneNullReturnPaths;
}
-int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) const {
- std::string OptStr = Config.lookup(Name);
- if (OptStr.empty())
- return DefaultVal;
-
+int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) {
+ llvm::SmallString<10> StrBuf;
+ llvm::raw_svector_ostream OS(StrBuf);
+ OS << DefaultVal;
+
+ StringRef V(Config.GetOrCreateValue(Name, OS.str()).getValue());
int Res = DefaultVal;
- assert(StringRef(OptStr).getAsInteger(10, Res) == false &&
- "analyzer-config option should be numeric.");
-
+ bool b = V.getAsInteger(10, Res);
+ assert(!b && "analyzer-config option should be numeric");
return Res;
}
-unsigned AnalyzerOptions::getAlwaysInlineSize() const {
- if (!AlwaysInlineSize.hasValue()) {
- unsigned DefaultSize = 3;
- const_cast<Optional<unsigned> &>(AlwaysInlineSize) =
- getOptionAsInteger("ipa-always-inline-size", DefaultSize);
- }
-
+unsigned AnalyzerOptions::getAlwaysInlineSize() {
+ if (!AlwaysInlineSize.hasValue())
+ AlwaysInlineSize = getOptionAsInteger("ipa-always-inline-size", 3);
return AlwaysInlineSize.getValue();
}