This patch introduces -Wrun-analyzers= and wires it up to the checkers.cc
code, via toplev.c

As noted earlier, I'm not a great fan of the monolithic option syntax
here; maybe there should be some kind of option that can be supplied
multiple times for adding individual checkers.

gcc/ChangeLog:
        * common.opt (Wrun-analyzers=): New option.
        * doc/invoke.texi (Warning Options): Add -Wrun-analyzers=.
        (-Wrun-analyzers=): New option.
        * toplev.c: Include "checkers.h".
        (compile_file): Call checkers_finish.
        (do_compile): Call checkers_start.
---
 gcc/common.opt      | 4 ++++
 gcc/doc/invoke.texi | 8 +++++++-
 gcc/toplev.c        | 9 +++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 1cb1c83..5a7b47d 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -669,6 +669,10 @@ Wreturn-local-addr
 Common Var(warn_return_local_addr) Init(1) Warning
 Warn about returning a pointer/reference to a local or temporary variable.
 
+Wrun-analyzers=
+Common Joined Var(warn_run_analyzers) Warning
+Run 3rd-party analyzer tools based on the supplied JSON file.
+
 Wshadow
 Common Var(warn_shadow) Warning
 Warn when one variable shadows another.  Same as -Wshadow=global.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 5ae9dc4..6756c07 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -303,7 +303,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wplacement-new  -Wplacement-new=@var{n} @gol
 -Wpointer-arith  -Wpointer-compare  -Wno-pointer-to-int-cast @gol
 -Wno-pragmas  -Wredundant-decls  -Wrestrict  -Wno-return-local-addr @gol
--Wreturn-type  -Wsequence-point  -Wshadow  -Wno-shadow-ivar @gol
+-Wreturn-type  -Wrun-analyzers=  -Wsequence-point  -Wshadow  -Wno-shadow-ivar 
@gol
 -Wshadow=global,  -Wshadow=local,  -Wshadow=compatible-local @gol
 -Wshift-overflow  -Wshift-overflow=@var{n} @gol
 -Wshift-count-negative  -Wshift-count-overflow  -Wshift-negative-value @gol
@@ -4638,6 +4638,12 @@ exceptions are @code{main} and functions defined in 
system headers.
 
 This warning is enabled by @option{-Wall}.
 
+@item -Wrun-analyzers=@var{path-to-json}
+@opindex Wrun-analyzers
+Run 3rd-party analyzer tools based on the supplied JSON file.
+
+FIXME: document the format here
+
 @item -Wshift-count-negative
 @opindex Wshift-count-negative
 @opindex Wno-shift-count-negative
diff --git a/gcc/toplev.c b/gcc/toplev.c
index b28f184..4f871e0 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -80,6 +80,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "hsa-common.h"
 #include "edit-context.h"
 #include "tree-pass.h"
+#include "checkers.h"
 
 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
 #include "dbxout.h"
@@ -501,6 +502,11 @@ compile_file (void)
   if (lang_hooks.decls.post_compilation_parsing_cleanups)
     lang_hooks.decls.post_compilation_parsing_cleanups ();
 
+  /* If any 3rd-party analyzers are being run, wait for them to
+     finish, and handle the results.  */
+  if (warn_run_analyzers)
+    checkers_finish ();
+
   if (seen_error ())
     return;
 
@@ -1983,6 +1989,9 @@ do_compile ()
     {
       int i;
 
+      if (warn_run_analyzers)
+       checkers_start (warn_run_analyzers);
+
       timevar_start (TV_PHASE_SETUP);
 
       /* This must be run always, because it is needed to compute the FP
-- 
1.8.5.3

Reply via email to