[PATCH] D53280: [analyzer] Emit a warning for unknown -analyzer-config options

Umann Kristóf via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 15 03:45:24 PDT 2018


Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, rnkovacs, MTC.
Herald added subscribers: cfe-commits, donat.nagy, mikhail.ramalho, a.sidorin, szepet, whisperity.

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'll implement the warning.


Repository:
  rC Clang

https://reviews.llvm.org/D53280

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -314,6 +314,8 @@
       Opts.CheckersControlList.emplace_back(checker, enable);
   }
 
+  std::vector<StringRef> RegisteredOptions = Opts.getConfigOptionList();
+
   // Go through the analyzer configuration options.
   for (const auto *A : Args.filtered(OPT_analyzer_config)) {
     A->claim();
@@ -338,6 +340,13 @@
         Success = false;
         break;
       }
+      // Check whether this really is a valid -analyzer-condfig option.
+      // TODO: We should check whether all options are valid or not, but for
+      // now, skip checker options.
+      if (key.count(':') == 0) {
+        if (llvm::find(RegisteredOptions, key) == RegisteredOptions.end())
+          Diags.Report(diag::warn_analyzer_config_unknown_config) << key;
+      }
       Opts.Config[key] = val;
     }
   }
Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===================================================================
--- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -320,6 +320,15 @@
   template <typename T>
   T getDefaultValForUserMode(T ShallowVal, T DeepVal);
 
+  std::vector<StringRef> getConfigOptionList() const {
+    return {
+#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \
+      CMDFLAG,
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
+#undef ANALYZER_OPTION
+    };
+  }
+
 #define ANALYZER_OPTION_WITH_FN(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL, \
                                 CREATE_FN)                              \
   TYPE CREATE_FN();
Index: include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -291,6 +291,9 @@
   "analyzer-config option '%0' has a key but no value">;
 def err_analyzer_config_multiple_values : Error<
   "analyzer-config option '%0' should contain only one '='">;
+def warn_analyzer_config_unknown_config : Warning<
+  "unkown -analyzer-config option '%0'">,
+  InGroup<OptionIgnored>;
 
 def err_drv_invalid_hvx_length : Error<
   "-mhvx-length is not supported without a -mhvx/-mhvx= flag">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53280.169674.patch
Type: text/x-patch
Size: 2389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181015/55134d48/attachment.bin>


More information about the cfe-commits mailing list