This revision was automatically updated to reflect the committed changes.
Szelethus marked an inline comment as done.
Closed by commit rC345989: [analyzer] New flag to print all -analyzer-config 
options (authored by Szelethus, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53296?vs=171611&id=172377#toc

Repository:
  rC Clang

https://reviews.llvm.org/D53296

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

Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===================================================================
--- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -175,6 +175,7 @@
 
   unsigned ShowCheckerHelp : 1;
   unsigned ShowEnabledCheckerList : 1;
+  unsigned ShowConfigOptionsList : 1;
   unsigned AnalyzeAll : 1;
   unsigned AnalyzerDisplayProgress : 1;
   unsigned AnalyzeNestedBlocks : 1;
Index: include/clang/StaticAnalyzer/Frontend/FrontendActions.h
===================================================================
--- include/clang/StaticAnalyzer/Frontend/FrontendActions.h
+++ include/clang/StaticAnalyzer/Frontend/FrontendActions.h
@@ -55,6 +55,7 @@
 void printCheckerHelp(raw_ostream &OS, ArrayRef<std::string> plugins);
 void printEnabledCheckerList(raw_ostream &OS, ArrayRef<std::string> plugins,
                              const AnalyzerOptions &opts);
+void printAnalyzerConfigList(raw_ostream &OS);
 
 } // end GR namespace
 
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -129,6 +129,9 @@
 def analyzer_checker_help : Flag<["-"], "analyzer-checker-help">,
   HelpText<"Display the list of analyzer checkers that are available">;
 
+def analyzer_config_help : Flag<["-"], "analyzer-config-help">,
+  HelpText<"Display the list of -analyzer-config options">;
+
 def analyzer_list_enabled_checkers : Flag<["-"], "analyzer-list-enabled-checkers">,
   HelpText<"Display the list of enabled analyzer checkers">;
 
Index: test/Analysis/analyzer-list-configs.c
===================================================================
--- test/Analysis/analyzer-list-configs.c
+++ test/Analysis/analyzer-list-configs.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -analyzer-config-help 2>&1 | FileCheck %s
+// CHECK: OVERVIEW: Clang Static Analyzer -analyzer-config Option List
+//
+// CHECK: USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>
+//
+// CHCEK:      clang -cc1 [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ...
+//
+// CHECK:      clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang<OPTION1=VALUE,OPTION2=VALUE,...>
+//
+// CHECK:      clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang OPTION1=VALUE, -Xclang -analyzer-config -Xclang OPTION2=VALUE, ...
+//
+//
+// CHECK: OPTIONS:
+//
+// CHECK: aggressive-binary-operation-simplification
+// CHECK:                   (bool) Whether SValBuilder should rearrange
+// CHECK:                   comparisons and additive operations of symbolic
+// CHECK:                   expressions which consist of a sum of a
+// CHECK:                   symbol and a concrete integer into the format
+// CHECK:                   where symbols are on the left-hand side
+// CHECK:                   and the integer is on the right. This is
+// CHECK:                   only done if both symbols and both concrete
+// CHECK:                   integers are signed, greater than or equal
+// CHECK:                   to the quarter of the minimum value of the
+// CHECK:                   type and less than or equal to the quarter
+// CHECK:                   of the maximum value of that type. A + n
+// CHECK:                   <OP> B + m becomes A - B <OP> m - n, where
+// CHECK:                   A and B symbolic, n and m are integers.
+// CHECK:                   <OP> is any of '==', '!=', '<', '<=', '>',
+// CHECK:                   '>=', '+' or '-'. The rearrangement also
+// CHECK:                   happens with '-' instead of '+' on either
+// CHECK:                   or both side and also if any or both integers
+// CHECK:                   are missing. (default: false)
Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
===================================================================
--- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
+++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
@@ -22,6 +22,7 @@
 #include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include <memory>
@@ -157,3 +158,74 @@
   SmallVector<CheckerOptInfo, 8> checkerOpts = getCheckerOptList(opts);
   ClangCheckerRegistry(plugins).printList(out, checkerOpts);
 }
+
+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 "
+                                        "<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";
+
+  using OptionAndDescriptionTy = std::pair<StringRef, std::string>;
+  OptionAndDescriptionTy PrintableOptions[] = {
+#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)                \
+    {                                                                          \
+      CMDFLAG,                                                                 \
+      llvm::Twine(llvm::Twine() + "(" +                                        \
+                  (#TYPE == "StringRef" ? "string" : #TYPE ) + ") " DESC       \
+                  " (default: " #DEFAULT_VAL ")").str()                        \
+    },
+
+#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,        \
+                                             SHALLOW_VAL, DEEP_VAL)            \
+    {                                                                          \
+      CMDFLAG,                                                                 \
+      llvm::Twine(llvm::Twine() + "(" +                                        \
+                  (#TYPE == "StringRef" ? "string" : #TYPE ) + ") " DESC       \
+                  " (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL    \
+                  " in deep mode)").str()                                      \
+    },
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
+#undef ANALYZER_OPTION
+#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
+  };
+
+  llvm::sort(PrintableOptions, [](const OptionAndDescriptionTy &LHS,
+                                  const OptionAndDescriptionTy &RHS) {
+    return LHS.first < RHS.first;
+  });
+
+  constexpr size_t MinLineWidth = 70;
+  constexpr size_t PadForOpt = 2;
+  constexpr size_t OptionWidth = 30;
+  constexpr size_t PadForDesc = PadForOpt + OptionWidth;
+  static_assert(MinLineWidth > PadForDesc, "MinLineWidth must be greater!");
+
+  llvm::formatted_raw_ostream FOut(out);
+
+  for (const auto &Pair : PrintableOptions) {
+    FOut.PadToColumn(PadForOpt) << Pair.first;
+
+    // If the buffer's length is greater then PadForDesc, print a newline.
+    if (FOut.getColumn() > PadForDesc)
+      FOut << '\n';
+
+    FOut.PadToColumn(PadForDesc);
+
+    for (char C : Pair.second) {
+      if (FOut.getColumn() > MinLineWidth && C == ' ') {
+        FOut << '\n';
+        FOut.PadToColumn(PadForDesc);
+        continue;
+      }
+      FOut << C;
+    }
+    FOut << "\n\n";
+  }
+}
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -279,6 +279,7 @@
   }
 
   Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help);
+  Opts.ShowConfigOptionsList = Args.hasArg(OPT_analyzer_config_help);
   Opts.ShowEnabledCheckerList = Args.hasArg(OPT_analyzer_list_enabled_checkers);
   Opts.DisableAllChecks = Args.hasArg(OPT_analyzer_disable_all_checks);
 
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===================================================================
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -241,11 +241,19 @@
     ento::printCheckerHelp(llvm::outs(), Clang->getFrontendOpts().Plugins);
     return true;
   }
+
+  // Honor -analyzer-list-enabled-checkers.
   if (Clang->getAnalyzerOpts()->ShowEnabledCheckerList) {
     ento::printEnabledCheckerList(llvm::outs(),
                                   Clang->getFrontendOpts().Plugins,
                                   *Clang->getAnalyzerOpts());
   }
+
+  // Honor -analyzer-config-help.
+  if (Clang->getAnalyzerOpts()->ShowConfigOptionsList) {
+    ento::printAnalyzerConfigList(llvm::outs());
+    return true;
+  }
 #endif
 
   // If there were errors in processing arguments, don't do anything else.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to