aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-10-01 18:28:19 +0000
committerTed Kremenek <kremenek@apple.com>2012-10-01 18:28:19 +0000
commit622b6fb0a1d280c16e135c7e427b79cafffbde1f (patch)
treeed546fdae1b950bb96b131078813e1ca63e05f3b
parent43e8ef0b90dffcf9bda4fc2d3e6b21feb1e15bfb (diff)
Have AnalyzerOptions::getBooleanOption() stick the matching config
string in the config table so that it can be dumped as part of the config dumper. Add a test to show that these options are sticking and can be cross-checked using FileCheck. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164954 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/StaticAnalyzer/Core/AnalyzerOptions.h14
-rw-r--r--include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h4
-rw-r--r--lib/StaticAnalyzer/Core/AnalysisManager.cpp2
-rw-r--r--lib/StaticAnalyzer/Core/AnalyzerOptions.cpp25
-rw-r--r--lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp2
-rw-r--r--test/Analysis/analyzer-config.c11
6 files changed, 36 insertions, 22 deletions
diff --git a/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index 7657736c2b..d6dee64e70 100644
--- a/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -192,7 +192,7 @@ private:
///
/// Accepts the strings "true" and "false".
/// If an option value is not provided, returns the given \p DefaultVal.
- bool getBooleanOption(StringRef Name, bool DefaultVal) const;
+ bool getBooleanOption(StringRef Name, bool DefaultVal);
/// Interprets an option's string value as an integer value.
int getOptionAsInteger(llvm::StringRef Name, int DefaultVal) const;
@@ -207,27 +207,27 @@ public:
bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const;
/// Returns true if ObjectiveC inlining is enabled, false otherwise.
- bool mayInlineObjCMethod() const;
+ bool mayInlineObjCMethod();
/// Returns whether or not the destructors for C++ temporary objects should
/// be included in the CFG.
///
/// This is controlled by the 'cfg-temporary-dtors' config option, which
/// accepts the values "true" and "false".
- bool includeTemporaryDtorsInCFG() const;
+ bool includeTemporaryDtorsInCFG();
/// Returns whether or not C++ standard library functions may be considered
/// for inlining.
///
/// This is controlled by the 'c++-stdlib-inlining' config option, which
/// accepts the values "true" and "false".
- bool mayInlineCXXStandardLibrary() const;
+ bool mayInlineCXXStandardLibrary();
/// Returns whether or not templated functions may be considered for inlining.
///
/// This is controlled by the 'c++-template-inlining' config option, which
/// accepts the values "true" and "false".
- bool mayInlineTemplateFunctions() const;
+ bool mayInlineTemplateFunctions();
/// Returns whether or not paths that go through null returns should be
/// suppressed.
@@ -237,7 +237,7 @@ public:
///
/// This is controlled by the 'suppress-null-return-paths' config option,
/// which accepts the values "true" and "false".
- bool shouldPruneNullReturnPaths() const;
+ bool shouldPruneNullReturnPaths();
// Returns the size of the functions (in basic blocks), which should be
// considered to be small enough to always inline.
@@ -247,7 +247,7 @@ public:
/// Returns true if the analyzer engine should synthesize fake bodies
/// for well-known functions.
- bool shouldSynthesizeBodies() const;
+ bool shouldSynthesizeBodies();
public:
AnalyzerOptions() : CXXMemberInliningMode() {
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h b/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
index 2ec301f474..9038ae5276 100644
--- a/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
+++ b/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
@@ -42,7 +42,7 @@ class AnalysisManager : public BugReporterData {
CheckerManager *CheckerMgr;
public:
- const AnalyzerOptions &options;
+ AnalyzerOptions &options;
AnalysisManager(ASTContext &ctx,DiagnosticsEngine &diags,
const LangOptions &lang,
@@ -50,7 +50,7 @@ public:
StoreManagerCreator storemgr,
ConstraintManagerCreator constraintmgr,
CheckerManager *checkerMgr,
- const AnalyzerOptions &Options);
+ AnalyzerOptions &Options);
~AnalysisManager();
diff --git a/lib/StaticAnalyzer/Core/AnalysisManager.cpp b/lib/StaticAnalyzer/Core/AnalysisManager.cpp
index 09a0debaac..011d4c09a2 100644
--- a/lib/StaticAnalyzer/Core/AnalysisManager.cpp
+++ b/lib/StaticAnalyzer/Core/AnalysisManager.cpp
@@ -20,7 +20,7 @@ AnalysisManager::AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
StoreManagerCreator storemgr,
ConstraintManagerCreator constraintmgr,
CheckerManager *checkerMgr,
- const AnalyzerOptions &Options)
+ AnalyzerOptions &Options)
: AnaCtxMgr(Options.UnoptimizedCFG,
/*AddImplicitDtors=*/true,
/*AddInitializers=*/true,
diff --git a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
index 1ffd105766..7e6013bba8 100644
--- a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -48,17 +48,20 @@ AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const {
return CXXMemberInliningMode >= K;
}
-bool AnalyzerOptions::getBooleanOption(StringRef Name, bool DefaultVal) const {
+static StringRef toString(bool b) { return b ? "true" : "false"; }
+
+bool AnalyzerOptions::getBooleanOption(StringRef Name, bool DefaultVal) {
// 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>(Config.lookup(Name))
- .Case("true", true)
- .Case("false", false)
- .Default(DefaultVal);
+ StringRef V(Config.GetOrCreateValue(Name, toString(DefaultVal)).getValue());
+ return llvm::StringSwitch<bool>(V)
+ .Case("true", true)
+ .Case("false", false)
+ .Default(DefaultVal);
}
-bool AnalyzerOptions::includeTemporaryDtorsInCFG() const {
+bool AnalyzerOptions::includeTemporaryDtorsInCFG() {
if (!IncludeTemporaryDtorsInCFG.hasValue())
const_cast<llvm::Optional<bool> &>(IncludeTemporaryDtorsInCFG) =
getBooleanOption("cfg-temporary-dtors", /*Default=*/false);
@@ -66,7 +69,7 @@ bool AnalyzerOptions::includeTemporaryDtorsInCFG() const {
return *IncludeTemporaryDtorsInCFG;
}
-bool AnalyzerOptions::mayInlineCXXStandardLibrary() const {
+bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
if (!InlineCXXStandardLibrary.hasValue())
const_cast<llvm::Optional<bool> &>(InlineCXXStandardLibrary) =
getBooleanOption("c++-stdlib-inlining", /*Default=*/true);
@@ -74,7 +77,7 @@ bool AnalyzerOptions::mayInlineCXXStandardLibrary() const {
return *InlineCXXStandardLibrary;
}
-bool AnalyzerOptions::mayInlineTemplateFunctions() const {
+bool AnalyzerOptions::mayInlineTemplateFunctions() {
if (!InlineTemplateFunctions.hasValue())
const_cast<llvm::Optional<bool> &>(InlineTemplateFunctions) =
getBooleanOption("c++-template-inlining", /*Default=*/true);
@@ -82,7 +85,7 @@ bool AnalyzerOptions::mayInlineTemplateFunctions() const {
return *InlineTemplateFunctions;
}
-bool AnalyzerOptions::mayInlineObjCMethod() const {
+bool AnalyzerOptions::mayInlineObjCMethod() {
if (!ObjCInliningMode.hasValue())
const_cast<llvm::Optional<bool> &>(ObjCInliningMode) =
getBooleanOption("objc-inlining", /*Default=*/true);
@@ -90,7 +93,7 @@ bool AnalyzerOptions::mayInlineObjCMethod() const {
return *ObjCInliningMode;
}
-bool AnalyzerOptions::shouldPruneNullReturnPaths() const {
+bool AnalyzerOptions::shouldPruneNullReturnPaths() {
if (!PruneNullReturnPaths.hasValue())
const_cast<llvm::Optional<bool> &>(PruneNullReturnPaths) =
getBooleanOption("suppress-null-return-paths", /*Default=*/true);
@@ -120,6 +123,6 @@ unsigned AnalyzerOptions::getAlwaysInlineSize() const {
return AlwaysInlineSize.getValue();
}
-bool AnalyzerOptions::shouldSynthesizeBodies() const {
+bool AnalyzerOptions::shouldSynthesizeBodies() {
return getBooleanOption("faux-bodies", true);
}
diff --git a/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
index 2e460b79e7..535de9fd98 100644
--- a/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ b/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -385,7 +385,7 @@ bool ExprEngine::inlineCall(const CallEvent &Call, const Decl *D,
const StackFrameContext *CallerSFC = CurLC->getCurrentStackFrame();
const LocationContext *ParentOfCallee = 0;
- const AnalyzerOptions &Opts = getAnalysisManager().options;
+ AnalyzerOptions &Opts = getAnalysisManager().options;
// FIXME: Refactor this check into a hypothetical CallEvent::canInline.
switch (Call.getKind()) {
diff --git a/test/Analysis/analyzer-config.c b/test/Analysis/analyzer-config.c
new file mode 100644
index 0000000000..7a37a51b8e
--- /dev/null
+++ b/test/Analysis/analyzer-config.c
@@ -0,0 +1,11 @@
+// RUN: %clang --analyze %s -o /dev/null -Xclang -analyzer-checker=debug.ConfigDumper > %t 2>&1
+// RUN: FileCheck --input-file=%t %s
+
+void bar() {}
+void foo() { bar(); }
+
+// CHECK: [config]
+// CHECK-NEXT: cfg-temporary-dtors = false
+// CHECK-NEXT: faux-bodies = true
+// CHECK-NEXT: [stats]
+// CHECK-NEXT: num-entries = 2