]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/analyzer/analyzer-pass.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / analyzer / analyzer-pass.cc
1 /* Integration of the analyzer with GCC's pass manager.
2 Copyright (C) 2019-2024 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 "config.h"
22 #define INCLUDE_MEMORY
23 #include "system.h"
24 #include "coretypes.h"
25 #include "context.h"
26 #include "tree-pass.h"
27 #include "diagnostic.h"
28 #include "options.h"
29 #include "tree.h"
30 #include "analyzer/analyzer.h"
31 #include "analyzer/engine.h"
32
33 namespace {
34
35 /* Data for the analyzer pass. */
36
37 const pass_data pass_data_analyzer =
38 {
39 IPA_PASS, /* type */
40 "analyzer", /* name */
41 OPTGROUP_NONE, /* optinfo_flags */
42 TV_ANALYZER, /* tv_id */
43 PROP_ssa, /* properties_required */
44 0, /* properties_provided */
45 0, /* properties_destroyed */
46 0, /* todo_flags_start */
47 0, /* todo_flags_finish */
48 };
49
50 /* The analyzer pass. */
51
52 class pass_analyzer : public ipa_opt_pass_d
53 {
54 public:
55 pass_analyzer(gcc::context *ctxt)
56 : ipa_opt_pass_d (pass_data_analyzer, ctxt,
57 NULL, /* generate_summary */
58 NULL, /* write_summary */
59 NULL, /* read_summary */
60 NULL, /* write_optimization_summary */
61 NULL, /* read_optimization_summary */
62 NULL, /* stmt_fixup */
63 0, /* function_transform_todo_flags_start */
64 NULL, /* function_transform */
65 NULL) /* variable_transform */
66 {}
67
68 /* opt_pass methods: */
69 bool gate (function *) final override;
70 unsigned int execute (function *) final override;
71 }; // class pass_analyzer
72
73 /* Only run the analyzer if -fanalyzer. */
74
75 bool
76 pass_analyzer::gate (function *)
77 {
78 return flag_analyzer != 0;
79 }
80
81 /* Entrypoint for the analyzer pass. */
82
83 unsigned int
84 pass_analyzer::execute (function *)
85 {
86 #if ENABLE_ANALYZER
87 ana::run_checkers ();
88 #else
89 sorry_no_analyzer ();
90 #endif
91
92 return 0;
93 }
94
95 } // anon namespace
96
97 /* Make an instance of the analyzer pass. */
98
99 ipa_opt_pass_d *
100 make_pass_analyzer (gcc::context *ctxt)
101 {
102 return new pass_analyzer (ctxt);
103 }
104
105 #if !ENABLE_ANALYZER
106
107 /* Issue a "sorry" diagnostic that the analyzer was not enabled. */
108
109 void
110 sorry_no_analyzer ()
111 {
112 sorry ("%qs was not enabled in this build of GCC"
113 " (missing configure-time option %qs)",
114 "-fanalyzer", "--enable-analyzer");
115 }
116
117 #endif /* #if !ENABLE_ANALYZER */