[cfe-commits] r164954 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h lib/StaticAnalyzer/Core/AnalysisManager.cpp lib/StaticAnalyzer/Core/AnalyzerOptions.cpp lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp test/Analysis/analyzer-config.c
Ted Kremenek
kremenek at apple.com
Mon Oct 1 11:28:19 PDT 2012
Author: kremenek
Date: Mon Oct 1 13:28:19 2012
New Revision: 164954
URL: http://llvm.org/viewvc/llvm-project?rev=164954&view=rev
Log:
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.
Added:
cfe/trunk/test/Analysis/analyzer-config.c
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.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=164954&r1=164953&r2=164954&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Mon Oct 1 13:28:19 2012
@@ -192,7 +192,7 @@
///
/// 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 @@
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 @@
///
/// 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 @@
/// Returns true if the analyzer engine should synthesize fake bodies
/// for well-known functions.
- bool shouldSynthesizeBodies() const;
+ bool shouldSynthesizeBodies();
public:
AnalyzerOptions() : CXXMemberInliningMode() {
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h?rev=164954&r1=164953&r2=164954&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h Mon Oct 1 13:28:19 2012
@@ -42,7 +42,7 @@
CheckerManager *CheckerMgr;
public:
- const AnalyzerOptions &options;
+ AnalyzerOptions &options;
AnalysisManager(ASTContext &ctx,DiagnosticsEngine &diags,
const LangOptions &lang,
@@ -50,7 +50,7 @@
StoreManagerCreator storemgr,
ConstraintManagerCreator constraintmgr,
CheckerManager *checkerMgr,
- const AnalyzerOptions &Options);
+ AnalyzerOptions &Options);
~AnalysisManager();
Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp?rev=164954&r1=164953&r2=164954&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp Mon Oct 1 13:28:19 2012
@@ -20,7 +20,7 @@
StoreManagerCreator storemgr,
ConstraintManagerCreator constraintmgr,
CheckerManager *checkerMgr,
- const AnalyzerOptions &Options)
+ AnalyzerOptions &Options)
: AnaCtxMgr(Options.UnoptimizedCFG,
/*AddImplicitDtors=*/true,
/*AddInitializers=*/true,
Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=164954&r1=164953&r2=164954&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Mon Oct 1 13:28:19 2012
@@ -48,17 +48,20 @@
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 @@
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 @@
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 @@
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 @@
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 @@
return AlwaysInlineSize.getValue();
}
-bool AnalyzerOptions::shouldSynthesizeBodies() const {
+bool AnalyzerOptions::shouldSynthesizeBodies() {
return getBooleanOption("faux-bodies", true);
}
Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=164954&r1=164953&r2=164954&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Mon Oct 1 13:28:19 2012
@@ -385,7 +385,7 @@
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()) {
Added: cfe/trunk/test/Analysis/analyzer-config.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=164954&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/analyzer-config.c (added)
+++ cfe/trunk/test/Analysis/analyzer-config.c Mon Oct 1 13:28:19 2012
@@ -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
More information about the cfe-commits
mailing list