From 4a5b35eeec9412fca288ff8e7d51fcc6f473b319 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 1 Oct 2012 18:28:19 +0000 Subject: [PATCH] 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. llvm-svn: 164954 --- .../clang/StaticAnalyzer/Core/AnalyzerOptions.h | 14 ++++++------ .../Core/PathSensitive/AnalysisManager.h | 4 ++-- clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp | 2 +- clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 25 ++++++++++++---------- .../Core/ExprEngineCallAndReturn.cpp | 2 +- clang/test/Analysis/analyzer-config.c | 11 ++++++++++ 6 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 clang/test/Analysis/analyzer-config.c diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h index 7657736..d6dee64 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/clang/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/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h index 2ec301f..9038ae5 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h +++ b/clang/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/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp b/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp index 09a0deb..011d4c0 100644 --- a/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp +++ b/clang/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/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 1ffd105..7e6013b 100644 --- a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/clang/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(Config.lookup(Name)) - .Case("true", true) - .Case("false", false) - .Default(DefaultVal); + StringRef V(Config.GetOrCreateValue(Name, toString(DefaultVal)).getValue()); + return llvm::StringSwitch(V) + .Case("true", true) + .Case("false", false) + .Default(DefaultVal); } -bool AnalyzerOptions::includeTemporaryDtorsInCFG() const { +bool AnalyzerOptions::includeTemporaryDtorsInCFG() { if (!IncludeTemporaryDtorsInCFG.hasValue()) const_cast &>(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 &>(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 &>(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 &>(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 &>(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/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp index 2e460b7..535de9f 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp +++ b/clang/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/clang/test/Analysis/analyzer-config.c b/clang/test/Analysis/analyzer-config.c new file mode 100644 index 0000000..7a37a51 --- /dev/null +++ b/clang/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 -- 2.7.4