GCC Middle and Back End API Reference
symbolic-ranges.h
Go to the documentation of this file.
1/* Typesafe symbolic ranges of values (e.g. "bytes m-n").
2 Copyright (C) 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_SYMBOLIC_RANGES_H
22#define GCC_ANALYZER_SYMBOLIC_RANGES_H
23
26
27namespace ana {
28namespace symbolic {
29
30template<typename ConcreteValueType>
31class range
32{
33public:
35 : m_start_offset (nullptr),
36 m_size (nullptr)
37 {
38 /* Placeholder default ctor for the few places where we need
39 to conditionally initialize these. */
40 }
41
42 range (const scalar<ConcreteValueType> &start_offset,
43 const scalar<ConcreteValueType> &size)
44 : m_start_offset (&start_offset),
45 m_size (&size)
46 {
47 }
48
51 : m_start_offset (&mgr.get_concrete (conc_range.get_start_offset ())),
52 m_size (&mgr.get_concrete (conc_range.get_size ()))
53 {
54 }
55
56 static range
58 const scalar<ConcreteValueType> &next_offset)
59 {
60 return range (start_offset, next_offset - start_offset);
61 }
62
65 {
66 return (m_start_offset->get_complexity ()
67 + m_size->get_complexity ());
68 }
69
71 get_start_offset () const { return *m_start_offset; };
72
74 get_size () const { return *m_size; }
75
78 {
79 ConcreteValueType concrete_one (1);
80 auto &symbolic_one = m_start_offset->get_mgr ().get_concrete (concrete_one);
81 return (get_next_offset () - symbolic_one);
82 }
83
85 get_next_offset () const { return *m_start_offset + *m_size; }
86
87 std::unique_ptr<text_art::tree_widget>
89 const char *prefix = nullptr) const;
90
91 void dump () const;
92
93 void log (const char *label, logger &log) const;
94
95 bool
97 {
98 return (m_start_offset == other.m_start_offset
99 && m_size == other.m_size);
100 }
101
102 static int
104 const range<ConcreteValueType> &rhs)
105 {
106 if (int c = node::cmp (*lhs.m_start_offset, *rhs.m_start_offset))
107 return c;
108 return node::cmp (*lhs.m_size, *rhs.m_size);
109 }
110
111
112 bool
113 operator< (const range<ConcreteValueType> &other) const
114 {
115 return cmp (*this, other) < 0;
116 }
117
120 {
121 return (m_start_offset->get_complexity ()
122 + m_size->get_complexity ());
123 }
124
125 void
127
128 std::unique_ptr<json::object>
129 to_json () const;
130
131 void
133
136 const region_model &model) const;
137
138 bool
140
141 bool
142 empty_p () const
143 {
144 return m_size->is_zero_p ();
145 }
146
147private:
150};
151
152template <typename ConcreteValueType>
153inline bool
156{
157 if (auto *concrete_start_offset
158 = in.get_start_offset ().dyn_cast_concrete_scalar ())
159 if (auto *concrete_size = in.get_size ().dyn_cast_concrete_scalar ())
160 {
162 (concrete_start_offset->get_concrete (),
163 concrete_size->get_concrete ());
164 return true;
165 }
166 return false;
167}
168
169template <typename ConcreteValueType>
178
179} // namespace ana::symbolic
180
183
184bool
187
188} // namespace ana
189
190#endif /* GCC_ANALYZER_SYMBOLIC_RANGES_H */
Definition concrete-ranges.h:33
ConcreteValueType get_start_offset() const
Definition concrete-ranges.h:54
ConcreteValueType get_size() const
Definition concrete-ranges.h:57
Definition analyzer-logging.h:36
Definition region-model.h:289
Definition symbolic-nodes.h:502
Definition symbolic-ranges.h:32
range(const scalar< ConcreteValueType > &start_offset, const scalar< ConcreteValueType > &size)
Definition symbolic-ranges.h:42
tristate intersects(const range< ConcreteValueType > &other, const region_model &model) const
bool access_range_contains_p(const range< ConcreteValueType > &other) const
range(const concrete::range< ConcreteValueType > &conc_range, scalar_manager< ConcreteValueType > &mgr)
Definition symbolic-ranges.h:49
bool operator<(const range< ConcreteValueType > &other) const
Definition symbolic-ranges.h:113
void log(const char *label, logger &log) const
static int cmp(const range< ConcreteValueType > &lhs, const range< ConcreteValueType > &rhs)
Definition symbolic-ranges.h:103
std::unique_ptr< json::object > to_json() const
const scalar< integer_with_unit< units::bit > > * m_size
Definition symbolic-ranges.h:149
complexity get_complexity() const
Definition symbolic-ranges.h:119
bool empty_p() const
Definition symbolic-ranges.h:142
const scalar< ConcreteValueType > & get_last_offset() const
Definition symbolic-ranges.h:77
const scalar< integer_with_unit< units::bit > > & get_size() const
Definition symbolic-ranges.h:74
complexity get_children_complexity() const
Definition symbolic-ranges.h:64
const scalar< integer_with_unit< units::bit > > & get_next_offset() const
Definition symbolic-ranges.h:85
range()
Definition symbolic-ranges.h:34
static range from_endpoints(const scalar< ConcreteValueType > &start_offset, const scalar< ConcreteValueType > &next_offset)
Definition symbolic-ranges.h:57
void accept_node_visitor(node_visitor &v) const
void dump_inline_to_pp(pretty_printer *pp) const
const scalar< integer_with_unit< units::bit > > & get_start_offset() const
Definition symbolic-ranges.h:71
std::unique_ptr< text_art::tree_widget > make_dump_widget(node_dump_state &nds, const char *prefix=nullptr) const
bool operator==(const range< ConcreteValueType > &other) const
Definition symbolic-ranges.h:96
const scalar< integer_with_unit< units::bit > > * m_start_offset
Definition symbolic-ranges.h:148
Definition symbolic-scalars.h:660
Definition symbolic-scalars.h:67
Definition pretty-print.h:241
Definition tristate.h:26
Definition common.h:74
symbolic::range< ConcreteValueType > symbolic_from_concrete(const concrete::range< ConcreteValueType > &conc_range, scalar_manager< concrete_bit_size > &bit_mgr)
Definition symbolic-ranges.h:171
bool concrete_from_symbolic(const symbolic::range< ConcreteValueType > &in, concrete::range< ConcreteValueType > *out)
Definition symbolic-ranges.h:154
Definition access-diagram.h:30
symbolic::range< integer_with_unit< units::bit > > symbolic_bit_range
Definition common.h:124
bool maybe_bytes_from_bits(concrete_bit_range bits, concrete_byte_range *out)
@ other
Definition common.h:535
concrete_bit_range bits_from_bytes(concrete_byte_range bytes)
Definition concrete-ranges.h:121
symbolic::range< integer_with_unit< units::byte > > symbolic_byte_range
Definition common.h:125
Definition store.h:398
Definition store.h:507
Definition complexity.h:31
Definition symbolic-nodes.h:276