CBMC
Loading...
Searching...
No Matches
goto_rw.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening
6
7Date: April 2010
8
9\*******************************************************************/
10
11
12#ifndef CPROVER_ANALYSES_GOTO_RW_H
13#define CPROVER_ANALYSES_GOTO_RW_H
14
15#include <util/mp_arith.h>
16
18
19#include "guard.h"
20
21#include <iosfwd>
22#include <map>
23#include <memory> // unique_ptr
24
25class goto_functionst;
27class rw_range_sett;
28
29void goto_rw(
30 const irep_idt &function,
33
34void goto_rw(
35 const irep_idt &function,
36 const goto_programt &,
38
39void goto_rw(const goto_functionst &,
40 const irep_idt &function,
42
44{
45public:
47
50
53
54 virtual ~range_domain_baset();
55
56 virtual void output(const namespacet &ns, std::ostream &out) const=0;
57};
58
63{
64public:
65 using value_type = int;
66
67 explicit range_spect(value_type v) : v(v)
68 {
69 }
70
72 {
73 return range_spect{-1};
74 }
75
76 bool is_unknown() const
77 {
78 return *this == unknown();
79 }
80
82 {
83 // The size need not fit into the analysis platform's width of a signed long
84 // (as an example, it could be an unsigned size_t max, or perhaps the source
85 // platform has much wider types than the analysis platform.
86 if(!size.is_long())
87 return range_spect::unknown();
88
89 mp_integer::llong_t ll = size.to_long();
90 if(
91 ll > std::numeric_limits<range_spect::value_type>::max() ||
92 ll < std::numeric_limits<range_spect::value_type>::min())
93 {
94 return range_spect::unknown();
95 }
96
97 return range_spect{(value_type)ll};
98 }
99
100 bool operator<(const range_spect &other) const
101 {
102 PRECONDITION(!is_unknown() && !other.is_unknown());
103 return v < other.v;
104 }
105
106 bool operator<=(const range_spect &other) const
107 {
108 PRECONDITION(!is_unknown() && !other.is_unknown());
109 return v <= other.v;
110 }
111
112 bool operator>(const range_spect &other) const
113 {
114 PRECONDITION(!is_unknown() && !other.is_unknown());
115 return v > other.v;
116 }
117
118 bool operator>=(const range_spect &other) const
119 {
120 PRECONDITION(!is_unknown() && !other.is_unknown());
121 return v >= other.v;
122 }
123
124 bool operator==(const range_spect &other) const
125 {
126 return v == other.v;
127 }
128
130 {
131 if(is_unknown() || other.is_unknown())
132 return range_spect::unknown();
134 }
135
137 {
138 range_spect result = *this + other;
139 v = result.v;
140 return *this;
141 }
142
144 {
145 if(is_unknown() || other.is_unknown())
146 return range_spect::unknown();
148 }
149
151 {
152 range_spect result = *this - other;
153 v = result.v;
154 return *this;
155 }
156
158 {
159 if(is_unknown() || other.is_unknown())
160 return range_spect::unknown();
162 }
163
164private:
166 friend std::ostream &operator<<(std::ostream &, const range_spect &);
167};
168
169inline std::ostream &operator<<(std::ostream &os, const range_spect &r)
170{
171 os << r.v;
172 return os;
173}
174
175// each element x represents a range of bits [x.first, x.second.first)
177{
178 typedef std::list<std::pair<range_spect, range_spect>> sub_typet;
180
181public:
182 void output(const namespacet &ns, std::ostream &out) const override;
183
184 // NOLINTNEXTLINE(readability/identifiers)
185 typedef sub_typet::iterator iterator;
186 // NOLINTNEXTLINE(readability/identifiers)
187 typedef sub_typet::const_iterator const_iterator;
188
189 iterator begin() { return data.begin(); }
190 const_iterator begin() const { return data.begin(); }
191 const_iterator cbegin() const { return data.begin(); }
192
193 iterator end() { return data.end(); }
194 const_iterator end() const { return data.end(); }
195 const_iterator cend() const { return data.end(); }
196
197 void push_back(const sub_typet::value_type &v) { data.push_back(v); }
198 void push_back(sub_typet::value_type &&v) { data.push_back(std::move(v)); }
199};
200
203class shift_exprt;
204
206{
207public:
208 typedef std::map<irep_idt, std::unique_ptr<range_domain_baset>> objectst;
209
210 virtual ~rw_range_sett();
211
216
217 const objectst &get_r_set() const
218 {
219 return r_range_set;
220 }
221
222 const objectst &get_w_set() const
223 {
224 return w_range_set;
225 }
226
227 const range_domaint &
228 get_ranges(const std::unique_ptr<range_domain_baset> &ranges) const
229 {
230 PRECONDITION(dynamic_cast<range_domaint *>(ranges.get()) != nullptr);
231 return static_cast<const range_domaint &>(*ranges);
232 }
233
234 enum class get_modet { LHS_W, READ };
235
236 virtual void get_objects_rec(
237 const irep_idt &,
239 get_modet mode,
240 const exprt &expr)
241 {
242 get_objects_rec(mode, expr);
243 }
244
245 virtual void get_objects_rec(
246 const irep_idt &,
248 const typet &type)
249 {
250 get_objects_rec(type);
251 }
252
253 virtual void get_array_objects(
254 const irep_idt &,
256 get_modet,
257 const exprt &);
258
259 void output(std::ostream &out) const;
260
261protected:
264
266
267 virtual void get_objects_rec(
268 get_modet mode,
269 const exprt &expr);
270
271 virtual void get_objects_rec(const typet &type);
272
273 virtual void get_objects_complex_real(
274 get_modet mode,
275 const complex_real_exprt &expr,
277 const range_spect &size);
278
279 virtual void get_objects_complex_imag(
280 get_modet mode,
281 const complex_imag_exprt &expr,
283 const range_spect &size);
284
285 virtual void get_objects_if(
286 get_modet mode,
287 const if_exprt &if_expr,
289 const range_spect &size);
290
291 // overload to include expressions read/written
292 // through dereferencing
293 virtual void get_objects_dereference(
294 get_modet mode,
297 const range_spect &size);
298
299 virtual void get_objects_byte_extract(
300 get_modet mode,
301 const byte_extract_exprt &be,
303 const range_spect &size);
304
305 virtual void get_objects_shift(
306 get_modet mode,
307 const shift_exprt &shift,
309 const range_spect &size);
310
311 virtual void get_objects_member(
312 get_modet mode,
313 const member_exprt &expr,
315 const range_spect &size);
316
317 virtual void get_objects_index(
318 get_modet mode,
319 const index_exprt &expr,
321 const range_spect &size);
322
323 virtual void get_objects_array(
324 get_modet mode,
325 const array_exprt &expr,
327 const range_spect &size);
328
329 virtual void get_objects_struct(
330 get_modet mode,
331 const struct_exprt &expr,
333 const range_spect &size);
334
335 virtual void get_objects_typecast(
336 get_modet mode,
337 const typecast_exprt &tc,
339 const range_spect &size);
340
341 virtual void get_objects_address_of(const exprt &object);
342
343 virtual void get_objects_rec(
344 get_modet mode,
345 const exprt &expr,
347 const range_spect &size);
348
349 virtual void add(
350 get_modet mode,
351 const irep_idt &identifier,
353 const range_spect &range_end);
354};
355
356inline std::ostream &operator << (
357 std::ostream &out,
358 const rw_range_sett &rw_set)
359{
360 rw_set.output(out);
361 return out;
362}
363
364class value_setst;
365
367{
368public:
376
378 const irep_idt &_function,
380 get_modet mode,
381 const exprt &expr) override
382 {
385
387 }
388
390 const irep_idt &_function,
392 const typet &type) override
393 {
395 target = _target;
396
398 }
399
401 const irep_idt &_function,
403 get_modet mode,
404 const exprt &pointer) override
405 {
407 target = _target;
408
410 }
411
412protected:
416
418
420 get_modet mode,
423 const range_spect &size) override;
424};
425
427{
428 typedef std::multimap<range_spect, std::pair<range_spect, exprt>> sub_typet;
430
431public:
432 virtual void output(const namespacet &ns, std::ostream &out) const override;
433
434 // NOLINTNEXTLINE(readability/identifiers)
435 typedef sub_typet::iterator iterator;
436 // NOLINTNEXTLINE(readability/identifiers)
437 typedef sub_typet::const_iterator const_iterator;
438
439 iterator begin() { return data.begin(); }
440 const_iterator begin() const { return data.begin(); }
441 const_iterator cbegin() const { return data.begin(); }
442
443 iterator end() { return data.end(); }
444 const_iterator end() const { return data.end(); }
445 const_iterator cend() const { return data.end(); }
446
447 iterator insert(const sub_typet::value_type &v)
448 {
449 return data.insert(v);
450 }
451
452 iterator insert(sub_typet::value_type &&v)
453 {
454 return data.insert(std::move(v));
455 }
456};
457
459{
460public:
471
473 get_ranges(const std::unique_ptr<range_domain_baset> &ranges) const
474 {
476 dynamic_cast<guarded_range_domaint *>(ranges.get()) != nullptr);
477 return static_cast<const guarded_range_domaint &>(*ranges);
478 }
479
481 const irep_idt &_function,
483 get_modet mode,
484 const exprt &expr) override
485 {
487
489 }
490
492 const irep_idt &function,
494 const typet &type) override
495 {
497 }
498
499protected:
502
504
505 void get_objects_if(
506 get_modet mode,
507 const if_exprt &if_expr,
509 const range_spect &size) override;
510
511 void add(
512 get_modet mode,
513 const irep_idt &identifier,
515 const range_spect &range_end) override;
516};
517
518#endif // CPROVER_ANALYSES_GOTO_RW_H
virtual void output(const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program, std::ostream &out) const
Output the abstract states for a single function.
Definition ai.cpp:39
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
Array constructor from list of elements.
Definition std_expr.h:1570
Expression of type type extracted from some object op starting at position offset (given in number of...
Imaginary part of the expression describing a complex number.
Definition std_expr.h:1957
Real part of the expression describing a complex number.
Definition std_expr.h:1920
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:57
A collection of goto functions.
A generic container class for the GOTO intermediate representation of one function.
instructionst::const_iterator const_targett
const_iterator cbegin() const
Definition goto_rw.h:441
iterator insert(const sub_typet::value_type &v)
Definition goto_rw.h:447
iterator insert(sub_typet::value_type &&v)
Definition goto_rw.h:452
const_iterator begin() const
Definition goto_rw.h:440
virtual void output(const namespacet &ns, std::ostream &out) const override
Definition goto_rw.cpp:714
sub_typet::const_iterator const_iterator
Definition goto_rw.h:437
sub_typet::iterator iterator
Definition goto_rw.h:435
const_iterator cend() const
Definition goto_rw.h:445
std::multimap< range_spect, std::pair< range_spect, exprt > > sub_typet
Definition goto_rw.h:428
const_iterator end() const
Definition goto_rw.h:444
The trinary if-then-else operator.
Definition std_expr.h:2426
Array index operator.
Definition std_expr.h:1431
Extract member of struct or union.
Definition std_expr.h:2866
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
virtual ~range_domain_baset()
Definition goto_rw.cpp:30
range_domain_baset & operator=(range_domain_baset &&rhs)=delete
virtual void output(const namespacet &ns, std::ostream &out) const =0
range_domain_baset(range_domain_baset &&rhs)=delete
range_domain_baset()=default
range_domain_baset(const range_domain_baset &rhs)=delete
range_domain_baset & operator=(const range_domain_baset &rhs)=delete
sub_typet::iterator iterator
Definition goto_rw.h:185
void output(const namespacet &ns, std::ostream &out) const override
Definition goto_rw.cpp:34
iterator end()
Definition goto_rw.h:193
std::list< std::pair< range_spect, range_spect > > sub_typet
Definition goto_rw.h:178
sub_typet::const_iterator const_iterator
Definition goto_rw.h:187
iterator begin()
Definition goto_rw.h:189
sub_typet data
Definition goto_rw.h:179
const_iterator cbegin() const
Definition goto_rw.h:191
const_iterator cend() const
Definition goto_rw.h:195
void push_back(sub_typet::value_type &&v)
Definition goto_rw.h:198
void push_back(const sub_typet::value_type &v)
Definition goto_rw.h:197
const_iterator end() const
Definition goto_rw.h:194
const_iterator begin() const
Definition goto_rw.h:190
Data type to describe upper and lower bounds of the range of bits that a read or write access may aff...
Definition goto_rw.h:63
friend std::ostream & operator<<(std::ostream &, const range_spect &)
Definition goto_rw.h:169
bool operator>(const range_spect &other) const
Definition goto_rw.h:112
static range_spect unknown()
Definition goto_rw.h:71
range_spect operator*(const range_spect &other) const
Definition goto_rw.h:157
range_spect & operator+=(const range_spect &other)
Definition goto_rw.h:136
range_spect operator+(const range_spect &other) const
Definition goto_rw.h:129
range_spect(value_type v)
Definition goto_rw.h:67
static range_spect to_range_spect(const mp_integer &size)
Definition goto_rw.h:81
bool is_unknown() const
Definition goto_rw.h:76
value_type v
Definition goto_rw.h:165
bool operator<=(const range_spect &other) const
Definition goto_rw.h:106
bool operator==(const range_spect &other) const
Definition goto_rw.h:124
bool operator>=(const range_spect &other) const
Definition goto_rw.h:118
int value_type
Definition goto_rw.h:65
bool operator<(const range_spect &other) const
Definition goto_rw.h:100
range_spect operator-(const range_spect &other) const
Definition goto_rw.h:143
range_spect & operator-=(const range_spect &other)
Definition goto_rw.h:150
void get_objects_rec(const irep_idt &function, goto_programt::const_targett target, const typet &type) override
Definition goto_rw.h:491
rw_guarded_range_set_value_sett(const namespacet &_ns, value_setst &_value_sets, guard_managert &guard_manager, message_handlert &message_handler)
Definition goto_rw.h:461
void get_objects_rec(const irep_idt &_function, goto_programt::const_targett _target, get_modet mode, const exprt &expr) override
Definition goto_rw.h:480
const guarded_range_domaint & get_ranges(const std::unique_ptr< range_domain_baset > &ranges) const
Definition goto_rw.h:473
void get_objects_if(get_modet mode, const if_exprt &if_expr, const range_spect &range_start, const range_spect &size) override
Definition goto_rw.cpp:732
guard_managert & guard_manager
Definition goto_rw.h:500
void add(get_modet mode, const irep_idt &identifier, const range_spect &range_start, const range_spect &range_end) override
Definition goto_rw.cpp:758
void get_objects_dereference(get_modet mode, const dereference_exprt &deref, const range_spect &range_start, const range_spect &size) override
Definition goto_rw.cpp:676
void get_array_objects(const irep_idt &_function, goto_programt::const_targett _target, get_modet mode, const exprt &pointer) override
Definition goto_rw.h:400
rw_range_set_value_sett(const namespacet &_ns, value_setst &_value_sets, message_handlert &message_handler)
Definition goto_rw.h:369
void get_objects_rec(const irep_idt &_function, goto_programt::const_targett _target, const typet &type) override
Definition goto_rw.h:389
value_setst & value_sets
Definition goto_rw.h:413
goto_programt::const_targett target
Definition goto_rw.h:415
void get_objects_rec(const irep_idt &_function, goto_programt::const_targett _target, get_modet mode, const exprt &expr) override
Definition goto_rw.h:377
void output(std::ostream &out) const
Definition goto_rw.cpp:61
objectst r_range_set
Definition goto_rw.h:265
virtual void get_objects_dereference(get_modet mode, const dereference_exprt &deref, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:132
std::map< irep_idt, std::unique_ptr< range_domain_baset > > objectst
Definition goto_rw.h:208
virtual void get_objects_complex_real(get_modet mode, const complex_real_exprt &expr, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:82
message_handlert & message_handler
Definition goto_rw.h:263
virtual ~rw_range_sett()
Definition goto_rw.cpp:48
const objectst & get_w_set() const
Definition goto_rw.h:222
virtual void get_objects_shift(get_modet mode, const shift_exprt &shift, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:186
virtual void get_objects_index(get_modet mode, const index_exprt &expr, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:271
virtual void get_objects_struct(get_modet mode, const struct_exprt &expr, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:366
virtual void get_objects_complex_imag(get_modet mode, const complex_imag_exprt &expr, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:91
virtual void get_objects_if(get_modet mode, const if_exprt &if_expr, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:113
virtual void get_objects_address_of(const exprt &object)
Definition goto_rw.cpp:468
rw_range_sett(const namespacet &_ns, message_handlert &message_handler)
Definition goto_rw.h:212
objectst w_range_set
Definition goto_rw.h:265
virtual void get_array_objects(const irep_idt &, goto_programt::const_targett, get_modet, const exprt &)
Definition goto_rw.cpp:664
virtual void get_objects_rec(const irep_idt &, goto_programt::const_targett, const typet &type)
Definition goto_rw.h:245
const objectst & get_r_set() const
Definition goto_rw.h:217
virtual void get_objects_byte_extract(get_modet mode, const byte_extract_exprt &be, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:144
virtual void get_objects_rec(const irep_idt &, goto_programt::const_targett, get_modet mode, const exprt &expr)
Definition goto_rw.h:236
virtual void get_objects_member(get_modet mode, const member_exprt &expr, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:237
const namespacet & ns
Definition goto_rw.h:262
virtual void add(get_modet mode, const irep_idt &identifier, const range_spect &range_start, const range_spect &range_end)
Definition goto_rw.cpp:520
virtual void get_objects_typecast(get_modet mode, const typecast_exprt &tc, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:440
const range_domaint & get_ranges(const std::unique_ptr< range_domain_baset > &ranges) const
Definition goto_rw.h:228
virtual void get_objects_array(get_modet mode, const array_exprt &expr, const range_spect &range_start, const range_spect &size)
Definition goto_rw.cpp:322
A base class for shift and rotate operators.
Struct constructor from list of elements.
Definition std_expr.h:1820
The Boolean constant true.
Definition std_expr.h:3126
Semantic type conversion.
Definition std_expr.h:1995
The type of an expression, extends irept.
Definition type.h:29
Concrete Goto Program.
void goto_rw(const irep_idt &function, goto_programt::const_targett target, rw_range_sett &rw_set)
Definition goto_rw.cpp:867
std::ostream & operator<<(std::ostream &os, const range_spect &r)
Definition goto_rw.h:169
Guard Data Structure.
guard_exprt guardt
Definition guard.h:29
static int8_t r
Definition irep_hash.h:60
get_modet
Definition object_id.cpp:18
#define PRECONDITION(CONDITION)
Definition invariant.h:463
This is unused by this implementation of guards, but can be used by other implementations of the same...
Definition guard_expr.h:20