GCC Middle and Back End API Reference
call-details.h
Go to the documentation of this file.
1/* Helper class for handling a call with specific arguments.
2 Copyright (C) 2019-2026 Free Software Foundation, Inc.
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#ifndef GCC_ANALYZER_CALL_DETAILS_H
22#define GCC_ANALYZER_CALL_DETAILS_H
23
24#include "pending-diagnostic.h"
25#include "symbolic-pointers.h"
26
27namespace ana {
28
29/* Helper class for handling calls to functions with known behavior. */
30
32{
33public:
34 call_details (const gcall &call, region_model *model,
37
38 region_model *get_model () const { return m_model; }
40 region_model_context *get_ctxt () const { return m_ctxt; }
41 logger *get_logger () const;
42
44 tree get_lhs_type () const { return m_lhs_type; }
45 const region *get_lhs_region () const { return m_lhs_region; }
46
47 bool maybe_set_lhs (const svalue *result) const;
49
50 unsigned num_args () const;
51 bool arg_is_pointer_p (unsigned idx) const
52 {
53 return POINTER_TYPE_P (get_arg_type (idx));
54 }
55 bool arg_is_size_p (unsigned idx) const;
56 bool arg_is_integral_p (unsigned idx) const
57 {
58 return INTEGRAL_TYPE_P (get_arg_type (idx));
59 }
60
61 const gcall &get_call_stmt () const { return m_call; }
62 location_t get_location () const;
63
64 tree get_arg_tree (unsigned idx) const;
65 tree get_arg_type (unsigned idx) const;
66 const svalue *get_arg_svalue (unsigned idx) const;
67
69 get_arg_as_sym_ptr (unsigned idx) const;
70
71 const symbolic_byte_size &
72 get_arg_as_num_bytes (unsigned idx) const;
73
74 const region *deref_ptr_arg (unsigned idx) const;
75 const char *get_arg_string_literal (unsigned idx) const;
76
78
79 void dump () const;
80
81 std::unique_ptr<text_art::tree_widget>
83
85
86 tree lookup_function_attribute (const char *attr_name) const;
87
88 void
89 check_for_null_terminated_string_arg (unsigned arg_idx) const;
90 const svalue *
92 bool include_terminator,
93 const symbolic::bit_vector **out_bit_vec) const;
94
95 void
96 complain_about_overlap (unsigned arg_idx_a,
97 unsigned arg_idx_b,
98 const svalue *num_bytes_read_sval) const;
99
100private:
101 const gcall &m_call;
106};
107
108/* A bundle of information about a problematic argument at a callsite
109 for use by pending_diagnostic subclasses for reporting and
110 for deduplication. */
111
113{
114public:
115 call_arg_details (const call_details &cd, unsigned arg_idx)
116 : m_call (cd.get_call_stmt ()),
117 m_called_fndecl (cd.get_fndecl_for_call ()),
118 m_arg_idx (arg_idx),
119 m_arg_expr (cd.get_arg_tree (arg_idx))
120 {
121 }
122
123 bool operator== (const call_arg_details &other) const
124 {
125 return (&m_call == &other.m_call
126 && m_called_fndecl == other.m_called_fndecl
127 && m_arg_idx == other.m_arg_idx
129 }
130
131 const gcall &m_call;
133 unsigned m_arg_idx; // 0-based
135};
136
137} // namespace ana
138
139#endif /* GCC_ANALYZER_CALL_DETAILS_H */
Definition call-details.h:32
uncertainty_t * get_uncertainty() const
symbolic::pointer get_arg_as_sym_ptr(unsigned idx) const
void check_for_null_terminated_string_arg(unsigned arg_idx) const
region_model_manager * get_manager() const
const svalue * check_for_null_terminated_string_arg(unsigned arg_idx, bool include_terminator, const symbolic::bit_vector **out_bit_vec) const
const symbolic_byte_size & get_arg_as_num_bytes(unsigned idx) const
const svalue * get_arg_svalue(unsigned idx) const
tree get_arg_tree(unsigned idx) const
bool arg_is_pointer_p(unsigned idx) const
Definition call-details.h:51
location_t get_location() const
const svalue * get_or_create_conjured_svalue(const region *) const
void complain_about_overlap(unsigned arg_idx_a, unsigned arg_idx_b, const svalue *num_bytes_read_sval) const
tree get_lhs_type() const
Definition call-details.h:44
region_model_context * get_ctxt() const
Definition call-details.h:40
region_model_context * m_ctxt
Definition call-details.h:103
bool arg_is_integral_p(unsigned idx) const
Definition call-details.h:56
const region * get_lhs_region() const
Definition call-details.h:45
call_details(const call_details &cd, region_model_context *ctxt)
const region * m_lhs_region
Definition call-details.h:105
tree get_fndecl_for_call() const
unsigned num_args() const
tree lookup_function_attribute(const char *attr_name) const
const gcall & get_call_stmt() const
Definition call-details.h:61
const gcall & m_call
Definition call-details.h:101
bool maybe_set_lhs(const svalue *result) const
tree get_arg_type(unsigned idx) const
tree m_lhs_type
Definition call-details.h:104
call_details(const gcall &call, region_model *model, region_model_context *ctxt)
const region * deref_ptr_arg(unsigned idx) const
std::unique_ptr< text_art::tree_widget > make_dump_widget(symbolic::node_dump_state &nds) const
region_model * m_model
Definition call-details.h:102
void set_any_lhs_with_defaults() const
void dump() const
const char * get_arg_string_literal(unsigned idx) const
region_model * get_model() const
Definition call-details.h:38
logger * get_logger() const
bool arg_is_size_p(unsigned idx) const
Definition analyzer-logging.h:36
static bool same_tree_p(tree t1, tree t2)
Definition region-model.h:840
Definition region-model-manager.h:36
Definition region-model.h:289
Definition region.h:154
Definition svalue.h:82
Definition symbolic-bit-vectors.h:107
Definition symbolic-pointers.h:33
Definition store.h:357
union tree_node * tree
Definition coretypes.h:97
Definition access-diagram.h:30
symbolic::scalar< integer_with_unit< units::byte > > symbolic_byte_size
Definition symbolic-scalars.h:197
@ other
Definition common.h:536
unsigned m_arg_idx
Definition call-details.h:133
tree m_called_fndecl
Definition call-details.h:132
call_arg_details(const call_details &cd, unsigned arg_idx)
Definition call-details.h:115
tree m_arg_expr
Definition call-details.h:134
bool operator==(const call_arg_details &other) const
Definition call-details.h:123
const gcall & m_call
Definition call-details.h:131
Definition symbolic-nodes.h:276
Definition gimple.h:356
#define POINTER_TYPE_P(TYPE)
Definition tree.h:715
#define INTEGRAL_TYPE_P(TYPE)
Definition tree.h:616