Go to the documentation of this file.
27 if(expr.
id() == ID_dereference)
32 pointer.id() == ID_typecast &&
39 if(pointer.is_constant())
59 if(expr.
id()==ID_index)
63 bool no_change =
true;
67 if(array_result.has_changed())
70 new_index_expr.array() = array_result.expr;
73 auto index_result =
simplify_rec(new_index_expr.index());
75 if(index_result.has_changed())
78 new_index_expr.index() = index_result.expr;
90 if(step_size.has_value())
92 const auto index = numeric_cast<mp_integer>(new_index_expr.index());
110 return new_index_expr;
112 else if(expr.
id()==ID_member)
116 bool no_change =
true;
118 auto struct_op_result =
121 if(struct_op_result.has_changed())
123 new_member_expr.struct_op() = struct_op_result.expr;
127 const typet &op_type =
ns.
follow(new_member_expr.struct_op().type());
129 if(op_type.
id() == ID_struct)
139 if(offset.has_value())
152 return new_member_expr;
154 else if(expr.
id()==ID_dereference)
158 if(r_pointer.has_changed())
160 new_expr.pointer() = r_pointer.expr;
161 return std::move(new_expr);
164 else if(expr.
id()==ID_if)
168 bool no_change =
true;
171 if(r_cond.has_changed())
173 new_if_expr.cond() = r_cond.expr;
178 if(true_result.has_changed())
180 new_if_expr.true_case() = true_result.expr;
186 if(false_result.has_changed())
188 new_if_expr.false_case() = false_result.expr;
193 if(new_if_expr.cond().is_true())
195 return new_if_expr.true_case();
197 else if(new_if_expr.cond().is_false())
199 return new_if_expr.false_case();
212 if(expr.
type().
id() != ID_pointer)
217 if(new_object.expr.id() == ID_index)
221 if(!index_expr.index().is_zero())
226 auto new_address_of_expr = expr;
227 new_address_of_expr.
object() = std::move(index_expr);
228 return plus_exprt(std::move(new_address_of_expr), offset);
231 else if(new_object.expr.id() == ID_dereference)
237 if(new_object.has_changed())
239 auto new_expr = expr;
240 new_expr.
object() = new_object;
252 if(ptr.
id()==ID_if && ptr.
operands().size()==3)
262 if(ptr.
type().
id()!=ID_pointer)
265 if(ptr.
id()==ID_address_of)
269 if(offset.has_value())
272 else if(ptr.
id()==ID_typecast)
275 const typet &op_type = op.type();
277 if(op_type.
id()==ID_pointer)
281 auto new_expr = expr;
286 else if(op_type.
id()==ID_signedbv ||
287 op_type.
id()==ID_unsignedbv)
303 if(tmp.
id()==ID_plus && tmp.
operands().size()==2)
308 plus_expr.op0().id() == ID_typecast &&
317 plus_expr.op1().id() == ID_typecast &&
329 else if(ptr.
id()==ID_plus)
334 for(
const auto &op : ptr.
operands())
336 if(op.type().id()==ID_pointer)
337 ptr_expr.push_back(op);
338 else if(!op.is_zero())
344 int_expr.push_back(tmp);
348 if(ptr_expr.size()!=1 || int_expr.empty())
351 typet pointer_base_type =
353 if(pointer_base_type.
id() == ID_empty)
358 if(!element_size.has_value())
367 if(int_expr.size()==1)
368 sum=int_expr.front();
376 auto new_expr =
plus_exprt(pointer_offset_expr, product);
380 else if(ptr.
id()==ID_constant)
401 number%=
power(2, offset_bits);
426 tmp0_address_of.object().id() == ID_index &&
440 tmp1_address_of.object().id() == ID_index &&
446 const auto &tmp0_object = tmp0_address_of.object();
447 const auto &tmp1_object = tmp1_address_of.object();
449 if(tmp0_object.id() == ID_symbol && tmp1_object.id() == ID_symbol)
457 tmp0_object.id() == ID_dynamic_object &&
458 tmp1_object.id() == ID_dynamic_object)
466 (tmp0_object.id() == ID_symbol && tmp1_object.id() == ID_dynamic_object) ||
467 (tmp0_object.id() == ID_dynamic_object && tmp1_object.id() == ID_symbol))
472 tmp0_object.id() == ID_string_constant &&
473 tmp1_object.id() == ID_string_constant && tmp0_object == tmp1_object)
493 if(op.
id()==ID_address_of)
497 if((op_object.id() != ID_symbol && op_object.id() != ID_dynamic_object &&
498 op_object.id() != ID_string_constant))
503 else if(op.
id() != ID_constant || !op.
is_zero())
508 if(new_inequality_ops.empty())
509 new_inequality_ops.push_back(op);
512 new_inequality_ops.push_back(
514 op, new_inequality_ops.front().
type())));
518 auto new_expr = expr;
520 new_expr.
operands() = std::move(new_inequality_ops);
532 if(op_result.expr.id() == ID_if)
537 auto p_o_false = expr;
540 auto p_o_true = expr;
543 auto new_expr =
if_exprt(cond, p_o_true, p_o_false, expr.
type());
547 if(op_result.has_changed())
549 auto new_expr = expr;
550 new_expr.
op() = op_result;
551 return std::move(new_expr);
560 auto new_expr = expr;
561 exprt &op = new_expr.op();
573 bool no_change =
true;
577 if(op_result.has_changed())
588 if(op.
id() == ID_address_of)
592 if(op_object.id() == ID_symbol)
600 else if(op_object.id() == ID_string_constant)
604 else if(op_object.id() == ID_array)
613 return std::move(new_expr);
619 auto new_expr = expr;
620 exprt &op = new_expr.op();
621 bool no_change =
true;
625 if(op_result.has_changed())
638 if(op.
id()==ID_address_of)
646 return std::move(new_expr);
652 auto new_expr = expr;
653 bool no_change =
true;
654 exprt &op = new_expr.pointer();
657 if(op_result.has_changed())
663 if(op.
id() == ID_address_of)
667 if(op_object.id() == ID_symbol)
672 if(size_opt.has_value())
675 exprt size = size_opt.value();
677 if(size.
type() != expr_type)
683 else if(op_object.id() == ID_string_constant)
694 return std::move(new_expr);
resultt simplify_rec(const exprt &)
resultt simplify_object_size(const object_size_exprt &)
resultt simplify_is_invalid_pointer(const unary_exprt &)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
static exprt conditional_cast(const exprt &expr, const typet &type)
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
resultt simplify_pointer_offset(const pointer_offset_exprt &)
struct configt::bv_encodingt bv_encoding
resultt simplify_address_of(const address_of_exprt &)
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
exprt good_pointer_def(const exprt &pointer, const namespacet &ns)
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
The type of an expression, extends irept.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
Operator to dereference a pointer.
The trinary if-then-else operator.
resultt simplify_inequality_address_of(const binary_relation_exprt &)
resultt simplify_is_dynamic_object(const unary_exprt &)
const string_constantt & to_string_constant(const exprt &expr)
The plus expression Associativity is not specified.
Base class for all expressions.
Generic base class for unary expressions.
if_exprt lift_if(const exprt &src, std::size_t operand_number)
lift up an if_exprt one level
resultt simplify_plus(const plus_exprt &)
Expression for finding the size (in bytes) of the object a pointer points to.
static resultt unchanged(exprt expr)
resultt simplify_node(exprt)
static bool is_dereference_integer_object(const exprt &expr, mp_integer &address)
resultt simplify_if(const if_exprt &)
optionalt< mp_integer > compute_pointer_offset(const exprt &expr, const namespacet &ns)
typet & type()
Return the type of the expression.
const pointer_object_exprt & to_pointer_object_expr(const exprt &expr)
Cast an exprt to a pointer_object_exprt.
unsigned int get_instance() const
resultt simplify_typecast(const typecast_exprt &)
bool has_prefix(const std::string &s, const std::string &prefix)
const std::string & id2string(const irep_idt &d)
#define forall_operands(it, expr)
#define SYMEX_DYNAMIC_PREFIX
#define PRECONDITION(CONDITION)
static resultt changed(resultt<> result)
const irep_idt & get_identifier() const
optionalt< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
const plus_exprt & to_plus_expr(const exprt &expr)
Cast an exprt to a plus_exprt.
Binary multiplication Associativity is not specified.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
resultt simplify_inequality(const binary_relation_exprt &)
simplifies inequalities !=, <=, <, >=, >, and also ==
A numerical identifier for the object a pointer points to.
pointer_typet pointer_type(const typet &subtype)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
resultt simplify_good_pointer(const unary_exprt &)
const irep_idt & id() const
std::vector< exprt > operandst
The Boolean constant false.
resultt simplify_mult(const mult_exprt &)
const dynamic_object_exprt & to_dynamic_object_expr(const exprt &expr)
Cast an exprt to a dynamic_object_exprt.
exprt pointer_offset(const exprt &pointer)
resultt simplify_pointer_object(const pointer_object_exprt &)
bitvector_typet char_type()
std::size_t get_width() const
bool is_zero() const
Return whether the expression is a constant representing 0.
Deprecated expression utility functions.
resultt simplify_object(const exprt &)
optionalt< mp_integer > pointer_offset_size(const typet &type, const namespacet &ns)
Compute the size of a type in bytes, rounding up to full bytes.
resultt simplify_inequality_pointer_object(const binary_relation_exprt &)
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
The offset (in bytes) of a pointer relative to the object.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
A base class for relations, i.e., binary predicates whose two operands have the same type.
const typet & base_type() const
The type of the data what we point to.
const pointer_offset_exprt & to_pointer_offset_expr(const exprt &expr)
Cast an exprt to a pointer_offset_exprt.
optionalt< exprt > size_of_expr(const typet &type, const namespacet &ns)
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
irep_idt get_component_name() const
constant_exprt make_boolean_expr(bool value)
returns true_exprt if given true and false_exprt otherwise
resultt simplify_address_of_arg(const exprt &)
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
bool is_null_pointer(const constant_exprt &expr)
Returns true if expr has a pointer type and a value NULL; it also returns true when expr has value ze...
Operator to return the address of an object.
Semantic type conversion.
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
A constant literal expression.
bitvector_typet c_index_type()
bool is_constant(const typet &type)
This method tests, if the given typet is a constant.
const irep_idt & get_value() const
optionalt< mp_integer > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.