1*4c3eb207Smrg /* Integration of the analyzer with GCC's pass manager.
2*4c3eb207Smrg Copyright (C) 2019-2020 Free Software Foundation, Inc.
3*4c3eb207Smrg Contributed by David Malcolm <dmalcolm@redhat.com>.
4*4c3eb207Smrg
5*4c3eb207Smrg This file is part of GCC.
6*4c3eb207Smrg
7*4c3eb207Smrg GCC is free software; you can redistribute it and/or modify it
8*4c3eb207Smrg under the terms of the GNU General Public License as published by
9*4c3eb207Smrg the Free Software Foundation; either version 3, or (at your option)
10*4c3eb207Smrg any later version.
11*4c3eb207Smrg
12*4c3eb207Smrg GCC is distributed in the hope that it will be useful, but
13*4c3eb207Smrg WITHOUT ANY WARRANTY; without even the implied warranty of
14*4c3eb207Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15*4c3eb207Smrg General Public License for more details.
16*4c3eb207Smrg
17*4c3eb207Smrg You should have received a copy of the GNU General Public License
18*4c3eb207Smrg along with GCC; see the file COPYING3. If not see
19*4c3eb207Smrg <http://www.gnu.org/licenses/>. */
20*4c3eb207Smrg
21*4c3eb207Smrg #include "config.h"
22*4c3eb207Smrg #include "system.h"
23*4c3eb207Smrg #include "coretypes.h"
24*4c3eb207Smrg #include "context.h"
25*4c3eb207Smrg #include "tree-pass.h"
26*4c3eb207Smrg #include "diagnostic.h"
27*4c3eb207Smrg #include "options.h"
28*4c3eb207Smrg #include "analyzer/engine.h"
29*4c3eb207Smrg
30*4c3eb207Smrg namespace {
31*4c3eb207Smrg
32*4c3eb207Smrg /* Data for the analyzer pass. */
33*4c3eb207Smrg
34*4c3eb207Smrg const pass_data pass_data_analyzer =
35*4c3eb207Smrg {
36*4c3eb207Smrg IPA_PASS, /* type */
37*4c3eb207Smrg "analyzer", /* name */
38*4c3eb207Smrg OPTGROUP_NONE, /* optinfo_flags */
39*4c3eb207Smrg TV_ANALYZER, /* tv_id */
40*4c3eb207Smrg PROP_ssa, /* properties_required */
41*4c3eb207Smrg 0, /* properties_provided */
42*4c3eb207Smrg 0, /* properties_destroyed */
43*4c3eb207Smrg 0, /* todo_flags_start */
44*4c3eb207Smrg 0, /* todo_flags_finish */
45*4c3eb207Smrg };
46*4c3eb207Smrg
47*4c3eb207Smrg /* The analyzer pass. */
48*4c3eb207Smrg
49*4c3eb207Smrg class pass_analyzer : public ipa_opt_pass_d
50*4c3eb207Smrg {
51*4c3eb207Smrg public:
pass_analyzer(gcc::context * ctxt)52*4c3eb207Smrg pass_analyzer(gcc::context *ctxt)
53*4c3eb207Smrg : ipa_opt_pass_d (pass_data_analyzer, ctxt,
54*4c3eb207Smrg NULL, /* generate_summary */
55*4c3eb207Smrg NULL, /* write_summary */
56*4c3eb207Smrg NULL, /* read_summary */
57*4c3eb207Smrg NULL, /* write_optimization_summary */
58*4c3eb207Smrg NULL, /* read_optimization_summary */
59*4c3eb207Smrg NULL, /* stmt_fixup */
60*4c3eb207Smrg 0, /* function_transform_todo_flags_start */
61*4c3eb207Smrg NULL, /* function_transform */
62*4c3eb207Smrg NULL) /* variable_transform */
63*4c3eb207Smrg {}
64*4c3eb207Smrg
65*4c3eb207Smrg /* opt_pass methods: */
66*4c3eb207Smrg bool gate (function *) FINAL OVERRIDE;
67*4c3eb207Smrg unsigned int execute (function *) FINAL OVERRIDE;
68*4c3eb207Smrg }; // class pass_analyzer
69*4c3eb207Smrg
70*4c3eb207Smrg /* Only run the analyzer if -fanalyzer. */
71*4c3eb207Smrg
72*4c3eb207Smrg bool
gate(function *)73*4c3eb207Smrg pass_analyzer::gate (function *)
74*4c3eb207Smrg {
75*4c3eb207Smrg return flag_analyzer != 0;
76*4c3eb207Smrg }
77*4c3eb207Smrg
78*4c3eb207Smrg /* Entrypoint for the analyzer pass. */
79*4c3eb207Smrg
80*4c3eb207Smrg unsigned int
execute(function *)81*4c3eb207Smrg pass_analyzer::execute (function *)
82*4c3eb207Smrg {
83*4c3eb207Smrg #if ENABLE_ANALYZER
84*4c3eb207Smrg ana::run_checkers ();
85*4c3eb207Smrg #else
86*4c3eb207Smrg sorry ("%qs was not enabled in this build of GCC"
87*4c3eb207Smrg " (missing configure-time option %qs)",
88*4c3eb207Smrg "-fanalyzer", "--enable-analyzer");
89*4c3eb207Smrg #endif
90*4c3eb207Smrg
91*4c3eb207Smrg return 0;
92*4c3eb207Smrg }
93*4c3eb207Smrg
94*4c3eb207Smrg } // anon namespace
95*4c3eb207Smrg
96*4c3eb207Smrg /* Make an instance of the analyzer pass. */
97*4c3eb207Smrg
98*4c3eb207Smrg ipa_opt_pass_d *
make_pass_analyzer(gcc::context * ctxt)99*4c3eb207Smrg make_pass_analyzer (gcc::context *ctxt)
100*4c3eb207Smrg {
101*4c3eb207Smrg return new pass_analyzer (ctxt);
102*4c3eb207Smrg }
103