public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH 19/45] analyzer: new file: analyzer-pass.cc and pass registration
Date: Fri, 13 Dec 2019 18:12:00 -0000	[thread overview]
Message-ID: <20191213181134.1830-20-dmalcolm@redhat.com> (raw)
In-Reply-To: <20191213181134.1830-1-dmalcolm@redhat.com>

Changed in v4:
- Remove include of gcc-plugin.h, reworking includes accordingly.
- Use TV_ANALYZER rather than TV_NONE for the pass
- Add a gate function to the pass
- Move the check for #if ENABLE_ANALYZER from the driver to the
  pass's execute vfunc
- Expose the pass via make_pass_analyzer, rather than via the plugin
  pass registration mechanism

Changed in v3:
- added to passes.def and tree-pass.h

gcc/ChangeLog:
	* analyzer/analyzer-pass.cc: New file.
	* passes.def (pass_analyzer): Add before
	pass_ipa_whole_program_visibility.
	* tree-pass.h (make_pass_analyzer): New decl.
---
 gcc/analyzer/analyzer-pass.cc | 102 ++++++++++++++++++++++++++++++++++
 gcc/passes.def                |   1 +
 gcc/tree-pass.h               |   1 +
 3 files changed, 104 insertions(+)
 create mode 100644 gcc/analyzer/analyzer-pass.cc

diff --git a/gcc/analyzer/analyzer-pass.cc b/gcc/analyzer/analyzer-pass.cc
new file mode 100644
index 000000000000..60535a944dc9
--- /dev/null
+++ b/gcc/analyzer/analyzer-pass.cc
@@ -0,0 +1,102 @@
+/* Integration of the analyzer with GCC's pass manager.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   Contributed by David Malcolm <dmalcolm@redhat.com>.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "context.h"
+#include "tree-pass.h"
+#include "diagnostic.h"
+#include "options.h"
+#include "analyzer/engine.h"
+
+namespace {
+
+/* Data for the analyzer pass.  */
+
+const pass_data pass_data_analyzer =
+{
+  IPA_PASS, /* type */
+  "analyzer", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_ANALYZER, /* tv_id */
+  PROP_ssa, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  0, /* todo_flags_finish */
+};
+
+/* The analyzer pass.  */
+
+class pass_analyzer : public ipa_opt_pass_d
+{
+public:
+   pass_analyzer(gcc::context *ctxt)
+   : ipa_opt_pass_d (pass_data_analyzer, ctxt,
+		     NULL, /* generate_summary */
+		     NULL, /* write_summary */
+		     NULL, /* read_summary */
+		     NULL, /* write_optimization_summary */
+		     NULL, /* read_optimization_summary */
+		     NULL, /* stmt_fixup */
+		     0, /* function_transform_todo_flags_start */
+		     NULL, /* function_transform */
+		     NULL) /* variable_transform */
+  {}
+
+  /* opt_pass methods: */
+  bool gate (function *) FINAL OVERRIDE;
+  unsigned int execute (function *) FINAL OVERRIDE;
+}; // class pass_analyzer
+
+/* Only run the analyzer if -fanalyzer.  */
+
+bool
+pass_analyzer::gate (function *)
+{
+  return flag_analyzer != 0;
+}
+
+/* Entrypoint for the analyzer pass.  */
+
+unsigned int
+pass_analyzer::execute (function *)
+{
+#if ENABLE_ANALYZER
+  run_checkers ();
+#else
+  sorry ("%qs was not enabled in this build of GCC"
+	 " (missing configure-time option %qs)",
+	 "-fanalyzer", "--enable-analyzer");
+#endif
+
+  return 0;
+}
+
+} // anon namespace
+
+/* Make an instance of the analyzer pass.  */
+
+ipa_opt_pass_d *
+make_pass_analyzer (gcc::context *ctxt)
+{
+  return new pass_analyzer (ctxt);
+}
diff --git a/gcc/passes.def b/gcc/passes.def
index 798a391bd351..0ee8b621016c 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -142,6 +142,7 @@ along with GCC; see the file COPYING3.  If not see
   TERMINATE_PASS_LIST (all_small_ipa_passes)
 
   INSERT_PASSES_AFTER (all_regular_ipa_passes)
+  NEXT_PASS (pass_analyzer);
   NEXT_PASS (pass_ipa_whole_program_visibility);
   NEXT_PASS (pass_ipa_profile);
   NEXT_PASS (pass_ipa_icf);
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index a987661530ea..59a5fa6ad4a5 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -490,6 +490,7 @@ extern simple_ipa_opt_pass *make_pass_build_ssa_passes (gcc::context *ctxt);
 extern simple_ipa_opt_pass *make_pass_local_optimization_passes (gcc::context *ctxt);
 extern simple_ipa_opt_pass *make_pass_ipa_remove_symbols (gcc::context *ctxt);
 
+extern ipa_opt_pass_d *make_pass_analyzer (gcc::context *ctxt);
 extern ipa_opt_pass_d *make_pass_ipa_whole_program_visibility (gcc::context
 							       *ctxt);
 extern simple_ipa_opt_pass *make_pass_ipa_increase_alignment (gcc::context
-- 
2.21.0

  parent reply	other threads:[~2019-12-13 18:12 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13 18:12 [PATCH 00/45] v4 of analyzer patch kit David Malcolm
2019-12-13 18:11 ` [PATCH 04/45] analyzer: internal documentation David Malcolm
2019-12-13 18:11 ` [PATCH 09/45] Add diagnostic_metadata and CWE support David Malcolm
2019-12-13 18:11 ` [PATCH 02/45] hash-map-tests.c: add a selftest involving int_hash David Malcolm
2019-12-13 18:11 ` [PATCH 05/45] Add pp_write_text_as_html_like_dot_to_stream David Malcolm
2019-12-16 17:32   ` David Malcolm
2019-12-13 18:11 ` [PATCH 14/45] analyzer: add new files to Makefile.in David Malcolm
2019-12-13 18:12 ` [PATCH 22/45] analyzer: new files: supergraph.{cc|h} David Malcolm
2019-12-13 18:12 ` [PATCH 10/45] Add diagnostic paths David Malcolm
2019-12-13 18:12 ` [PATCH 06/45] sbitmap.h: add operator const sbitmap & to auto_sbitmap David Malcolm
2019-12-13 18:12 ` [PATCH 13/45] analyzer: changes to configure.ac David Malcolm
2019-12-13 18:12 ` [PATCH 27/45] analyzer: new files: pending-diagnostic.{cc|h} David Malcolm
2019-12-13 18:12 ` [PATCH 24/45] analyzer: new files: tristate.{cc|h} David Malcolm
2019-12-13 18:12 ` [PATCH 34/45] analyzer: new file: sm-taint.cc David Malcolm
2019-12-13 18:12 ` David Malcolm [this message]
2019-12-13 18:12 ` [PATCH 20/45] analyzer: new files: graphviz.{cc|h} David Malcolm
2019-12-13 18:12 ` [PATCH 08/45] Add -fdiagnostics-nn-line-numbers David Malcolm
2019-12-13 18:12 ` [PATCH 39/45] analyzer: new file: exploded-graph.h David Malcolm
2019-12-13 18:12 ` [PATCH 23/45] analyzer: new files: analyzer.{cc|h} David Malcolm
2019-12-13 18:12 ` [PATCH 15/45] analyzer: new files: analyzer-selftests.{cc|h} David Malcolm
2019-12-13 18:12 ` [PATCH 17/45] analyzer: command-line options David Malcolm
2019-12-13 18:12 ` [PATCH 12/45] timevar.def: add TVs for analyzer David Malcolm
2019-12-13 18:12 ` [PATCH 37/45] analyzer: new files: program-point.{cc|h} David Malcolm
2019-12-13 18:12 ` [PATCH 28/45] analyzer: new files: sm.{cc|h} David Malcolm
2019-12-13 18:12 ` [PATCH 18/45] analyzer: logging support David Malcolm
2019-12-13 18:12 ` [PATCH 32/45] analyzer: new file: sm-sensitive.cc David Malcolm
2019-12-13 18:13 ` [PATCH 44/45] gdbinit.in: add break-on-saved-diagnostic David Malcolm
2019-12-13 18:14 ` [PATCH 41/45] analyzer: new files: engine.{cc|h} David Malcolm
2019-12-13 18:14 ` [PATCH 11/45] Add ordered_hash_map David Malcolm
2019-12-13 18:14 ` [PATCH 42/45] analyzer: new files: checker-path.{cc|h} David Malcolm
2019-12-13 18:15 ` [PATCH 31/45] analyzer: new file: sm-pattern-test.cc David Malcolm
2019-12-13 18:15 ` [PATCH 25/45] analyzer: new files: constraint-manager.{cc|h} David Malcolm
2019-12-13 18:15 ` [PATCH 30/45] analyzer: new file: sm-file.cc David Malcolm
2019-12-13 18:15 ` [PATCH 45/45] analyzer: test suite David Malcolm
2019-12-13 18:15 ` [PATCH 21/45] analyzer: new files: digraph.{cc|h} and shortest-paths.h David Malcolm
2019-12-13 18:16 ` [PATCH 01/45] gimple const-correctness fixes David Malcolm
2019-12-13 18:16 ` [PATCH 16/45] analyzer: new builtins David Malcolm
2019-12-13 18:27   ` Jakub Jelinek
2019-12-13 18:32     ` David Malcolm
2019-12-18 14:45       ` [PATCH] analyzer: remove __analyzer builtins David Malcolm
2019-12-18 15:06         ` Jakub Jelinek
2019-12-13 18:16 ` [PATCH 38/45] analyzer: new files: program-state.{cc|h} David Malcolm
2019-12-13 18:16 ` [PATCH 40/45] analyzer: new files: state-purge.{cc|h} David Malcolm
2019-12-13 18:16 ` [PATCH 29/45] analyzer: new files: sm-malloc.cc and sm-malloc.dot David Malcolm
2019-12-13 18:16 ` [PATCH 36/45] analyzer: new files: call-string.{cc|h} David Malcolm
2019-12-13 18:16 ` [PATCH 35/45] analyzer: new files: analysis-plan.{cc|h} David Malcolm
2019-12-13 18:16 ` [PATCH 26/45] analyzer: new files: region-model.{cc|h} David Malcolm
2019-12-13 18:16 ` [PATCH 43/45] analyzer: new files: diagnostic-manager.{cc|h} David Malcolm
2019-12-13 18:16 ` [PATCH 07/45] vec.h: add auto_delete_vec David Malcolm
2019-12-13 18:16 ` [PATCH 33/45] analyzer: new file: sm-signal.cc David Malcolm
2019-12-13 18:16 ` [PATCH 03/45] analyzer: user-facing documentation David Malcolm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191213181134.1830-20-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).