CBMC
Loading...
Searching...
No Matches
simplify_expr_pointer.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
10
11#include "arith_tools.h"
12#include "c_types.h"
13#include "expr_util.h"
14#include "namespace.h"
15#include "pointer_expr.h"
16#include "pointer_offset_size.h"
17#include "pointer_predicates.h"
18#include "std_expr.h"
19#include "string_constant.h"
20
22 const exprt &expr,
23 mp_integer &address)
24{
25 if(expr.id() == ID_dereference)
26 {
27 const auto &pointer = to_dereference_expr(expr).pointer();
28
29 if(
30 pointer.id() == ID_typecast &&
31 to_typecast_expr(pointer).op().is_constant() &&
32 !to_integer(to_constant_expr(to_typecast_expr(pointer).op()), address))
33 {
34 return true;
35 }
36
37 if(pointer.is_constant())
38 {
39 const constant_exprt &constant = to_constant_expr(pointer);
40
41 if(constant.is_null_pointer())
42 {
43 address=0;
44 return true;
45 }
46 else if(!to_integer(constant, address))
47 return true;
48 }
49 }
50
51 return false;
52}
53
56 const unary_exprt &expr)
57{
58 const exprt &pointer = expr.op();
59 PRECONDITION(pointer.type().id() == ID_pointer);
60
61 if(pointer.id() == ID_if)
62 {
63 if_exprt if_expr = lift_if(expr, 0);
64 return changed(simplify_if_preorder(if_expr));
65 }
66 else
67 {
68 auto r_it = simplify_rec(pointer); // recursive call
69 if(r_it.has_changed())
70 {
71 auto tmp = expr;
72 tmp.op() = r_it.expr;
73 return tmp;
74 }
75 }
76
77 return unchanged(expr);
78}
79
82{
83 if(expr.id()==ID_index)
84 {
85 auto new_index_expr = to_index_expr(expr);
86
87 bool no_change = true;
88
89 auto array_result = simplify_address_of_arg(new_index_expr.array());
90
91 if(array_result.has_changed())
92 {
93 no_change = false;
94 new_index_expr.array() = array_result.expr;
95 }
96
97 auto index_result = simplify_rec(new_index_expr.index());
98
99 if(index_result.has_changed())
100 {
101 no_change = false;
102 new_index_expr.index() = index_result.expr;
103 }
104
105 // rewrite (*(type *)int) [index] by
106 // pushing the index inside
107
108 mp_integer address;
109 if(is_dereference_integer_object(new_index_expr.array(), address))
110 {
111 // push index into address
112 auto step_size = pointer_offset_size(new_index_expr.type(), ns);
113
114 if(step_size.has_value())
115 {
116 const auto index = numeric_cast<mp_integer>(new_index_expr.index());
117
118 if(index.has_value())
119 {
121 to_dereference_expr(new_index_expr.array()).pointer().type());
122 pointer_type.base_type() = new_index_expr.type();
123
124 typecast_exprt typecast_expr(
126 (*step_size) * (*index) + bytest{address}, c_index_type()),
128
129 return dereference_exprt{typecast_expr};
130 }
131 }
132 }
133
134 if(!no_change)
135 return new_index_expr;
136 }
137 else if(expr.id()==ID_member)
138 {
139 auto new_member_expr = to_member_expr(expr);
140
141 bool no_change = true;
142
143 auto struct_op_result =
144 simplify_address_of_arg(new_member_expr.struct_op());
145
146 if(struct_op_result.has_changed())
147 {
148 new_member_expr.struct_op() = struct_op_result.expr;
149 no_change = false;
150 }
151
152 const typet &op_type = new_member_expr.struct_op().type();
153
154 if(op_type.id() == ID_struct || op_type.id() == ID_struct_tag)
155 {
156 // rewrite NULL -> member by
157 // pushing the member inside
158
159 mp_integer address;
160 if(is_dereference_integer_object(new_member_expr.struct_op(), address))
161 {
162 const struct_typet &struct_type =
163 op_type.id() == ID_struct_tag
164 ? ns.follow_tag(to_struct_tag_type(op_type))
165 : to_struct_type(op_type);
166 const irep_idt &member = to_member_expr(expr).get_component_name();
167 auto offset = member_offset(struct_type, member, ns);
168 if(offset.has_value())
169 {
171 to_dereference_expr(new_member_expr.struct_op()).pointer().type());
172 pointer_type.base_type() = new_member_expr.type();
173 typecast_exprt typecast_expr(
174 from_integer(bytest{address} + *offset, c_index_type()),
176 return dereference_exprt{typecast_expr};
177 }
178 }
179 }
180
181 if(!no_change)
182 return new_member_expr;
183 }
184 else if(expr.id()==ID_dereference)
185 {
186 auto new_expr = to_dereference_expr(expr);
187 auto r_pointer = simplify_rec(new_expr.pointer());
188 if(r_pointer.has_changed())
189 {
190 new_expr.pointer() = r_pointer.expr;
191 return std::move(new_expr);
192 }
193 }
194 else if(expr.id()==ID_if)
195 {
196 auto new_if_expr = to_if_expr(expr);
197
198 bool no_change = true;
199
200 auto r_cond = simplify_rec(new_if_expr.cond());
201 if(r_cond.has_changed())
202 {
203 new_if_expr.cond() = r_cond.expr;
204 no_change = false;
205 }
206
207 auto true_result = simplify_address_of_arg(new_if_expr.true_case());
208 if(true_result.has_changed())
209 {
210 new_if_expr.true_case() = true_result.expr;
211 no_change = false;
212 }
213
214 auto false_result = simplify_address_of_arg(new_if_expr.false_case());
215
216 if(false_result.has_changed())
217 {
218 new_if_expr.false_case() = false_result.expr;
219 no_change = false;
220 }
221
222 // condition is a constant?
223 if(new_if_expr.cond() == true)
224 {
225 return new_if_expr.true_case();
226 }
227 else if(new_if_expr.cond() == false)
228 {
229 return new_if_expr.false_case();
230 }
231
232 if(!no_change)
233 return new_if_expr;
234 }
235
236 return unchanged(expr);
237}
238
241{
242 if(expr.type().id() != ID_pointer)
243 return unchanged(expr);
244
245 auto new_object = simplify_address_of_arg(expr.object());
246
247 if(new_object.expr.id() == ID_index)
248 {
249 auto index_expr = to_index_expr(new_object.expr);
250
251 if(index_expr.index() != 0)
252 {
253 // we normalize &a[i] to (&a[0])+i
254 exprt offset = index_expr.op1();
255 index_expr.op1()=from_integer(0, offset.type());
256 auto new_address_of_expr = expr;
257 new_address_of_expr.object() = std::move(index_expr);
258 return plus_exprt(std::move(new_address_of_expr), offset);
259 }
260 }
261 else if(new_object.expr.id() == ID_dereference)
262 {
263 // simplify &*p to p
264 return to_dereference_expr(new_object.expr).pointer();
265 }
266
267 if(new_object.has_changed())
268 {
269 auto new_expr = expr;
270 new_expr.object() = new_object;
271 return new_expr;
272 }
273 else
274 return unchanged(expr);
275}
276
279{
280 const exprt &ptr = expr.pointer();
281
282 if(ptr.type().id()!=ID_pointer)
283 return unchanged(expr);
284
285 if(ptr.id()==ID_address_of)
286 {
287 auto offset = compute_pointer_offset(to_address_of_expr(ptr).object(), ns);
288
289 if(offset.has_value())
290 return from_integer(*offset, expr.type());
291 }
292 else if(ptr.id()==ID_typecast) // pointer typecast
293 {
294 const auto &op = to_typecast_expr(ptr).op();
295 const typet &op_type = op.type();
296
297 if(op_type.id()==ID_pointer)
298 {
299 // Cast from pointer to pointer.
300 // This just passes through, remove typecast.
301 auto new_expr = expr;
302 new_expr.op() = op;
303
304 return changed(simplify_pointer_offset(new_expr)); // recursive call
305 }
306 else if(op_type.id()==ID_signedbv ||
307 op_type.id()==ID_unsignedbv)
308 {
309 // Cast from integer to pointer, say (int *)x.
310
311 if(op.is_constant())
312 {
313 // (T *)0x1234 -> 0x1234
314 return changed(simplify_typecast(typecast_exprt{op, expr.type()}));
315 }
316 else
317 {
318 // We do a bit of special treatment for (TYPE *)(a+(int)&o),
319 // which is re-written to 'a'.
320
321 typet type = expr.type();
322 exprt tmp = op;
323 if(tmp.id()==ID_plus && tmp.operands().size()==2)
324 {
325 const auto &plus_expr = to_plus_expr(tmp);
326
327 if(
328 plus_expr.op0().id() == ID_typecast &&
329 to_typecast_expr(plus_expr.op0()).op().id() == ID_address_of)
330 {
331 auto new_expr =
332 typecast_exprt::conditional_cast(plus_expr.op1(), type);
333
334 return changed(simplify_node(new_expr));
335 }
336 else if(
337 plus_expr.op1().id() == ID_typecast &&
338 to_typecast_expr(plus_expr.op1()).op().id() == ID_address_of)
339 {
340 auto new_expr =
341 typecast_exprt::conditional_cast(plus_expr.op0(), type);
342
343 return changed(simplify_node(new_expr));
344 }
345 }
346 }
347 }
348 }
349 else if(ptr.id()==ID_plus) // pointer arithmetic
350 {
351 exprt::operandst ptr_expr;
352 exprt::operandst int_expr;
353
354 for(const auto &op : ptr.operands())
355 {
356 if(op.type().id()==ID_pointer)
357 ptr_expr.push_back(op);
358 else if(op != 0)
359 {
360 exprt tmp=op;
361 if(tmp.type()!=expr.type())
362 tmp = simplify_typecast(typecast_exprt(tmp, expr.type()));
363
364 int_expr.push_back(tmp);
365 }
366 }
367
368 if(ptr_expr.size()!=1 || int_expr.empty())
369 return unchanged(expr);
370
371 typet pointer_base_type =
372 to_pointer_type(ptr_expr.front().type()).base_type();
373 if(pointer_base_type.id() == ID_empty)
374 pointer_base_type = char_type();
375
376 auto element_size = pointer_offset_size(pointer_base_type, ns);
377
378 if(!element_size.has_value())
379 return unchanged(expr);
380
381 exprt pointer_offset_expr = simplify_pointer_offset(
382 pointer_offset_exprt(ptr_expr.front(), expr.type()));
383
384 exprt sum;
385
386 if(int_expr.size()==1)
387 sum=int_expr.front();
388 else
389 sum = simplify_plus(plus_exprt{int_expr, expr.type()});
390
391 exprt size_expr = from_integer(*element_size, expr.type());
392
393 exprt product = simplify_mult(mult_exprt{sum, size_expr});
394
395 auto new_expr = plus_exprt(pointer_offset_expr, product);
396
397 return changed(simplify_plus(new_expr));
398 }
399 else if(ptr.is_constant())
400 {
401 const constant_exprt &c_ptr = to_constant_expr(ptr);
402
403 if(c_ptr.is_null_pointer())
404 {
405 return from_integer(0, expr.type());
406 }
407 }
408
409 return unchanged(expr);
410}
411
413 const binary_relation_exprt &expr)
414{
415 // the operands of the relation are both either one of
416 // a) an address_of_exprt
417 // b) a typecast_exprt with an address_of_exprt operand
418
419 PRECONDITION(expr.id() == ID_equal || expr.id() == ID_notequal);
420
421 // skip over the typecast
422 exprt tmp0 = skip_typecast(expr.op0());
423 PRECONDITION(tmp0.id() == ID_address_of);
424
425 auto &tmp0_address_of = to_address_of_expr(tmp0);
426
427 if(
428 tmp0_address_of.object().id() == ID_index &&
429 to_index_expr(tmp0_address_of.object()).index() == 0)
430 {
431 tmp0_address_of =
432 address_of_exprt(to_index_expr(tmp0_address_of.object()).array());
433 }
434
435 // skip over the typecast
436 exprt tmp1 = skip_typecast(expr.op1());
437 PRECONDITION(tmp1.id() == ID_address_of);
438
439 auto &tmp1_address_of = to_address_of_expr(tmp1);
440
441 if(
442 tmp1_address_of.object().id() == ID_index &&
443 to_index_expr(tmp1_address_of.object()).index() == 0)
444 {
445 tmp1 = address_of_exprt(to_index_expr(tmp1_address_of.object()).array());
446 }
447
448 const auto &tmp0_object = tmp0_address_of.object();
449 const auto &tmp1_object = tmp1_address_of.object();
450
451 if(tmp0_object.id() == ID_symbol && tmp1_object.id() == ID_symbol)
452 {
453 bool equal = to_symbol_expr(tmp0_object).identifier() ==
454 to_symbol_expr(tmp1_object).identifier();
455
456 return make_boolean_expr(expr.id() == ID_equal ? equal : !equal);
457 }
458 else if(
459 tmp0_object.id() == ID_dynamic_object &&
460 tmp1_object.id() == ID_dynamic_object)
461 {
462 bool equal = to_dynamic_object_expr(tmp0_object).get_instance() ==
464
465 return make_boolean_expr(expr.id() == ID_equal ? equal : !equal);
466 }
467 else if(
468 (tmp0_object.id() == ID_symbol && tmp1_object.id() == ID_dynamic_object) ||
469 (tmp0_object.id() == ID_dynamic_object && tmp1_object.id() == ID_symbol))
470 {
471 return make_boolean_expr(expr.id() != ID_equal);
472 }
473 else if(
474 tmp0_object.id() == ID_string_constant &&
475 tmp1_object.id() == ID_string_constant && tmp0_object == tmp1_object)
476 {
477 return make_boolean_expr(expr.id() == ID_equal);
478 }
479
480 return unchanged(expr);
481}
482
484 const binary_relation_exprt &expr)
485{
486 PRECONDITION(expr.id() == ID_equal || expr.id() == ID_notequal);
487 PRECONDITION(expr.is_boolean());
488
489 exprt::operandst new_inequality_ops;
490 for(const auto &operand : expr.operands())
491 {
492 PRECONDITION(operand.id() == ID_pointer_object);
493 const exprt &op = to_pointer_object_expr(operand).pointer();
494
495 if(op.id()==ID_address_of)
496 {
497 const auto &op_object = to_address_of_expr(op).object();
498
499 if((op_object.id() != ID_symbol && op_object.id() != ID_dynamic_object &&
500 op_object.id() != ID_string_constant))
501 {
502 return unchanged(expr);
503 }
504 }
505 else if(!op.is_constant() || op != 0)
506 {
507 return unchanged(expr);
508 }
509
510 if(new_inequality_ops.empty())
511 new_inequality_ops.push_back(op);
512 else
513 {
514 new_inequality_ops.push_back(
516 op, new_inequality_ops.front().type())));
517 }
518 }
519
520 auto new_expr = expr;
521
522 new_expr.operands() = std::move(new_inequality_ops);
523
524 return changed(simplify_inequality(new_expr));
525}
526
529{
530 const exprt &op = expr.pointer();
531
532 auto op_result = simplify_object(op);
533
534 if(op_result.expr.id() == ID_if)
535 {
536 const if_exprt &if_expr = to_if_expr(op_result.expr);
537 exprt cond=if_expr.cond();
538
539 auto p_o_false = expr;
540 p_o_false.op() = if_expr.false_case();
541
542 auto p_o_true = expr;
543 p_o_true.op() = if_expr.true_case();
544
545 auto new_expr = if_exprt(cond, p_o_true, p_o_false, expr.type());
546 return changed(simplify_rec(new_expr));
547 }
548
549 if(op_result.has_changed())
550 {
551 auto new_expr = expr;
552 new_expr.op() = op_result;
553 return std::move(new_expr);
554 }
555 else
556 return unchanged(expr);
557}
558
561{
562 auto new_expr = expr;
563 exprt &op = new_expr.op();
564
565 bool no_change = true;
566
567 auto op_result = simplify_object(op);
568
569 if(op_result.has_changed())
570 {
571 op = op_result.expr;
572 no_change = false;
573 }
574
575 // NULL is not dynamic
576 if(op.is_constant() && to_constant_expr(op).is_null_pointer())
577 return false_exprt();
578
579 // &something depends on the something
580 if(op.id() == ID_address_of)
581 {
582 const auto &op_object = to_address_of_expr(op).object();
583
584 if(op_object.id() == ID_symbol)
585 {
586 const irep_idt identifier = to_symbol_expr(op_object).identifier();
587
588 // this is for the benefit of symex
589 return make_boolean_expr(
590 identifier.starts_with(SYMEX_DYNAMIC_PREFIX "::"));
591 }
592 else if(op_object.id() == ID_string_constant)
593 {
594 return false_exprt();
595 }
596 else if(op_object.id() == ID_array)
597 {
598 return false_exprt();
599 }
600 }
601
602 if(no_change)
603 return unchanged(expr);
604 else
605 return std::move(new_expr);
606}
607
610{
611 auto new_expr = expr;
612 exprt &op = new_expr.op();
613 bool no_change = true;
614
615 auto op_result = simplify_object(op);
616
617 if(op_result.has_changed())
618 {
619 op = op_result.expr;
620 no_change = false;
621 }
622
623 // NULL is not invalid
624 if(op.is_constant() && to_constant_expr(op).is_null_pointer())
625 {
626 return false_exprt();
627 }
628
629 // &anything is not invalid
630 if(op.id()==ID_address_of)
631 {
632 return false_exprt();
633 }
634
635 if(no_change)
636 return unchanged(expr);
637 else
638 return std::move(new_expr);
639}
640
643{
644 auto new_expr = expr;
645 bool no_change = true;
646 exprt &op = new_expr.pointer();
647 auto op_result = simplify_object(op);
648
649 if(op_result.has_changed())
650 {
651 op = op_result.expr;
652 no_change = false;
653 }
654
655 if(op.id() == ID_address_of)
656 {
657 const auto &op_object = to_address_of_expr(op).object();
658
659 if(op_object.id() == ID_symbol)
660 {
661 // just get the type
662 auto size_opt = size_of_expr(op_object.type(), ns);
663
664 if(size_opt.has_value())
665 {
666 const typet &expr_type = expr.type();
667 exprt size = size_opt.value();
668
669 if(size.type() != expr_type)
670 size = simplify_typecast(typecast_exprt(size, expr_type));
671
672 return size;
673 }
674 }
675 else if(op_object.id() == ID_string_constant)
676 {
677 typet type=expr.type();
678 return from_integer(
679 to_string_constant(op_object).value().size() + 1, type);
680 }
681 }
682
683 if(no_change)
684 return unchanged(expr);
685 else
686 return std::move(new_expr);
687}
688
690 const prophecy_r_or_w_ok_exprt &expr)
691{
692 exprt new_expr = simplify_rec(expr.lower(ns));
693 if(!new_expr.is_constant())
694 return unchanged(expr);
695 else
696 return std::move(new_expr);
697}
698
701{
702 exprt new_expr = simplify_rec(expr.lower(ns));
703 if(!new_expr.is_constant())
704 return unchanged(expr);
705 else
706 return std::move(new_expr);
707}
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
bool to_integer(const constant_exprt &expr, mp_integer &int_value)
Convert a constant expression expr to an arbitrary-precision integer.
std::optional< Target > numeric_cast(const exprt &arg)
Converts an expression to any integral type.
pointer_typet pointer_type(const typet &subtype)
Definition c_types.cpp:235
bitvector_typet char_type()
Definition c_types.cpp:106
bitvector_typet c_index_type()
Definition c_types.cpp:16
Operator to return the address of an object.
exprt & op0()
Definition expr.h:134
exprt & op1()
Definition expr.h:137
A base class for relations, i.e., binary predicates whose two operands have the same type.
Definition std_expr.h:784
A constant literal expression.
Definition std_expr.h:3007
bool is_null_pointer() const
Returns true if expr has a pointer type and a value NULL; it also returns true when expr has value ze...
Definition std_expr.cpp:170
Operator to dereference a pointer.
bool starts_with(const char *s) const
equivalent of as_string().starts_with(s)
Definition dstring.h:107
unsigned int get_instance() const
Base class for all expressions.
Definition expr.h:57
std::vector< exprt > operandst
Definition expr.h:59
bool is_boolean() const
Return whether the expression represents a Boolean.
Definition expr.h:229
exprt & op1()
Definition expr.h:137
bool is_constant() const
Return whether the expression is a constant.
Definition expr.h:213
typet & type()
Return the type of the expression.
Definition expr.h:85
operandst & operands()
Definition expr.h:95
The Boolean constant false.
Definition std_expr.h:3135
The trinary if-then-else operator.
Definition std_expr.h:2426
exprt & cond()
Definition std_expr.h:2443
exprt & false_case()
Definition std_expr.h:2463
exprt & true_case()
Definition std_expr.h:2453
exprt & array()
Definition std_expr.h:1461
const irep_idt & id() const
Definition irep.h:390
irep_idt get_component_name() const
Definition std_expr.h:2888
Binary multiplication Associativity is not specified.
Definition std_expr.h:1104
Expression for finding the size (in bytes) of the object a pointer points to.
The plus expression Associativity is not specified.
Definition std_expr.h:1006
A numerical identifier for the object a pointer points to.
The offset (in bytes) of a pointer relative to the object.
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
const typet & base_type() const
The type of the data what we point to.
pointer_in_range (see pointer_in_range_exprt) with prophecy expressions to encode whether a pointer r...
exprt lower(const namespacet &ns) const
A base class for a predicate that indicates that an address range is ok to read or write or both.
exprt lower(const namespacet &ns) const
Lower an r_or_w_ok_exprt to arithmetic and logic expressions.
const namespacet & ns
resultt simplify_inequality_address_of(const binary_relation_exprt &)
resultt simplify_prophecy_r_or_w_ok(const prophecy_r_or_w_ok_exprt &)
Try to simplify prophecy_{r,w,rw}_ok to a constant expression.
static resultt changed(resultt<> result)
resultt simplify_unary_pointer_predicate_preorder(const unary_exprt &)
resultt simplify_address_of(const address_of_exprt &)
resultt simplify_node(const exprt &)
resultt simplify_prophecy_pointer_in_range(const prophecy_pointer_in_range_exprt &)
Try to simplify prophecy_pointer_in_range to a constant expression.
resultt simplify_rec(const exprt &)
resultt simplify_typecast(const typecast_exprt &)
resultt simplify_pointer_object(const pointer_object_exprt &)
resultt simplify_object(const exprt &)
resultt simplify_mult(const mult_exprt &)
resultt simplify_address_of_arg(const exprt &)
virtual resultt simplify_inequality(const binary_relation_exprt &)
simplifies inequalities !=, <=, <, >=, >, and also ==
virtual resultt simplify_inequality_pointer_object(const binary_relation_exprt &)
static resultt unchanged(exprt expr)
resultt simplify_is_invalid_pointer(const unary_exprt &)
virtual resultt simplify_pointer_offset(const pointer_offset_exprt &)
resultt simplify_plus(const plus_exprt &)
resultt simplify_if_preorder(const if_exprt &expr)
resultt simplify_is_dynamic_object(const unary_exprt &)
resultt simplify_object_size(const object_size_exprt &)
Structure type, corresponds to C style structs.
Definition std_types.h:230
void identifier(const irep_idt &identifier)
Definition std_expr.h:160
Semantic type conversion.
Definition std_expr.h:1995
static exprt conditional_cast(const exprt &expr, const typet &type)
Definition std_expr.h:2003
The type of an expression, extends irept.
Definition type.h:29
Generic base class for unary expressions.
Definition std_expr.h:364
const exprt & op() const
Definition std_expr.h:394
constant_exprt make_boolean_expr(bool value)
returns true_exprt if given true and false_exprt otherwise
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
if_exprt lift_if(const exprt &src, std::size_t operand_number)
lift up an if_exprt one level
Deprecated expression utility functions.
named_mp_integert< bytes_tagt > bytest
Definition mp_arith.h:184
API to expression classes for Pointers.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
const pointer_object_exprt & to_pointer_object_expr(const exprt &expr)
Cast an exprt to a pointer_object_exprt.
const dynamic_object_exprt & to_dynamic_object_expr(const exprt &expr)
Cast an exprt to a dynamic_object_exprt.
std::optional< bytest > compute_pointer_offset(const exprt &expr, const namespacet &ns)
std::optional< exprt > size_of_expr(const typet &type, const namespacet &ns)
std::optional< bytest > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
std::optional< bytest > pointer_offset_size(const typet &type, const namespacet &ns)
Compute the size of a type in bytes, rounding up to full bytes.
Pointer Logic.
Various predicates over pointers in programs.
#define SYMEX_DYNAMIC_PREFIX
static bool is_dereference_integer_object(const exprt &expr, mp_integer &address)
BigInt mp_integer
Definition smt_terms.h:17
#define PRECONDITION(CONDITION)
Definition invariant.h:463
API to expression classes.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
Definition std_expr.h:1494
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
Definition std_expr.h:2024
const plus_exprt & to_plus_expr(const exprt &expr)
Cast an exprt to a plus_exprt.
Definition std_expr.h:1045
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
Definition std_expr.h:2501
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
Definition std_expr.h:2953
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
Definition std_expr.h:3078
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition std_expr.h:221
bool is_constant(const typet &type)
This method tests, if the given typet is a constant.
Definition std_types.h:28
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
Definition std_types.h:307
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition std_types.h:517
const string_constantt & to_string_constant(const exprt &expr)
dstringt irep_idt