[cfe-commits] r165041 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h lib/StaticAnalyzer/Core/AnalyzerOptions.cpp test/Analysis/analyzer-config.c test/Analysis/analyzer-config.cpp
Ted Kremenek
kremenek at apple.com
Tue Oct 2 13:31:57 PDT 2012
Author: kremenek
Date: Tue Oct 2 15:31:56 2012
New Revision: 165041
URL: http://llvm.org/viewvc/llvm-project?rev=165041&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/test/Analysis/analyzer-config.c
cfe/trunk/test/Analysis/analyzer-config.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Tue Oct 2 15:31:56 2012
@@ -195,7 +195,7 @@
bool getBooleanOption(StringRef Name, bool DefaultVal);
/// Interprets an option's string value as an integer value.
- int getOptionAsInteger(llvm::StringRef Name, int DefaultVal) const;
+ int getOptionAsInteger(llvm::StringRef Name, int DefaultVal);
public:
/// Returns the option controlling which C++ member functions will be
@@ -243,7 +243,7 @@
// considered to be small enough to always inline.
//
// This is controlled by "ipa-always-inline-size" analyzer-config option.
- unsigned getAlwaysInlineSize() const;
+ unsigned getAlwaysInlineSize();
/// Returns true if the analyzer engine should synthesize fake bodies
/// for well-known functions.
Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Tue Oct 2 15:31:56 2012
@@ -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 @@
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();
}
Modified: cfe/trunk/test/Analysis/analyzer-config.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/analyzer-config.c (original)
+++ cfe/trunk/test/Analysis/analyzer-config.c Tue Oct 2 15:31:56 2012
@@ -7,5 +7,6 @@
// CHECK: [config]
// CHECK-NEXT: cfg-temporary-dtors = false
// CHECK-NEXT: faux-bodies = true
+// CHECK-NEXT: ipa-always-inline-size = 3
// CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 2
+// CHECK-NEXT: num-entries = 3
Modified: cfe/trunk/test/Analysis/analyzer-config.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.cpp?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/analyzer-config.cpp (original)
+++ cfe/trunk/test/Analysis/analyzer-config.cpp Tue Oct 2 15:31:56 2012
@@ -16,5 +16,6 @@
// CHECK-NEXT: c++-template-inlining = true
// CHECK-NEXT: cfg-temporary-dtors = false
// CHECK-NEXT: faux-bodies = true
+// CHECK-NEXT: ipa-always-inline-size = 3
// CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 5
+// CHECK-NEXT: num-entries = 6
More information about the cfe-commits
mailing list