GCC Middle and Back End API Reference
concrete-ranges.h
Go to the documentation of this file.
1/* Unit-safe concrete ranges of values (e.g. "bits 16-31", "bytes 0-1023").
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_CONCRETE_RANGES_H
22#define GCC_ANALYZER_CONCRETE_RANGES_H
23
25
26namespace ana {
27namespace concrete {
28
29/* Concrete ranges of bits or bytes (or unitless). */
30
31template<typename ConcreteValueType>
32class range
33{
34public:
35 range () = default;
36
37 range (ConcreteValueType start_offset,
38 ConcreteValueType size)
39 : m_start_offset (start_offset),
40 m_size (size)
41 {
42 }
43
44 void
45 dump () const;
46
47 void
49
50 void
52
53 ConcreteValueType
54 get_start_offset () const { return m_start_offset; };
55
56 ConcreteValueType
57 get_size () const { return m_size; }
58
59 ConcreteValueType
61 {
62 return get_next_offset () - ConcreteValueType (1);
63 }
64
65 ConcreteValueType
66 get_next_offset () const { return m_start_offset + m_size; }
67
68 bool
69 contains_p (ConcreteValueType offset) const
70 {
71 return (offset >= get_start_offset ()
72 && offset < get_next_offset ());
73 }
74
75 bool
76 intersects_p (const range &other, range *out = nullptr) const;
77
78 bool
79 exceeds_p (ConcreteValueType offset,
80 range<ConcreteValueType> *out) const;
81
82 bool
83 falls_short_of_p (ConcreteValueType offset,
84 range<ConcreteValueType> *out) const;
85
86 bool
88 {
89 return (m_start_offset == other.m_start_offset
90 && m_size == other.m_size);
91 }
92
93 static int
95 const range<ConcreteValueType> &rhs);
96
97 bool
98 operator< (const range<ConcreteValueType> &other) const
99 {
100 return cmp (*this, other) < 0;
101 }
102
103 std::unique_ptr<json::object>
104 to_json () const;
105
106
107 std::unique_ptr<diagnostics::markup::node>
109
110private:
111 ConcreteValueType m_start_offset;
112 ConcreteValueType m_size;
113};
114
115} // namespace ana::concrete
116
119
126
127bool
130
131bool
132concrete_bit_range_from_mask (unsigned HOST_WIDE_INT mask,
133 concrete_bit_range *out);
134
135void
137 concrete_byte_range *out_byte_range,
138 concrete_bit_offset *out_bit_offset);
139
140} // namespace ana
141
142#endif /* GCC_ANALYZER_CONCRETE_RANGES_H */
Definition concrete-ranges.h:33
std::unique_ptr< json::object > to_json() const
bool operator<(const range< ConcreteValueType > &other) const
Definition concrete-ranges.h:98
ConcreteValueType get_last_offset() const
Definition concrete-ranges.h:60
bool intersects_p(const range &other, range *out=nullptr) const
integer_with_unit< units::bit > get_next_offset() const
Definition concrete-ranges.h:66
range(ConcreteValueType start_offset, ConcreteValueType size)
Definition concrete-ranges.h:37
integer_with_unit< units::bit > m_size
Definition concrete-ranges.h:112
ConcreteValueType get_start_offset() const
Definition concrete-ranges.h:54
bool falls_short_of_p(ConcreteValueType offset, range< ConcreteValueType > *out) const
std::unique_ptr< diagnostics::markup::node > make_markup_node() const
bool contains_p(ConcreteValueType offset) const
Definition concrete-ranges.h:69
integer_with_unit< units::bit > m_start_offset
Definition concrete-ranges.h:111
bool operator==(const range< ConcreteValueType > &other) const
Definition concrete-ranges.h:87
bool exceeds_p(ConcreteValueType offset, range< ConcreteValueType > *out) const
ConcreteValueType get_size() const
Definition concrete-ranges.h:57
void dump_to_pp_pretty(pretty_printer *pp) const
static int cmp(const range< ConcreteValueType > &lhs, const range< ConcreteValueType > &rhs)
void dump_to_pp(pretty_printer *pp) const
Definition pretty-print.h:241
Definition concrete-ranges.h:27
Definition access-diagram.h:30
integer_with_unit< units::bit > concrete_bit_offset
Definition integer-with-unit.h:329
concrete::range< integer_with_unit< units::byte > > concrete_byte_range
Definition concrete-ranges.h:118
bool concrete_bit_range_from_mask(unsigned HOST_WIDE_INT mask, concrete_bit_range *out)
bool maybe_bytes_from_bits(concrete_bit_range bits, concrete_byte_range *out)
concrete::range< integer_with_unit< units::bit > > concrete_bit_range
Definition concrete-ranges.h:117
@ other
Definition common.h:535
concrete_bit_range bits_from_bytes(concrete_byte_range bytes)
Definition concrete-ranges.h:121
void get_smallest_enclosing_byte_range(const concrete_bit_range &in_bit_range, concrete_byte_range *out_byte_range, concrete_bit_offset *out_bit_offset)