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
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along 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
33namespace {
34
35/* Data for the analyzer pass. */
36
37const pass_data pass_data_analyzer =
38{
39 .type: IPA_PASS, /* type */
40 .name: "analyzer", /* name */
41 .optinfo_flags: OPTGROUP_NONE, /* optinfo_flags */
42 .tv_id: TV_ANALYZER, /* tv_id */
43 PROP_ssa, /* properties_required */
44 .properties_provided: 0, /* properties_provided */
45 .properties_destroyed: 0, /* properties_destroyed */
46 .todo_flags_start: 0, /* todo_flags_start */
47 .todo_flags_finish: 0, /* todo_flags_finish */
48};
49
50/* The analyzer pass. */
51
52class pass_analyzer : public ipa_opt_pass_d
53{
54public:
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
75bool
76pass_analyzer::gate (function *)
77{
78 return flag_analyzer != 0;
79}
80
81/* Entrypoint for the analyzer pass. */
82
83unsigned int
84pass_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
99ipa_opt_pass_d *
100make_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
109void
110sorry_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 */
118

source code of gcc/analyzer/analyzer-pass.cc