Daily bump.
[official-gcc.git] / gcc / analyzer / call-info.cc
blob1d44cb8822180ee9e6f1ae6ab7ae741921207f36
1 /* Subclasses of custom_edge_info for describing outcomes of function calls.
2 Copyright (C) 2021 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)
10 any later version.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "function.h"
26 #include "basic-block.h"
27 #include "gimple.h"
28 #include "gimple-iterator.h"
29 #include "diagnostic-core.h"
30 #include "options.h"
31 #include "cgraph.h"
32 #include "tree-pretty-print.h"
33 #include "tristate.h"
34 #include "bitmap.h"
35 #include "selftest.h"
36 #include "function.h"
37 #include "json.h"
38 #include "analyzer/analyzer.h"
39 #include "analyzer/analyzer-logging.h"
40 #include "ordered-hash-map.h"
41 #include "cfg.h"
42 #include "digraph.h"
43 #include "analyzer/supergraph.h"
44 #include "sbitmap.h"
45 #include "analyzer/call-string.h"
46 #include "analyzer/program-point.h"
47 #include "analyzer/store.h"
48 #include "analyzer/region-model.h"
49 #include "analyzer/constraint-manager.h"
50 #include "diagnostic-event-id.h"
51 #include "analyzer/sm.h"
52 #include "analyzer/pending-diagnostic.h"
53 #include "analyzer/region-model-reachability.h"
54 #include "analyzer/analyzer-selftests.h"
55 #include "analyzer/program-state.h"
56 #include "diagnostic-path.h"
57 #include "analyzer/checker-path.h"
58 #include "analyzer/diagnostic-manager.h"
59 #include "alloc-pool.h"
60 #include "fibonacci_heap.h"
61 #include "shortest-paths.h"
62 #include "analyzer/exploded-graph.h"
63 #include "analyzer/call-info.h"
65 #if ENABLE_ANALYZER
67 namespace ana {
69 /* class call_info : public custom_eedge_info_t. */
71 /* Implementation of custom_edge_info::print vfunc for call_info:
72 use get_desc to get a label_text, and print it to PP. */
74 void
75 call_info::print (pretty_printer *pp) const
77 label_text desc (get_desc (pp_show_color (pp)));
78 pp_string (pp, desc.m_buffer);
79 desc.maybe_free ();
82 /* Implementation of custom_edge_info::add_events_to_path vfunc for
83 call_info: add a custom_event using call_info::get_desc as its
84 description. */
86 void
87 call_info::add_events_to_path (checker_path *emission_path,
88 const exploded_edge &eedge) const
90 class call_event : public custom_event
92 public:
93 call_event (location_t loc, tree fndecl, int depth,
94 const call_info *call_info)
95 : custom_event (loc, fndecl, depth),
96 m_call_info (call_info)
99 label_text get_desc (bool can_colorize) const
101 return m_call_info->get_desc (can_colorize);
104 private:
105 const call_info *m_call_info;
108 const exploded_node *src_node = eedge.m_src;
109 const program_point &src_point = src_node->get_point ();
110 tree caller_fndecl = src_point.get_fndecl ();
111 const int stack_depth = src_point.get_stack_depth ();
113 emission_path->add_event (new call_event (get_call_stmt ()->location,
114 caller_fndecl,
115 stack_depth,
116 this));
119 /* Recreate a call_details instance from this call_info. */
121 call_details
122 call_info::get_call_details (region_model *model,
123 region_model_context *ctxt) const
125 return call_details (m_call_stmt, model, ctxt);
128 /* call_info's ctor.
130 The call_info instance will outlive the call_details instance;
131 call_details instances are typically created on the stack. */
133 call_info::call_info (const call_details &cd)
134 : m_call_stmt (cd.get_call_stmt ()),
135 m_fndecl (cd.get_fndecl_for_call ())
137 gcc_assert (m_fndecl);
140 /* class success_call_info : public call_info. */
142 /* Implementation of call_info::get_desc vfunc for success_call_info. */
144 label_text
145 success_call_info::get_desc (bool can_colorize) const
147 return make_label_text (can_colorize, "when %qE succeeds", get_fndecl ());
150 /* class failed_call_info : public call_info. */
152 /* Implementation of call_info::get_desc vfunc for failed_call_info. */
154 label_text
155 failed_call_info::get_desc (bool can_colorize) const
157 return make_label_text (can_colorize, "when %qE fails", get_fndecl ());
160 } // namespace ana
162 #endif /* #if ENABLE_ANALYZER */