lebedev.ri created this revision.
lebedev.ri added reviewers: alexfh, aaron.ballman, hokein.
Herald added a subscriber: xazax.hun.

After https://reviews.llvm.org/D46159 was created by @pfultz2, and i initially 
thought it was already possible, i had the need to view the call graph.
I have almost wrote the clang-tidy check for that, but then i remembered of 
`clang-analyzer-debug.ViewCallGraph`.
Naturally, it did not work out-of-the-box, thus this patch.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46188

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidyOptions.cpp
  clang-tidy/ClangTidyOptions.h
  clang-tidy/tool/ClangTidyMain.cpp
  docs/clang-tidy/index.rst
  test/clang-tidy/enable-debug-checks.cpp

Index: test/clang-tidy/enable-debug-checks.cpp
===================================================================
--- /dev/null
+++ test/clang-tidy/enable-debug-checks.cpp
@@ -0,0 +1,6 @@
+// Check if '-enable-debug-checks' is visible for users
+// RUN: clang-tidy -help | not grep 'enable-debug-checks'
+
+// Check if '-enable-debug-checks' enables debug checks.
+// RUN: clang-tidy -checks=* -list-checks | not grep 'clang-analyzer-debug'
+// RUN: clang-tidy -checks=* -list-checks -enable-debug-checks | grep 'clang-analyzer-debug'
Index: docs/clang-tidy/index.rst
===================================================================
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -117,6 +117,10 @@
                                    clang-analyzer- checks.
                                    This option overrides the value read from a
                                    .clang-tidy file.
+    -enable-alpha-checks         - This option is not visible in help.
+                                   It allows to enable clang analyzer Alpha checks.
+    -enable-debug-checks         - This option is not visible in help.
+                                   It allows to enable clang analyzer Debug checks.
     -checks=<string>             -
                                    Comma-separated list of globs with optional '-'
                                    prefix. Globs are processed in order of
Index: clang-tidy/tool/ClangTidyMain.cpp
===================================================================
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -198,6 +198,12 @@
 static cl::opt<bool> EnableAlphaChecks("enable-alpha-checks", cl::init(false),
                                        cl::Hidden, cl::cat(ClangTidyCategory));
 
+/// This option Enables debug checkers from the static analyzer.
+/// This option is set to false and not visible in help, because they are not
+/// for general usage.
+static cl::opt<bool> EnableDebugChecks("enable-debug-checks", cl::init(false),
+                                       cl::Hidden, cl::cat(ClangTidyCategory));
+
 static cl::opt<std::string> ExportFixes("export-fixes", cl::desc(R"(
 YAML file to store suggested fixes in. The
 stored fixes can be applied to the input source
@@ -308,6 +314,7 @@
   DefaultOptions.SystemHeaders = SystemHeaders;
   DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
   DefaultOptions.EnableAlphaChecks = EnableAlphaChecks;
+  DefaultOptions.EnableDebugChecks = EnableDebugChecks;
   DefaultOptions.FormatStyle = FormatStyle;
   DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
   // USERNAME is used on Windows.
Index: clang-tidy/ClangTidyOptions.h
===================================================================
--- clang-tidy/ClangTidyOptions.h
+++ clang-tidy/ClangTidyOptions.h
@@ -80,6 +80,9 @@
   /// \brief Turns on experimental alpha checkers from the static analyzer.
   llvm::Optional<bool> EnableAlphaChecks;
 
+  /// \brief Turns on debug checkers from the static analyzer.
+  llvm::Optional<bool> EnableDebugChecks;
+
   /// \brief Format code around applied fixes with clang-format using this
   /// style.
   ///
Index: clang-tidy/ClangTidyOptions.cpp
===================================================================
--- clang-tidy/ClangTidyOptions.cpp
+++ clang-tidy/ClangTidyOptions.cpp
@@ -88,6 +88,7 @@
     IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
     IO.mapOptional("AnalyzeTemporaryDtors", Options.AnalyzeTemporaryDtors);
     IO.mapOptional("EnableAlphaChecks", Options.EnableAlphaChecks);
+    IO.mapOptional("EnableDebugChecks", Options.EnableDebugChecks);
     IO.mapOptional("FormatStyle", Options.FormatStyle);
     IO.mapOptional("User", Options.User);
     IO.mapOptional("CheckOptions", NOpts->Options);
@@ -110,6 +111,7 @@
   Options.SystemHeaders = false;
   Options.AnalyzeTemporaryDtors = false;
   Options.EnableAlphaChecks = false;
+  Options.EnableDebugChecks = false;
   Options.FormatStyle = "none";
   Options.User = llvm::None;
   for (ClangTidyModuleRegistry::iterator I = ClangTidyModuleRegistry::begin(),
@@ -151,6 +153,7 @@
   overrideValue(Result.SystemHeaders, Other.SystemHeaders);
   overrideValue(Result.AnalyzeTemporaryDtors, Other.AnalyzeTemporaryDtors);
   overrideValue(Result.EnableAlphaChecks, Other.EnableAlphaChecks);
+  overrideValue(Result.EnableDebugChecks, Other.EnableDebugChecks);
   overrideValue(Result.FormatStyle, Other.FormatStyle);
   overrideValue(Result.User, Other.User);
   mergeVectors(Result.ExtraArgs, Other.ExtraArgs);
Index: clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -304,11 +304,12 @@
 typedef std::vector<std::pair<std::string, bool>> CheckersList;
 
 static CheckersList getCheckersControlList(ClangTidyContext &Context,
-                                           bool IncludeExperimental) {
+                                           bool IncludeExperimental,
+                                           bool IncludeDebug) {
   CheckersList List;
 
   const auto &RegisteredCheckers =
-      AnalyzerOptions::getRegisteredCheckers(IncludeExperimental);
+      AnalyzerOptions::getRegisteredCheckers(IncludeExperimental, IncludeDebug);
   bool AnalyzerChecksEnabled = false;
   for (StringRef CheckName : RegisteredCheckers) {
     std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());
@@ -376,7 +377,8 @@
       Context.getOptions().AnalyzeTemporaryDtors ? "true" : "false";
 
   AnalyzerOptions->CheckersControlList =
-      getCheckersControlList(Context, *Context.getOptions().EnableAlphaChecks);
+      getCheckersControlList(Context, *Context.getOptions().EnableAlphaChecks,
+                             *Context.getOptions().EnableDebugChecks);
   if (!AnalyzerOptions->CheckersControlList.empty()) {
     setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
     AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
@@ -401,7 +403,8 @@
   }
 
   for (const auto &AnalyzerCheck :
-       getCheckersControlList(Context, *Context.getOptions().EnableAlphaChecks))
+       getCheckersControlList(Context, *Context.getOptions().EnableAlphaChecks,
+                              *Context.getOptions().EnableDebugChecks))
     CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
 
   std::sort(CheckNames.begin(), CheckNames.end());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to