r345985 - [analyzer][NFC] Fix some incorrect uses of -analyzer-config options

Kristof Umann via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 2 08:48:11 PDT 2018


Author: szelethus
Date: Fri Nov  2 08:48:10 2018
New Revision: 345985

URL: http://llvm.org/viewvc/llvm-project?rev=345985&view=rev
Log:
[analyzer][NFC] Fix some incorrect uses of -analyzer-config options

I'm in the process of refactoring AnalyzerOptions. The main motivation behind
here is to emit warnings if an invalid -analyzer-config option is given from
the command line, and be able to list them all.

In this patch, I found some flags that should've been used as checker options,
or have absolutely no mention of in AnalyzerOptions, or are nonexistent.

- NonLocalizedStringChecker now uses its "AggressiveReport" flag as a checker
    option
- lib/StaticAnalyzer/Frontend/ModelInjector.cpp now accesses the "model-path"
    option through a getter in AnalyzerOptions
- -analyzer-config path-diagnostics-alternate=false is not a thing, I removed it,
- lib/StaticAnalyzer/Checkers/AllocationDiagnostics.cpp and
    lib/StaticAnalyzer/Checkers/AllocationDiagnostics.h are weird, they actually
    only contain an option getter. I deleted them, and fixed RetainCountChecker
    to get it's "leak-diagnostics-reference-allocation" option as a checker option,
- "region-store-small-struct-limit" has a proper getter now.

Differential Revision: https://reviews.llvm.org/D53276

Removed:
    cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.h
Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
    cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
    cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
    cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
    cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
    cfe/trunk/test/Analysis/analyzer-config.c
    cfe/trunk/test/Analysis/analyzer-config.cpp
    cfe/trunk/test/Analysis/cstring-plist.c
    cfe/trunk/test/Analysis/localization-aggressive.m

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=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Fri Nov  2 08:48:10 2018
@@ -328,6 +328,11 @@ private:
   /// \sa shouldElideConstructors
   Optional<bool> ElideConstructors;
 
+  /// \sa getModelPath
+  Optional<StringRef> ModelPath;
+
+  /// \sa getRegionStoreSmallStructLimit
+  Optional<unsigned> RegionStoreSmallStructLimit;
 
   /// A helper function that retrieves option for a given full-qualified
   /// checker name.
@@ -745,6 +750,21 @@ public:
   /// Starting with C++17 some elisions become mandatory, and in these cases
   /// the option will be ignored.
   bool shouldElideConstructors();
+
+  /// The largest number of fields a struct can have and still be
+  /// considered "small".
+  ///
+  /// This is currently used to decide whether or not it is worth "forcing" a
+  /// LazyCompoundVal on bind.
+  ///
+  /// This is controlled by 'region-store-small-struct-limit' option.
+  /// To disable all small-struct-dependent behavior, set the option to "0".
+  unsigned getRegionStoreSmallStructLimit();
+
+  /// The analyzer can inline an alternative implementation written in C at the
+  /// call site if the called function's body is not available. This is a path
+  /// where to look for those alternative implementations (called models)
+  StringRef getModelPath();
 };
 
 using AnalyzerOptionsRef = IntrusiveRefCntPtr<AnalyzerOptions>;

Removed: cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.cpp?rev=345984&view=auto
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.cpp (removed)
@@ -1,24 +0,0 @@
-//=- AllocationDiagnostics.cpp - Config options for allocation diags *- C++ -*-//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Declares the configuration functions for leaks/allocation diagnostics.
-//
-//===--------------------------
-
-#include "AllocationDiagnostics.h"
-
-namespace clang {
-namespace ento {
-
-bool shouldIncludeAllocationSiteInLeakDiagnostics(AnalyzerOptions &AOpts) {
-  return AOpts.getBooleanOption("leak-diagnostics-reference-allocation",
-                                false);
-}
-
-}}

Removed: cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.h?rev=345984&view=auto
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.h (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/AllocationDiagnostics.h (removed)
@@ -1,31 +0,0 @@
-//=--- AllocationDiagnostics.h - Config options for allocation diags *- C++ -*-//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Declares the configuration functions for leaks/allocation diagnostics.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_ALLOCATIONDIAGNOSTICS_H
-#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_ALLOCATIONDIAGNOSTICS_H
-
-#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
-
-namespace clang { namespace ento {
-
-/// Returns true if leak diagnostics should directly reference
-/// the allocatin site (where possible).
-///
-/// The default is false.
-///
-bool shouldIncludeAllocationSiteInLeakDiagnostics(AnalyzerOptions &AOpts);
-
-}}
-
-#endif
-

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Fri Nov  2 08:48:10 2018
@@ -3,7 +3,6 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_clang_library(clangStaticAnalyzerCheckers
-  AllocationDiagnostics.cpp
   AnalysisOrderChecker.cpp
   AnalyzerStatsChecker.cpp
   ArrayBoundChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp Fri Nov  2 08:48:10 2018
@@ -1398,7 +1398,8 @@ void ento::registerNonLocalizedStringChe
   NonLocalizedStringChecker *checker =
       mgr.registerChecker<NonLocalizedStringChecker>();
   checker->IsAggressive =
-      mgr.getAnalyzerOptions().getBooleanOption("AggressiveReport", false);
+      mgr.getAnalyzerOptions().getBooleanOption("AggressiveReport", false,
+                                                checker);
 }
 
 void ento::registerEmptyLocalizationContextChecker(CheckerManager &mgr) {

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp Fri Nov  2 08:48:10 2018
@@ -1393,5 +1393,12 @@ void RetainCountChecker::printState(raw_
 //===----------------------------------------------------------------------===//
 
 void ento::registerRetainCountChecker(CheckerManager &Mgr) {
-  Mgr.registerChecker<RetainCountChecker>(Mgr.getAnalyzerOptions());
+  auto *Chk = Mgr.registerChecker<RetainCountChecker>();
+
+  AnalyzerOptions &Options = Mgr.getAnalyzerOptions();
+
+  Chk->IncludeAllocationLine = Options.getBooleanOption(
+                           "leak-diagnostics-reference-allocation", false, Chk);
+  Chk->ShouldCheckOSObjectRetainCount = Options.getBooleanOption(
+                                                   "CheckOSObject", true, Chk);
 }

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h Fri Nov  2 08:48:10 2018
@@ -16,7 +16,6 @@
 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H
 
 #include "../ClangSACheckers.h"
-#include "../AllocationDiagnostics.h"
 #include "RetainCountDiagnostics.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
@@ -266,25 +265,18 @@ class RetainCountChecker
   mutable std::unique_ptr<RetainSummaryManager> Summaries;
   mutable SummaryLogTy SummaryLog;
 
-  AnalyzerOptions &Options;
   mutable bool ShouldResetSummaryLog;
 
+public:
   /// Optional setting to indicate if leak reports should include
   /// the allocation line.
-  mutable bool IncludeAllocationLine;
+  bool IncludeAllocationLine;
+  bool ShouldCheckOSObjectRetainCount;
 
-public:
-  RetainCountChecker(AnalyzerOptions &Options)
-      : Options(Options), ShouldResetSummaryLog(false),
-        IncludeAllocationLine(
-            shouldIncludeAllocationSiteInLeakDiagnostics(Options)) {}
+  RetainCountChecker() : ShouldResetSummaryLog(false) {}
 
   ~RetainCountChecker() override { DeleteContainerSeconds(DeadSymbolTags); }
 
-  bool shouldCheckOSObjectRetainCount() const {
-    return Options.getBooleanOption("CheckOSObject", true, this);
-  }
-
   void checkEndAnalysis(ExplodedGraph &G, BugReporter &BR,
                         ExprEngine &Eng) const {
     // FIXME: This is a hack to make sure the summary log gets cleared between
@@ -339,7 +331,7 @@ public:
     bool ARCEnabled = (bool)Ctx.getLangOpts().ObjCAutoRefCount;
     if (!Summaries) {
       Summaries.reset(new RetainSummaryManager(
-          Ctx, ARCEnabled, shouldCheckOSObjectRetainCount()));
+          Ctx, ARCEnabled, ShouldCheckOSObjectRetainCount));
     } else {
       assert(Summaries->isARCEnabled() == ARCEnabled);
     }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Fri Nov  2 08:48:10 2018
@@ -503,8 +503,21 @@ bool AnalyzerOptions::naiveCTUEnabled()
   return NaiveCTU.getValue();
 }
 
+unsigned AnalyzerOptions::getRegionStoreSmallStructLimit() {
+  if (!RegionStoreSmallStructLimit.hasValue())
+    RegionStoreSmallStructLimit =
+                       getOptionAsInteger("region-store-small-struct-limit", 2);
+  return RegionStoreSmallStructLimit.getValue();
+}
+
 StringRef AnalyzerOptions::getCTUIndexName() {
   if (!CTUIndexName.hasValue())
     CTUIndexName = getOptionAsString("ctu-index-name", "externalFnMap.txt");
   return CTUIndexName.getValue();
 }
+
+StringRef AnalyzerOptions::getModelPath() {
+  if (!ModelPath.hasValue())
+    ModelPath = getOptionAsString("model-path", "");
+  return ModelPath.getValue();
+}

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Fri Nov  2 08:48:10 2018
@@ -350,7 +350,7 @@ public:
     if (SubEngine *Eng = StateMgr.getOwningEngine()) {
       AnalyzerOptions &Options = Eng->getAnalysisManager().options;
       SmallStructLimit =
-        Options.getOptionAsInteger("region-store-small-struct-limit", 2);
+        Options.getRegionStoreSmallStructLimit();
     }
   }
 

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp Fri Nov  2 08:48:10 2018
@@ -48,7 +48,7 @@ void ModelInjector::onBodySynthesis(cons
   FileID mainFileID = SM.getMainFileID();
 
   AnalyzerOptionsRef analyzerOpts = CI.getAnalyzerOpts();
-  llvm::StringRef modelPath = analyzerOpts->Config["model-path"];
+  llvm::StringRef modelPath = analyzerOpts->getModelPath();
 
   llvm::SmallString<128> fileName;
 

Modified: cfe/trunk/test/Analysis/analyzer-config.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/analyzer-config.c (original)
+++ cfe/trunk/test/Analysis/analyzer-config.c Fri Nov  2 08:48:10 2018
@@ -26,7 +26,6 @@ void foo() {
 // CHECK-NEXT: inline-lambdas = true
 // CHECK-NEXT: ipa = dynamic-bifurcate
 // CHECK-NEXT: ipa-always-inline-size = 3
-// CHECK-NEXT: leak-diagnostics-reference-allocation = false
 // CHECK-NEXT: max-inlinable-size = 100
 // CHECK-NEXT: max-nodes = 225000
 // CHECK-NEXT: max-times-inline-large = 32
@@ -37,4 +36,4 @@ void foo() {
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 25
+// CHECK-NEXT: num-entries = 24

Modified: cfe/trunk/test/Analysis/analyzer-config.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.cpp?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/analyzer-config.cpp (original)
+++ cfe/trunk/test/Analysis/analyzer-config.cpp Fri Nov  2 08:48:10 2018
@@ -41,7 +41,6 @@ public:
 // CHECK-NEXT: inline-lambdas = true
 // CHECK-NEXT: ipa = dynamic-bifurcate
 // CHECK-NEXT: ipa-always-inline-size = 3
-// CHECK-NEXT: leak-diagnostics-reference-allocation = false
 // CHECK-NEXT: max-inlinable-size = 100
 // CHECK-NEXT: max-nodes = 225000
 // CHECK-NEXT: max-times-inline-large = 32
@@ -52,4 +51,4 @@ public:
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 32
+// CHECK-NEXT: num-entries = 31

Modified: cfe/trunk/test/Analysis/cstring-plist.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cstring-plist.c?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/cstring-plist.c (original)
+++ cfe/trunk/test/Analysis/cstring-plist.c Fri Nov  2 08:48:10 2018
@@ -1,5 +1,8 @@
 // RUN: rm -f %t
-// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=core,unix.Malloc,unix.cstring.NullArg -analyzer-disable-checker=alpha.unix.cstring.OutOfBounds -analyzer-output=plist -analyzer-config path-diagnostics-alternate=false -o %t %s
+// RUN: %clang_analyze_cc1 -fblocks \
+// RUN:   -analyzer-checker=core,unix.Malloc,unix.cstring.NullArg \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.OutOfBounds \
+// RUN:   -analyzer-output=plist -o %t %s
 // RUN: FileCheck -input-file %t %s
 
 typedef __typeof(sizeof(int)) size_t;

Modified: cfe/trunk/test/Analysis/localization-aggressive.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/localization-aggressive.m?rev=345985&r1=345984&r2=345985&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/localization-aggressive.m (original)
+++ cfe/trunk/test/Analysis/localization-aggressive.m Fri Nov  2 08:48:10 2018
@@ -1,6 +1,10 @@
 // RUN: %clang_cc1 -fblocks -x objective-c-header -emit-pch -o %t.pch %S/Inputs/localization-pch.h
 
-// RUN: %clang_analyze_cc1 -fblocks -analyzer-store=region  -analyzer-checker=optin.osx.cocoa.localizability.NonLocalizedStringChecker -analyzer-checker=optin.osx.cocoa.localizability.EmptyLocalizationContextChecker -include-pch %t.pch -verify  -analyzer-config AggressiveReport=true %s
+// RUN: %clang_analyze_cc1 -fblocks -analyzer-store=region \
+// RUN:   -analyzer-config optin.osx.cocoa.localizability.NonLocalizedStringChecker:AggressiveReport=true \
+// RUN:   -analyzer-checker=optin.osx.cocoa.localizability.NonLocalizedStringChecker \
+// RUN:   -analyzer-checker=optin.osx.cocoa.localizability.EmptyLocalizationContextChecker \
+// RUN:   -include-pch %t.pch -verify  %s
 
 // These declarations were reduced using Delta-Debugging from Foundation.h
 // on Mac OS X.




More information about the cfe-commits mailing list