]> granicus.if.org Git - clang/commitdiff
Have AnalyzerOptions::getBooleanOption() stick the matching config
authorTed Kremenek <kremenek@apple.com>
Mon, 1 Oct 2012 18:28:19 +0000 (18:28 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 1 Oct 2012 18:28:19 +0000 (18:28 +0000)
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

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 [new file with mode: 0644]

index 7657736c2bd2bd98dd5a1b580944786cd221fe9b..d6dee64e705547f8c684cb71b9665718ee5033ac 100644 (file)
@@ -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() {
index 2ec301f474242d8e84cfc91c66d79e5ee48a9b18..9038ae5276a70bb579ab3f85439a88666403038a 100644 (file)
@@ -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();
   
index 09a0debaace0ab02ce6ebf028f350443053d3a07..011d4c09a23fef75f4fc45a2164e5d15890f5983 100644 (file)
@@ -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,
index 1ffd10576656dbef7d63d0d3344f3b14aa9b634c..7e6013bba8a4e898f6c71fe3eff1516c03e77830 100644 (file)
@@ -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);
 }
index 2e460b79e7dca8b44b8739cdb1957f04eca99900..535de9fd9814044e76a8c38ff89b078e1f8f7711 100644 (file)
@@ -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 (file)
index 0000000..7a37a51
--- /dev/null
@@ -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