xref: /netbsd-src/external/gpl3/gcc/dist/gcc/analyzer/pending-diagnostic.cc (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1 /* Classes for analyzer diagnostics.
2    Copyright (C) 2019-2022 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 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "intl.h"
26 #include "diagnostic.h"
27 #include "function.h"
28 #include "json.h"
29 #include "analyzer/analyzer.h"
30 #include "diagnostic-event-id.h"
31 #include "analyzer/analyzer-logging.h"
32 #include "analyzer/sm.h"
33 #include "diagnostic-event-id.h"
34 #include "analyzer/sm.h"
35 #include "analyzer/pending-diagnostic.h"
36 #include "selftest.h"
37 #include "tristate.h"
38 #include "analyzer/call-string.h"
39 #include "analyzer/program-point.h"
40 #include "analyzer/store.h"
41 #include "analyzer/region-model.h"
42 
43 #if ENABLE_ANALYZER
44 
45 namespace ana {
46 
47 /* struct interesting_t.  */
48 
49 /* Mark the creation of REG as being interesting.  */
50 
51 void
add_region_creation(const region * reg)52 interesting_t::add_region_creation (const region *reg)
53 {
54   gcc_assert (reg);
55   m_region_creation.safe_push (reg);
56 }
57 
58 void
dump_to_pp(pretty_printer * pp,bool simple) const59 interesting_t::dump_to_pp (pretty_printer *pp, bool simple) const
60 {
61   pp_string (pp, "{ region creation: [");
62   unsigned i;
63   const region *reg;
64   FOR_EACH_VEC_ELT (m_region_creation, i, reg)
65     {
66       if (i > 0)
67 	pp_string (pp, ", ");
68       reg->dump_to_pp (pp, simple);
69     }
70   pp_string (pp, "]}");
71 }
72 
73 /* Generate a label_text by printing FMT.
74 
75    Use a clone of the global_dc for formatting callbacks.
76 
77    Use this evdesc::event_desc's m_colorize flag to control colorization
78    (so that e.g. we can disable it for JSON output).  */
79 
80 label_text
formatted_print(const char * fmt,...) const81 evdesc::event_desc::formatted_print (const char *fmt, ...) const
82 {
83   pretty_printer *pp = global_dc->printer->clone ();
84 
85   pp_show_color (pp) = m_colorize;
86 
87   text_info ti;
88   rich_location rich_loc (line_table, UNKNOWN_LOCATION);
89   va_list ap;
90   va_start (ap, fmt);
91   ti.format_spec = _(fmt);
92   ti.args_ptr = &ap;
93   ti.err_no = 0;
94   ti.x_data = NULL;
95   ti.m_richloc = &rich_loc;
96   pp_format (pp, &ti);
97   pp_output_formatted_text (pp);
98   va_end (ap);
99 
100   label_text result = label_text::take (xstrdup (pp_formatted_text (pp)));
101   delete pp;
102   return result;
103 }
104 
105 /* Return true if T1 and T2 are "the same" for the purposes of
106    diagnostic deduplication.  */
107 
108 bool
same_tree_p(tree t1,tree t2)109 pending_diagnostic::same_tree_p (tree t1, tree t2)
110 {
111   return simple_cst_equal (t1, t2) == 1;
112 }
113 
114 } // namespace ana
115 
116 #endif /* #if ENABLE_ANALYZER */
117