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