1 /* Subclasses of custom_edge_info for describing outcomes of function calls.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
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)
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.
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/>. */
22 #define INCLUDE_MEMORY
23 #define INCLUDE_VECTOR
25 #include "coretypes.h"
28 #include "basic-block.h"
30 #include "gimple-iterator.h"
31 #include "diagnostic-core.h"
34 #include "tree-pretty-print.h"
36 #include "analyzer/analyzer.h"
37 #include "analyzer/analyzer-logging.h"
38 #include "ordered-hash-map.h"
41 #include "analyzer/supergraph.h"
43 #include "analyzer/call-string.h"
44 #include "analyzer/program-point.h"
45 #include "analyzer/store.h"
46 #include "analyzer/region-model.h"
47 #include "analyzer/constraint-manager.h"
48 #include "diagnostic-event-id.h"
49 #include "analyzer/sm.h"
50 #include "analyzer/pending-diagnostic.h"
51 #include "analyzer/region-model-reachability.h"
52 #include "analyzer/analyzer-selftests.h"
53 #include "analyzer/program-state.h"
54 #include "diagnostic-path.h"
55 #include "analyzer/checker-path.h"
56 #include "analyzer/diagnostic-manager.h"
57 #include "analyzer/exploded-graph.h"
58 #include "analyzer/call-details.h"
59 #include "analyzer/call-info.h"
60 #include "make-unique.h"
66 /* class custom_edge_info. */
69 custom_edge_info::update_state (program_state
*state
,
70 const exploded_edge
*eedge
,
71 region_model_context
*ctxt
) const
73 return update_model (state
->m_region_model
, eedge
, ctxt
);
76 /* class call_info : public custom_edge_info. */
78 /* Implementation of custom_edge_info::print vfunc for call_info:
79 use get_desc to get a label_text, and print it to PP. */
82 call_info::print (pretty_printer
*pp
) const
84 label_text
desc (get_desc (pp_show_color (pp
)));
85 pp_string (pp
, desc
.get ());
88 /* Implementation of custom_edge_info::add_events_to_path vfunc for
89 call_info: add a custom_event using call_info::get_desc as its
93 call_info::add_events_to_path (checker_path
*emission_path
,
94 const exploded_edge
&eedge
) const
96 class call_event
: public custom_event
99 call_event (const event_loc_info
&loc_info
,
100 const call_info
*call_info
)
101 : custom_event (loc_info
),
102 m_call_info (call_info
)
105 label_text
get_desc (bool can_colorize
) const final override
107 return m_call_info
->get_desc (can_colorize
);
111 const call_info
*m_call_info
;
114 const exploded_node
*src_node
= eedge
.m_src
;
115 const program_point
&src_point
= src_node
->get_point ();
116 tree caller_fndecl
= src_point
.get_fndecl ();
117 const int stack_depth
= src_point
.get_stack_depth ();
119 emission_path
->add_event
120 (make_unique
<call_event
> (event_loc_info (get_call_stmt ()->location
,
126 /* Recreate a call_details instance from this call_info. */
129 call_info::get_call_details (region_model
*model
,
130 region_model_context
*ctxt
) const
132 return call_details (m_call_stmt
, model
, ctxt
);
137 The call_info instance will outlive the call_details instance;
138 call_details instances are typically created on the stack. */
140 call_info::call_info (const call_details
&cd
)
141 : m_call_stmt (cd
.get_call_stmt ()),
142 m_fndecl (cd
.get_fndecl_for_call ())
144 gcc_assert (m_fndecl
);
147 call_info::call_info (const call_details
&cd
,
148 const function
&called_fn
)
149 : m_call_stmt (cd
.get_call_stmt ()),
150 m_fndecl (called_fn
.decl
)
152 gcc_assert (m_fndecl
);
155 /* class succeed_or_fail_call_info : public call_info. */
158 succeed_or_fail_call_info::get_desc (bool can_colorize
) const
161 return make_label_text (can_colorize
, "when %qE succeeds", get_fndecl ());
163 return make_label_text (can_colorize
, "when %qE fails", get_fndecl ());
168 #endif /* #if ENABLE_ANALYZER */