Line data Source code
1 : /* Subclasses of custom_edge_info for describing outcomes of function calls.
2 : Copyright (C) 2021-2026 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 : #ifndef GCC_ANALYZER_CALL_INFO_H
22 : #define GCC_ANALYZER_CALL_INFO_H
23 :
24 : namespace ana {
25 :
26 : /* Subclass of custom_edge_info for an outcome of a call.
27 : This is still abstract; the update_model and print_desc vfuncs must be
28 : implemented. */
29 :
30 0 : class call_info : public custom_edge_info
31 : {
32 : public:
33 : void print (pretty_printer *pp) const override;
34 : void add_events_to_path (checker_path *emission_path,
35 : const exploded_edge &eedge,
36 : pending_diagnostic &pd,
37 : const state_transition *state_trans) const override;
38 :
39 492 : const gcall &get_call_stmt () const { return m_call_stmt; }
40 767 : tree get_fndecl () const { return m_fndecl; }
41 :
42 : virtual void print_desc (pretty_printer &pp) const = 0;
43 :
44 : call_details get_call_details (region_model *model,
45 : region_model_context *ctxt) const;
46 :
47 : protected:
48 : call_info (const call_details &cd);
49 : call_info (const call_details &cd, const function &called_fn);
50 :
51 : private:
52 : const gcall &m_call_stmt;
53 : tree m_fndecl;
54 : };
55 :
56 : /* Subclass of call_info for a "success" outcome of a call,
57 : adding either a
58 : "when `FNDECL' succeeds" message (when 'success' is true)
59 : or a
60 : "when `FNDECL' fails" message (when 'success' is false).
61 :
62 : If get_message_detail () returns non-none, then add a string
63 : in parentheses after e.g.
64 : "when `listen` fails (returning -1)"
65 :
66 : This is still abstract: the custom_edge_info::update_model vfunc
67 : must be implemented. */
68 :
69 0 : class succeed_or_fail_call_info : public call_info
70 : {
71 : public:
72 : enum class message_detail
73 : {
74 : none,
75 : returning_zero,
76 : returning_one,
77 : returning_minus_one,
78 : returning_non_negative,
79 : returning_non_null,
80 : returning_null,
81 : };
82 :
83 : void print_desc (pretty_printer &pp) const override;
84 :
85 : virtual message_detail
86 44 : get_message_detail () const { return message_detail::none; }
87 :
88 : protected:
89 1146 : succeed_or_fail_call_info (const call_details &cd, bool success)
90 1578 : : call_info (cd), m_success (success) {}
91 :
92 : static const char *
93 : get_string_for_message_detail (message_detail msg_detail);
94 :
95 : bool m_success;
96 : };
97 :
98 : /* Subclass of call_info for a "success" outcome of a call,
99 : adding a "when `FNDECL' succeeds" message.
100 : This is still abstract: the custom_edge_info::update_model vfunc
101 : must be implemented. */
102 :
103 : class success_call_info : public succeed_or_fail_call_info
104 : {
105 : protected:
106 79 : success_call_info (const call_details &cd)
107 79 : : succeed_or_fail_call_info (cd, true)
108 : {}
109 : };
110 :
111 : /* Subclass of call_info for a "failure" outcome of a call,
112 : adding a "when `FNDECL' fails" message.
113 : This is still abstract: the custom_edge_info::update_model vfunc
114 : must be implemented. */
115 :
116 0 : class failed_call_info : public succeed_or_fail_call_info
117 : {
118 : protected:
119 393 : failed_call_info (const call_details &cd)
120 393 : : succeed_or_fail_call_info (cd, false)
121 : {}
122 : };
123 :
124 : } // namespace ana
125 :
126 : #endif /* GCC_ANALYZER_CALL_INFO_H */
|