]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/analyzer/call-info.cc
analyzer: fix "when 'strchr' returns non-NULL" message
[thirdparty/gcc.git] / gcc / analyzer / call-info.cc
CommitLineData
eafa9d96 1/* Subclasses of custom_edge_info for describing outcomes of function calls.
7adcbafe 2 Copyright (C) 2021-2022 Free Software Foundation, Inc.
eafa9d96
DM
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"
6341f14e 22#define INCLUDE_MEMORY
eafa9d96
DM
23#include "system.h"
24#include "coretypes.h"
25#include "tree.h"
26#include "function.h"
27#include "basic-block.h"
28#include "gimple.h"
29#include "gimple-iterator.h"
30#include "diagnostic-core.h"
31#include "options.h"
32#include "cgraph.h"
33#include "tree-pretty-print.h"
eafa9d96 34#include "bitmap.h"
eafa9d96
DM
35#include "analyzer/analyzer.h"
36#include "analyzer/analyzer-logging.h"
37#include "ordered-hash-map.h"
38#include "cfg.h"
39#include "digraph.h"
40#include "analyzer/supergraph.h"
41#include "sbitmap.h"
42#include "analyzer/call-string.h"
43#include "analyzer/program-point.h"
44#include "analyzer/store.h"
45#include "analyzer/region-model.h"
46#include "analyzer/constraint-manager.h"
47#include "diagnostic-event-id.h"
48#include "analyzer/sm.h"
49#include "analyzer/pending-diagnostic.h"
50#include "analyzer/region-model-reachability.h"
51#include "analyzer/analyzer-selftests.h"
52#include "analyzer/program-state.h"
53#include "diagnostic-path.h"
54#include "analyzer/checker-path.h"
55#include "analyzer/diagnostic-manager.h"
eafa9d96
DM
56#include "analyzer/exploded-graph.h"
57#include "analyzer/call-info.h"
d60b40b8 58#include "make-unique.h"
eafa9d96
DM
59
60#if ENABLE_ANALYZER
61
62namespace ana {
63
bfca9505
DM
64/* class custom_edge_info. */
65
66bool
67custom_edge_info::update_state (program_state *state,
68 const exploded_edge *eedge,
69 region_model_context *ctxt) const
70{
71 return update_model (state->m_region_model, eedge, ctxt);
72}
73
74/* class call_info : public custom_edge_info. */
eafa9d96
DM
75
76/* Implementation of custom_edge_info::print vfunc for call_info:
77 use get_desc to get a label_text, and print it to PP. */
78
79void
80call_info::print (pretty_printer *pp) const
81{
82 label_text desc (get_desc (pp_show_color (pp)));
f858fe7a 83 pp_string (pp, desc.get ());
eafa9d96
DM
84}
85
86/* Implementation of custom_edge_info::add_events_to_path vfunc for
87 call_info: add a custom_event using call_info::get_desc as its
88 description. */
89
90void
91call_info::add_events_to_path (checker_path *emission_path,
92 const exploded_edge &eedge) const
93{
94 class call_event : public custom_event
95 {
96 public:
97 call_event (location_t loc, tree fndecl, int depth,
98 const call_info *call_info)
99 : custom_event (loc, fndecl, depth),
100 m_call_info (call_info)
101 {}
102
2ac1459f 103 label_text get_desc (bool can_colorize) const final override
eafa9d96
DM
104 {
105 return m_call_info->get_desc (can_colorize);
106 }
107
108 private:
109 const call_info *m_call_info;
110 };
111
112 const exploded_node *src_node = eedge.m_src;
113 const program_point &src_point = src_node->get_point ();
114 tree caller_fndecl = src_point.get_fndecl ();
115 const int stack_depth = src_point.get_stack_depth ();
116
d60b40b8
DM
117 emission_path->add_event (make_unique<call_event> (get_call_stmt ()->location,
118 caller_fndecl,
119 stack_depth,
120 this));
eafa9d96
DM
121}
122
123/* Recreate a call_details instance from this call_info. */
124
125call_details
126call_info::get_call_details (region_model *model,
127 region_model_context *ctxt) const
128{
129 return call_details (m_call_stmt, model, ctxt);
130}
131
132/* call_info's ctor.
133
134 The call_info instance will outlive the call_details instance;
135 call_details instances are typically created on the stack. */
136
137call_info::call_info (const call_details &cd)
138: m_call_stmt (cd.get_call_stmt ()),
139 m_fndecl (cd.get_fndecl_for_call ())
140{
141 gcc_assert (m_fndecl);
142}
143
144/* class success_call_info : public call_info. */
145
146/* Implementation of call_info::get_desc vfunc for success_call_info. */
147
148label_text
149success_call_info::get_desc (bool can_colorize) const
150{
151 return make_label_text (can_colorize, "when %qE succeeds", get_fndecl ());
152}
153
154/* class failed_call_info : public call_info. */
155
156/* Implementation of call_info::get_desc vfunc for failed_call_info. */
157
158label_text
159failed_call_info::get_desc (bool can_colorize) const
160{
161 return make_label_text (can_colorize, "when %qE fails", get_fndecl ());
162}
163
164} // namespace ana
165
166#endif /* #if ENABLE_ANALYZER */