Branch data Line data Source code
1 : : /* Subclasses of custom_edge_info for describing outcomes of function calls.
2 : : Copyright (C) 2021-2025 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 "ordered-hash-map.h"
24 : : #include "cfg.h"
25 : : #include "digraph.h"
26 : : #include "sbitmap.h"
27 : : #include "diagnostic-event-id.h"
28 : :
29 : : #include "analyzer/analyzer-logging.h"
30 : : #include "analyzer/supergraph.h"
31 : : #include "analyzer/call-string.h"
32 : : #include "analyzer/program-point.h"
33 : : #include "analyzer/store.h"
34 : : #include "analyzer/region-model.h"
35 : : #include "analyzer/constraint-manager.h"
36 : : #include "analyzer/sm.h"
37 : : #include "analyzer/pending-diagnostic.h"
38 : : #include "analyzer/region-model-reachability.h"
39 : : #include "analyzer/analyzer-selftests.h"
40 : : #include "analyzer/program-state.h"
41 : : #include "analyzer/checker-path.h"
42 : : #include "analyzer/diagnostic-manager.h"
43 : : #include "analyzer/exploded-graph.h"
44 : : #include "analyzer/call-details.h"
45 : : #include "analyzer/call-info.h"
46 : :
47 : : #if ENABLE_ANALYZER
48 : :
49 : : namespace ana {
50 : :
51 : : /* class custom_edge_info. */
52 : :
53 : : bool
54 : 8227 : custom_edge_info::update_state (program_state *state,
55 : : const exploded_edge *eedge,
56 : : region_model_context *ctxt) const
57 : : {
58 : 8227 : return update_model (state->m_region_model, eedge, ctxt);
59 : : }
60 : :
61 : : /* Base implementation of custom_edge_info::create_enode vfunc. */
62 : :
63 : : exploded_node *
64 : 3855 : custom_edge_info::create_enode (exploded_graph &eg,
65 : : const program_point &point,
66 : : program_state &&state,
67 : : exploded_node *enode_for_diag,
68 : : region_model_context *) const
69 : : {
70 : 3855 : return eg.get_or_create_node (point, state, enode_for_diag);
71 : : }
72 : :
73 : : /* class call_info : public custom_edge_info. */
74 : :
75 : : /* Implementation of custom_edge_info::print vfunc for call_info. */
76 : :
77 : : void
78 : 0 : call_info::print (pretty_printer *pp) const
79 : : {
80 : 0 : gcc_assert (pp);
81 : 0 : print_desc (*pp);
82 : 0 : }
83 : :
84 : : /* Implementation of custom_edge_info::add_events_to_path vfunc for
85 : : call_info: add a custom_event using call_info::get_desc as its
86 : : description. */
87 : :
88 : : void
89 : 292 : call_info::add_events_to_path (checker_path *emission_path,
90 : : const exploded_edge &eedge) const
91 : : {
92 : 0 : class call_event : public custom_event
93 : : {
94 : : public:
95 : 292 : call_event (const event_loc_info &loc_info,
96 : : const call_info *call_info)
97 : 292 : : custom_event (loc_info),
98 : 292 : m_call_info (call_info)
99 : : {}
100 : :
101 : 576 : void print_desc (pretty_printer &pp) const final override
102 : : {
103 : 576 : m_call_info->print_desc (pp);
104 : 576 : }
105 : :
106 : : private:
107 : : const call_info *m_call_info;
108 : : };
109 : :
110 : 292 : const exploded_node *src_node = eedge.m_src;
111 : 292 : const program_point &src_point = src_node->get_point ();
112 : 292 : tree caller_fndecl = src_point.get_fndecl ();
113 : 292 : const int stack_depth = src_point.get_stack_depth ();
114 : :
115 : 292 : emission_path->add_event
116 : 292 : (std::make_unique<call_event> (event_loc_info (get_call_stmt ().location,
117 : : caller_fndecl,
118 : 292 : stack_depth),
119 : 292 : this));
120 : 292 : }
121 : :
122 : : /* Recreate a call_details instance from this call_info. */
123 : :
124 : : call_details
125 : 7062 : call_info::get_call_details (region_model *model,
126 : : region_model_context *ctxt) const
127 : : {
128 : 7062 : return call_details (m_call_stmt, model, ctxt);
129 : : }
130 : :
131 : : /* call_info's ctor.
132 : :
133 : : The call_info instance will outlive the call_details instance;
134 : : call_details instances are typically created on the stack. */
135 : :
136 : 4734 : call_info::call_info (const call_details &cd)
137 : 4734 : : m_call_stmt (cd.get_call_stmt ()),
138 : 4734 : m_fndecl (cd.get_fndecl_for_call ())
139 : : {
140 : 4734 : gcc_assert (m_fndecl);
141 : 4734 : }
142 : :
143 : 2177 : call_info::call_info (const call_details &cd,
144 : 2177 : const function &called_fn)
145 : 2177 : : m_call_stmt (cd.get_call_stmt ()),
146 : 2177 : m_fndecl (called_fn.decl)
147 : : {
148 : 2177 : gcc_assert (m_fndecl);
149 : 2177 : }
150 : :
151 : : /* class succeed_or_fail_call_info : public call_info. */
152 : :
153 : : void
154 : 276 : succeed_or_fail_call_info::print_desc (pretty_printer &pp) const
155 : : {
156 : 276 : if (m_success)
157 : 158 : pp_printf (&pp, "when %qE succeeds", get_fndecl ());
158 : : else
159 : 118 : pp_printf (&pp, "when %qE fails", get_fndecl ());
160 : 276 : }
161 : :
162 : : } // namespace ana
163 : :
164 : : #endif /* #if ENABLE_ANALYZER */
|