Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, rnkovacs, 
baloghadamsoftware.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, kristof.beyls, whisperity, javed.absar.
Herald added a project: clang.
Szelethus added a parent revision: D57855: [analyzer] Reimplement checker 
options.

Title says it all, here is how it looks like locally:

  OVERVIEW: Clang Static Analyzer Checker Option List
  
  USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config 
<OPTION1=VALUE,OPTION2=VALUE,...>
  
         clang -cc1 [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, 
-analyzer-config OPTION2=VALUE, ...
  
         clang [CLANG_OPTIONS] -Xclang -analyzer-config 
-Xclang<OPTION1=VALUE,OPTION2=VALUE,...>
  
         clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang OPTION1=VALUE, 
-Xclang -analyzer-config -Xclang OPTION2=VALUE, ...
  
  OPTIONS:
  
    alpha.clone.CloneChecker:MinimumCloneComplexity   (int) Ensures that every 
clone has at least
                                                      the given complexity. 
Complexity is here
                                                      defined as the total 
amount of children
                                                      of a statement. This 
constraint assumes
                                                      the first statement in 
the group is representative
                                                      for all other statements 
in the group in
                                                      terms of complexity. 
(default: 50)
  
    alpha.clone.CloneChecker:ReportNormalClones       (bool) Report all clones, 
even less suspicious
                                                      ones. (default: true)
  
    alpha.clone.CloneChecker:IgnoredFilesPattern      (string) If supplied, the 
checker wont analyze
                                                      files with a filename 
that matches the given
                                                      pattern. (default: "")
  
    alpha.cplusplus.UninitializedObject:Pedantic      (bool) If set to false, 
the checker won't
                                                      emit warnings for objects 
that don't have
                                                      at least one initialized 
field. (default: false)
  
    alpha.cplusplus.UninitializedObject:NotesAsWarnings
                                                      (bool) If set to true, 
the checker will
                                                      emit a warning for each 
uninitalized field,
                                                      as opposed to emitting 
one warning per constructor
                                                      call, and listing the 
uninitialized fields
                                                      that belongs to it in 
notes. (default: false)
  
    alpha.cplusplus.UninitializedObject:CheckPointeeInitialization
                                                      (bool) If set to false, 
the checker will
                                                      not analyze the pointee 
of pointer/reference
                                                      fields, and will only 
check whether the
                                                      object itself is 
initialized. (default: false)
  
    alpha.cplusplus.UninitializedObject:IgnoreRecordsWithField
                                                      (string) If supplied, the 
checker will not
                                                      analyze structures that 
have a field with
                                                      a name or type name that 
matches the given
                                                      pattern. (default: "")
  
    alpha.cplusplus.UninitializedObject:IgnoreGuardedFields
                                                      (bool) If set to true, 
the checker will
                                                      analyze _syntactically_ 
whether the found
                                                      uninitialized object is 
used without a preceding
                                                      assert call. Defaults to 
false. (default: false)
  
    alpha.security.MmapWriteExec:MmapProtExec         (int) Specifies the value 
of PROT_EXEC 
                                                      (default: 0x04)
  
    alpha.security.MmapWriteExec:MmapProtRead         (int) Specifies the value 
of PROT_READ 
                                                      (default: 0x01)
  
    cplusplus.Move:WarnOn                             (string) In 
non-aggressive mode, only warn
                                                      on use-after-move of 
local variables (or
                                                      local rvalue references) 
and of STL objects.
                                                      The former is possible 
because local variables
                                                      (or local rvalue 
references) are not tempting
                                                      their user to re-use the 
storage. The latter
                                                      is possible because STL 
objects are known
                                                      to end up in a valid but 
unspecified state
                                                      after the move and their 
state-reset methods
                                                      are also known, which 
allows us to predict
                                                      precisely when 
use-after-move is invalid.
                                                      Some STL objects are 
known to conform to
                                                      additional contracts 
after move, so they
                                                      are not tracked. However, 
smart pointers
                                                      specifically are tracked 
because we can
                                                      perform extra checking 
over them. In aggressive
                                                      mode, warn on any 
use-after-move because
                                                      the user has 
intentionally asked us to completely
                                                      eliminate use-after-move 
in his code. Values:
                                                      "KnownsOnly", 
"KnownsAndLocals", "All". 
                                                      (default: KnownsAndLocals)
  
    debug.AnalysisOrder:PreStmtCastExpr               (bool) (default: false)
  
    debug.AnalysisOrder:PostStmtCastExpr              (bool) (default: false)
  
    debug.AnalysisOrder:PreStmtArraySubscriptExpr     (bool) (default: false)
  
    debug.AnalysisOrder:PostStmtArraySubscriptExpr    (bool) (default: false)
  
    debug.AnalysisOrder:PreStmtCXXNewExpr             (bool) (default: false)
  
    debug.AnalysisOrder:PostStmtCXXNewExpr            (bool) (default: false)
  
    debug.AnalysisOrder:PreStmtOffsetOfExpr           (bool) (default: false)
  
    debug.AnalysisOrder:PostStmtOffsetOfExpr          (bool) (default: false)
  
    debug.AnalysisOrder:PreCall                       (bool) (default: false)
  
    debug.AnalysisOrder:PostCall                      (bool) (default: false)
  
    debug.AnalysisOrder:EndFunction                   (bool) (default: false)
  
    debug.AnalysisOrder:NewAllocator                  (bool) (default: false)
  
    debug.AnalysisOrder:Bind                          (bool) (default: false)
  
    debug.AnalysisOrder:LiveSymbols                   (bool) (default: false)
  
    debug.AnalysisOrder:RegionChanges                 (bool) (default: false)
  
    debug.AnalysisOrder:*                             (bool) Enables all 
callbacks. (default: false)
  
    optin.cplusplus.VirtualCall:PureOnly              (bool) Whether to only 
report calls to pure
                                                      virtual methods. 
(default: false)
  
    optin.osx.cocoa.localizability.NonLocalizedStringChecker:AggressiveReport
                                                      (bool) Marks a string 
being returned by
                                                      any call as localized if 
it is in LocStringFunctions
                                                      (LSF) or the function is 
annotated. Otherwise,
                                                      we mark it as 
NonLocalized (Aggressive)
                                                      or NonLocalized only if 
it is not backed
                                                      by a SymRegion 
(Non-Aggressive), basically
                                                      leaving only string 
literals as NonLocalized. 
                                                      (default: false)
  
    optin.performance.Padding:AllowedPad              (int) Reports are only 
generated if the
                                                      excessive padding exceeds 
'AllowedPad' in
                                                      bytes. (default: 24)
  
    osx.NumberObjectConversion:Pedantic               (bool) Enables detection 
of more conversion
                                                      patterns (which are most 
likely more harmless,
                                                      and therefore are more 
likely to produce
                                                      false positives). 
(default: false)
  
    osx.cocoa.RetainCount:leak-diagnostics-reference-allocation
                                                      (bool) Reports are only 
generated if the
                                                      excessive padding exceeds 
'AllowedPad' in
                                                      bytes. (default: false)
  
    osx.cocoa.RetainCount:CheckOSObject               (bool) Reports are only 
generated if the
                                                      excessive padding exceeds 
'AllowedPad' in
                                                      bytes. (default: true)
  
    osx.cocoa.RetainCount:TrackNSCFStartParam         (bool) (default: false)
  
    unix.DynamicMemoryModeling:Optimistic             (bool) In set to false, 
the checker assumes
                                                      that it does not know 
which functions might
                                                      free the memory. 
(default: false)


Repository:
  rC Clang

https://reviews.llvm.org/D57858

Files:
  include/clang/Driver/CC1Options.td
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
  include/clang/StaticAnalyzer/Frontend/FrontendActions.h
  lib/Frontend/CompilerInvocation.cpp
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
  lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
  test/Analysis/analyzer-checker-option-help.c

Index: test/Analysis/analyzer-checker-option-help.c
===================================================================
--- /dev/null
+++ test/Analysis/analyzer-checker-option-help.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -analyzer-checker-option-help 2>&1 | FileCheck %s
+
+// CHECK: OVERVIEW: Clang Static Analyzer Checker Option List
+//
+// CHECK: USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>
+//
+// CHECK:        clang -cc1 [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE,
+// CHECK-SAME:     -analyzer-config OPTION2=VALUE, ...
+//
+// CHECK:        clang [CLANG_OPTIONS] -Xclang -analyzer-config
+// CHECK-SAME:     -Xclang<OPTION1=VALUE,OPTION2=VALUE,...>
+//
+// CHECK:        clang [CLANG_OPTIONS] -Xclang -analyzer-config
+// CHECK-SAME:     -Xclang OPTION1=VALUE, -Xclang -analyzer-config
+// CHECK-SAME:     -Xclang OPTION2=VALUE, ...
+//
+// CHECK: OPTIONS:
+//
+// CHECK:   alpha.clone.CloneChecker:MinimumCloneComplexity  
+// CHECK-SAME:   (int) Ensures that every clone has at least
+// CHECK:        the given complexity. Complexity is here
+// CHECK:        defined as the total amount of children
+// CHECK:        of a statement. This constraint assumes
+// CHECK:        the first statement in the group is representative
+// CHECK:        for all other statements in the group in
+// CHECK:        terms of complexity. (default: 50)
Index: lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===================================================================
--- lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -427,3 +427,57 @@
   for (const auto *i : enabledCheckers)
     out << i->FullName << '\n';
 }
+
+void CheckerRegistry::printCheckerOptionList(raw_ostream &out) const {
+  out << "OVERVIEW: Clang Static Analyzer Checker Option List\n\n";
+  out << "USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config "
+                                        "<OPTION1=VALUE,OPTION2=VALUE,...>\n\n";
+  out << "       clang -cc1 [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, "
+                                      "-analyzer-config OPTION2=VALUE, ...\n\n";
+  out << "       clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang"
+                                        "<OPTION1=VALUE,OPTION2=VALUE,...>\n\n";
+  out << "       clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang "
+                              "OPTION1=VALUE, -Xclang -analyzer-config -Xclang "
+                              "OPTION2=VALUE, ...\n\n";
+  out << "OPTIONS:\n\n";
+
+  constexpr size_t MinLineWidth = 90;
+  constexpr size_t PadForOpt = 2;
+  constexpr size_t OptionWidth = 50;
+  constexpr size_t PadForDesc = PadForOpt + OptionWidth;
+  static_assert(MinLineWidth > PadForDesc, "MinLineWidth must be greater!");
+
+  llvm::formatted_raw_ostream FOut(out);
+
+  for (const CheckerInfo &Checker : Checkers) {
+    for (const CmdLineOption &Option : Checker.CmdLineOptions) {
+      FOut.PadToColumn(PadForOpt) << Checker.FullName << ':'
+                                  << Option.OptionName;
+
+      // If the buffer's length is greater then PadForDesc, print a newline.
+      if (FOut.getColumn() > PadForDesc)
+        FOut << '\n';
+
+      FOut.PadToColumn(PadForDesc) << "(" << Option.OptionType << ") ";
+
+      for (char C : Option.Description) {
+        if (FOut.getColumn() > MinLineWidth && C == ' ') {
+          FOut << '\n';
+          FOut.PadToColumn(PadForDesc);
+          continue;
+        }
+        FOut << C;
+      }
+
+      if (!Option.Description.empty())
+        FOut << ' ';
+      if (FOut.getColumn() > MinLineWidth) {
+        FOut << '\n';
+        FOut.PadToColumn(PadForDesc);
+      }
+      FOut << "(default: "
+           << (Option.DefaultValStr.empty() ? "\"\"" : Option.DefaultValStr)
+           << ")\n\n";
+    }
+  }
+}
Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
===================================================================
--- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
+++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
@@ -65,6 +65,15 @@
       .printEnabledCheckerList(out);
 }
 
+void ento::printCheckerConfigList(raw_ostream &OS,
+                                  ArrayRef<std::string> plugins,
+                                  AnalyzerOptions &opts,
+                                  DiagnosticsEngine &diags,
+                                  const LangOptions &LangOpts) {
+  CheckerRegistry(plugins, diags, opts, LangOpts)
+      .printCheckerOptionList(OS);
+}
+
 void ento::printAnalyzerConfigList(raw_ostream &out) {
   out << "OVERVIEW: Clang Static Analyzer -analyzer-config Option List\n\n";
   out << "USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config "
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===================================================================
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -245,6 +245,16 @@
     return true;
   }
 
+  // Honor -analyzer-checker-option-help.
+  if (Clang->getAnalyzerOpts()->ShowCheckerOptionList) {
+    ento::printCheckerConfigList(llvm::outs(),
+                                 Clang->getFrontendOpts().Plugins,
+                                 *Clang->getAnalyzerOpts(),
+                                 Clang->getDiagnostics(),
+                                 Clang->getLangOpts());
+    return true;
+  }
+
   // Honor -analyzer-list-enabled-checkers.
   if (Clang->getAnalyzerOpts()->ShowEnabledCheckerList) {
     ento::printEnabledCheckerList(llvm::outs(),
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -285,6 +285,7 @@
   }
 
   Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help);
+  Opts.ShowCheckerOptionList = Args.hasArg(OPT_analyzer_checker_option_help);
   Opts.ShowConfigOptionsList = Args.hasArg(OPT_analyzer_config_help);
   Opts.ShowEnabledCheckerList = Args.hasArg(OPT_analyzer_list_enabled_checkers);
   Opts.ShouldEmitErrorsOnInvalidConfigValue =
Index: include/clang/StaticAnalyzer/Frontend/FrontendActions.h
===================================================================
--- include/clang/StaticAnalyzer/Frontend/FrontendActions.h
+++ include/clang/StaticAnalyzer/Frontend/FrontendActions.h
@@ -61,6 +61,10 @@
                              DiagnosticsEngine &diags,
                              const LangOptions &LangOpts);
 void printAnalyzerConfigList(raw_ostream &OS);
+void printCheckerConfigList(raw_ostream &OS, ArrayRef<std::string> plugins,
+                            AnalyzerOptions &opts,
+                            DiagnosticsEngine &diags,
+                            const LangOptions &LangOpts);
 
 } // end GR namespace
 
Index: include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
===================================================================
--- include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -248,6 +248,7 @@
   void printCheckerWithDescList(raw_ostream &out,
                                 size_t maxNameChars = 30) const;
   void printEnabledCheckerList(raw_ostream &out) const;
+  void printCheckerOptionList(raw_ostream &out) const;
 
 private:
   /// Collect all enabled checkers. The returned container preserves the order
Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===================================================================
--- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -198,6 +198,7 @@
   unsigned DisableAllChecks : 1;
 
   unsigned ShowCheckerHelp : 1;
+  unsigned ShowCheckerOptionList : 1;
   unsigned ShowEnabledCheckerList : 1;
   unsigned ShowConfigOptionsList : 1;
   unsigned ShouldEmitErrorsOnInvalidConfigValue : 1;
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -139,6 +139,9 @@
 def analyzer_config : Separate<["-"], "analyzer-config">,
   HelpText<"Choose analyzer options to enable">;
 
+def analyzer_checker_option_help : Flag<["-"], "analyzer-checker-option-help">,
+  HelpText<"Display the list of checker options">;
+
 def analyzer_config_compatibility_mode : Separate<["-"], "analyzer-config-compatibility-mode">,
   HelpText<"Don't emit errors on invalid analyzer-config inputs">;
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D57858: [analyzer]... Kristóf Umann via Phabricator via cfe-commits

Reply via email to