37 build(type, little_endian);
50 if(!width_opt.has_value())
53 const std::size_t new_size =
map.size() + *width_opt;
54 map.reserve(new_size);
56 for(std::size_t i =
map.size(); i < new_size; ++i)
62 if(src.
id() == ID_pointer)
82 const std::size_t pointer_width = type.
get_width();
85 return pointer_width - object_width;
101 bv.begin() + offset_width, bv.begin() + offset_width + object_width);
110 return bvt(bv.begin(), bv.begin() + offset_width);
116 result.reserve(offset.size() +
object.size());
117 result.insert(result.end(), offset.begin(), offset.end());
118 result.insert(result.end(),
object.begin(),
object.end());
129 if(expr.
id() == ID_is_invalid_pointer)
131 if(operands.size()==1 &&
132 operands[0].type().id()==ID_pointer)
146 bvt equal_invalid_bv;
147 equal_invalid_bv.reserve(object_bits);
149 for(std::size_t i=0; i<object_bits; i++)
151 equal_invalid_bv.push_back(
prop.
lequal(object_bv[i], invalid_bv[i]));
158 else if(expr.
id() == ID_is_dynamic_object)
160 if(operands.size()==1 &&
161 operands[0].type().id()==ID_pointer)
171 else if(expr.
id()==ID_lt || expr.
id()==ID_le ||
172 expr.
id()==ID_gt || expr.
id()==ID_ge)
174 if(operands.size()==2 &&
175 operands[0].type().id()==ID_pointer &&
176 operands[1].type().id()==ID_pointer)
196 return same_object_lit;
209 auto prophecy_r_or_w_ok =
215 auto prophecy_pointer_in_range =
228 bool get_array_constraints)
229 :
boolbvt(_ns, _prop, message_handler, get_array_constraints),
236 if(expr.
id()==ID_symbol)
240 else if(expr.
id()==ID_label)
244 else if(expr.
id() == ID_null_object)
249 else if(expr.
id()==ID_index)
262 if(array_type.id()==ID_pointer)
268 else if(array_type.id()==ID_array ||
269 array_type.id()==ID_string_constant)
272 if(!bv_opt.has_value())
274 bv = std::move(*bv_opt);
287 return std::move(bv);
289 else if(expr.
id()==ID_byte_extract_little_endian ||
290 expr.
id()==ID_byte_extract_big_endian)
296 if(!bv_opt.has_value())
305 return std::move(bv);
307 else if(expr.
id()==ID_member)
315 if(!bv_opt.has_value())
318 bvt bv = std::move(*bv_opt);
319 if(struct_op_type.
id()==ID_struct)
332 struct_op_type.
id() == ID_union,
333 "member expression should operate on struct or union");
337 return std::move(bv);
341 expr.
id() == ID_array)
345 else if(expr.
id()==ID_if)
354 if(!bv1_opt.has_value())
358 if(!bv2_opt.has_value())
373 if(expr.
id()==ID_symbol)
379 else if(expr.
id()==ID_nondet_symbol)
383 else if(expr.
id()==ID_typecast)
387 const exprt &op = typecast_expr.
op();
390 if(op_type.
id()==ID_pointer)
394 op_type.
id() == ID_c_enum || op_type.
id() == ID_c_enum_tag)
404 else if(expr.
id()==ID_if)
408 else if(expr.
id()==ID_index)
412 else if(expr.
id()==ID_member)
416 else if(expr.
id()==ID_address_of)
421 if(!bv_opt.has_value())
427 else if(expr.
id() == ID_object_address)
430 return add_addr(object_address_expr.object_expr());
444 else if(expr.
id()==ID_plus)
455 for(
const auto &op : plus_expr.
operands())
457 if(op.type().id() == ID_pointer)
465 pointer_base_type.
id() != ID_empty,
466 "no pointer arithmetic over void pointers");
475 "there should be exactly one pointer-type operand in a pointer-type sum");
480 for(
const auto &operand : plus_expr.
operands())
482 if(operand.type().id() == ID_pointer)
486 operand.type().id() != ID_unsignedbv &&
487 operand.type().id() != ID_signedbv)
506 else if(expr.
id()==ID_minus)
513 minus_expr.
lhs().
type().
id() == ID_pointer,
514 "first operand should be of pointer type");
517 minus_expr.
rhs().
type().
id() != ID_unsignedbv &&
518 minus_expr.
rhs().
type().
id() != ID_signedbv)
527 typet pointer_base_type =
530 pointer_base_type.
id() != ID_empty,
531 "no pointer arithmetic over void pointers");
533 CHECK_RETURN(element_size_opt.has_value() && *element_size_opt > 0);
536 else if(expr.
id()==ID_byte_extract_little_endian ||
537 expr.
id()==ID_byte_extract_big_endian)
542 expr.
id() == ID_byte_update_little_endian ||
543 expr.
id() == ID_byte_update_big_endian)
547 else if(expr.
id() == ID_field_address)
550 const typet &compound_type =
ns.
follow(field_address_expr.compound_type());
555 if(compound_type.
id() == ID_struct)
564 else if(compound_type.
id() == ID_union)
570 INVARIANT(
false,
"field address expressions operate on struct or union");
575 else if(expr.
id() == ID_element_address)
588 element_address_expr.type(), bv, *size, element_address_expr.index());
598 if(expr.
id() != ID_minus)
603 return minus_expr.lhs().type().id() == ID_pointer &&
604 minus_expr.rhs().type().id() == ID_pointer;
609 if(expr.
type().
id()==ID_pointer)
631 const bvt lhs_offset =
636 const bvt rhs_offset =
643 "no pointer arithmetic over void pointers");
645 CHECK_RETURN(element_size_opt.has_value() && *element_size_opt > 0);
647 if(*element_size_opt != 1)
662 const bvt object_size_bv =
692 expr.
id() == ID_pointer_offset &&
719 expr.
id() == ID_pointer_object &&
733 expr.
id() == ID_typecast &&
752 for(
const auto &literal : bv)
765 result = ch + result;
774 std::size_t offset)
const
778 if(type.
id() != ID_pointer)
783 bvt value_bv(bv.begin() + offset, bv.begin() + offset + bits);
787 std::string value_offset =
794 return value[value.size() - 1 - i] ==
'1';
902 const std::size_t max_objects=std::size_t(1)<<object_bits;
906 "too many addressed objects: maximum number of objects is set to 2^n=" +
907 std::to_string(max_objects) +
" (with n=" + std::to_string(object_bits) +
909 "use the `--object-bits n` option to increase the maximum number");
917 if(postponed.
expr.
id() == ID_is_dynamic_object)
922 std::size_t number=0;
924 for(
auto it = objects.cbegin(); it != objects.cend(); ++it, ++number)
926 const exprt &expr=*it;
949 const auto postponed_object_size =
952 const auto &type =
to_pointer_type(postponed_object_size->pointer().type());
954 std::size_t number=0;
956 for(
auto it = objects.cbegin(); it != objects.cend(); ++it, ++number)
958 const exprt &expr=*it;
960 if(expr.
id() != ID_symbol && expr.
id() != ID_string_constant)
965 if(!size_expr.has_value())
969 size_expr.value(), postponed_object_size->type());
986 for(std::size_t i = 0; i < postponed.
bv.size(); ++i)
992#define COMPACT_OBJECT_SIZE_EQ
993#ifndef COMPACT_OBJECT_SIZE_EQ
998 for(std::size_t i = 0; i < postponed.
bv.size(); ++i)
1000 prop.
lcnf({!l1, !postponed.
bv[i], size_bv[i]});
1001 prop.
lcnf({!l1, postponed.
bv[i], !size_bv[i]});
1015 for(postponed_listt::const_iterator
static bool convert(const irep_idt &identifier, const std::ostringstream &s, symbol_table_baset &symbol_table, message_handlert &message_handler)
static std::string bits_to_string(const propt &prop, const bvt &bv)
static bool is_pointer_subtraction(const exprt &expr)
static std::string bits_to_string(const propt &prop, const bvt &bv)
static bool is_pointer_subtraction(const exprt &expr)
Expression classes for byte-level operators.
const byte_update_exprt & to_byte_update_expr(const exprt &expr)
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
pointer_typet pointer_type(const typet &subtype)
Operator to return the address of an object.
Thrown when an unexpected error occurs during the analysis (e.g., when the SAT solver returns an erro...
Pointer-typed bitvector constant annotated with the pointer expression that the bitvector is the nume...
std::size_t get_width() const
const bvt & get_literals(const irep_idt &identifier, const typet &type, std::size_t width)
virtual optionalt< std::size_t > get_width_opt(const typet &type) const
virtual bvt convert_index(const exprt &array, const mp_integer &index)
index operator with constant index
virtual bvt convert_byte_extract(const byte_extract_exprt &expr)
virtual bvt convert_bitvector(const exprt &expr)
Converts an expression into its gate-level representation and returns a vector of literals correspond...
virtual exprt bv_get_rec(const exprt &expr, const bvt &bv, std::size_t offset) const
virtual bvt convert_member(const member_exprt &expr)
virtual bvt convert_if(const if_exprt &expr)
virtual bvt convert_byte_update(const byte_update_exprt &expr)
void finish_eager_conversion() override
virtual const bvt & convert_bv(const exprt &expr, const optionalt< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
virtual std::size_t boolbv_width(const typet &type) const
literalt convert_rest(const exprt &expr) override
Map bytes according to the configured endianness.
void build_little_endian(const typet &type) override
void build_big_endian(const typet &type) override
const boolbv_widtht & boolbv_width
bv_endianness_mapt(const typet &type, bool little_endian, const namespacet &_ns, const boolbv_widtht &_boolbv_width)
std::size_t get_object_width(const pointer_typet &) const
void do_postponed(const postponedt &postponed)
NODISCARD optionalt< bvt > convert_address_of_rec(const exprt &)
pointer_logict pointer_logic
NODISCARD bvt offset_arithmetic(const pointer_typet &, const bvt &, const mp_integer &)
postponed_listt postponed_list
std::size_t get_address_width(const pointer_typet &) const
virtual NODISCARD bvt add_addr(const exprt &)
endianness_mapt endianness_map(const typet &, bool little_endian) const override
void finish_eager_conversion() override
exprt bv_get_rec(const exprt &, const bvt &, std::size_t offset) const override
static bvt object_offset_encoding(const bvt &object, const bvt &offset)
Construct a pointer encoding from given encodings of object and offset.
NODISCARD bvt encode(const mp_integer &object, const pointer_typet &) const
std::size_t get_offset_width(const pointer_typet &) const
literalt convert_rest(const exprt &) override
bv_pointerst(const namespacet &, propt &, message_handlert &, bool get_array_constraints=false)
bvt convert_bitvector(const exprt &) override
Converts an expression into its gate-level representation and returns a vector of literals correspond...
bvt object_literals(const bvt &bv, const pointer_typet &type) const
Given a pointer encoded in bv, extract the literals identifying the object that the pointer points to...
bvt offset_literals(const bvt &bv, const pointer_typet &type) const
Given a pointer encoded in bv, extract the literals representing the offset into an object that the p...
virtual bvt convert_pointer_type(const exprt &)
static literalt sign_bit(const bvt &op)
bvt add(const bvt &op0, const bvt &op1)
static bvt zero_extension(const bvt &bv, std::size_t new_size)
bvt select(literalt s, const bvt &a, const bvt &b)
If s is true, selects a otherwise selects b.
static bvt build_constant(const mp_integer &i, std::size_t width)
literalt equal(const bvt &op0, const bvt &op1)
Bit-blasting ID_equal and use in other encodings.
bvt signed_multiplier(const bvt &op0, const bvt &op1)
bvt sub(const bvt &op0, const bvt &op1)
bvt divider(const bvt &op0, const bvt &op1, representationt rep)
bvt multiplier(const bvt &op0, const bvt &op1, representationt rep)
static bvt extension(const bvt &bv, std::size_t new_size, representationt rep)
literalt rel(const bvt &bv0, irep_idt id, const bvt &bv1, representationt rep)
struct configt::bv_encodingt bv_encoding
A constant literal expression.
const irep_idt & get_value() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Maps a big-endian offset to a little-endian offset.
virtual void build_big_endian(const typet &type)
void build(const typet &type, bool little_endian)
std::vector< size_t > map
Base class for all expressions.
std::vector< exprt > operandst
bool is_boolean() const
Return whether the expression represents a Boolean.
bool is_constant() const
Return whether the expression is a constant.
typet & type()
Return the type of the expression.
The trinary if-then-else operator.
const irep_idt & id() const
Extract member of struct or union.
const exprt & compound() const
irep_idt get_component_name() const
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
The plus expression Associativity is not specified.
const mp_integer & get_invalid_object() const
const mp_integer & get_null_object() const
numberingt< exprt, irep_hash > objects
exprt pointer_expr(const pointert &pointer, const pointer_typet &type) const
Convert an (object,offset) pair to an expression.
mp_integer add_object(const exprt &expr)
bool is_dynamic_object(const exprt &expr) const
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.
void l_set_to_true(literalt a)
virtual literalt land(literalt a, literalt b)=0
virtual literalt limplies(literalt a, literalt b)=0
void lcnf(literalt l0, literalt l1)
virtual void set_equal(literalt a, literalt b)
asserts a==b in the propositional formula
virtual bvt new_variables(std::size_t width)
generates a bitvector of given width with new variables
virtual literalt new_variable()=0
virtual literalt lequal(literalt a, literalt b)=0
virtual literalt lor(literalt a, literalt b)=0
virtual tvt l_get(literalt a) const =0
const irep_idt & get_identifier() const
tv_enumt get_value() const
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
The unary minus expression.
auto expr_try_dynamic_cast(TExpr &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TExpr >::type
Try to cast a reference to a generic exprt to a specific derived class.
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...
Deprecated expression utility functions.
std::vector< literalt > bvt
literalt const_literal(bool value)
const mp_integer binary2integer(const std::string &n, bool is_signed)
convert binary string representation to mp_integer
static bool is_dynamic(const exprt &object)
This function returns true for heap allocated objects or false for stack allocated objects.
nonstd::optional< T > optionalt
API to expression classes for Pointers.
const element_address_exprt & to_element_address_expr(const exprt &expr)
Cast an exprt to an element_address_exprt.
const object_address_exprt & to_object_address_expr(const exprt &expr)
Cast an exprt to an object_address_exprt.
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 pointer_offset_exprt & to_pointer_offset_expr(const exprt &expr)
Cast an exprt to a pointer_offset_exprt.
const pointer_object_exprt & to_pointer_object_expr(const exprt &expr)
Cast an exprt to a pointer_object_exprt.
const field_address_exprt & to_field_address_expr(const exprt &expr)
Cast an exprt to an field_address_exprt.
optionalt< mp_integer > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
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.
optionalt< exprt > size_of_expr(const typet &type, const namespacet &ns)
exprt object_size(const exprt &pointer)
exprt same_object(const exprt &p1, const exprt &p2)
exprt null_object(const exprt &pointer)
Various predicates over pointers in programs.
exprt simplify_expr(exprt src, const namespacet &ns)
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
#define POSTCONDITION(CONDITION)
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const plus_exprt & to_plus_expr(const exprt &expr)
Cast an exprt to a plus_exprt.
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const minus_exprt & to_minus_expr(const exprt &expr)
Cast an exprt to a minus_exprt.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
bool can_cast_type< bitvector_typet >(const typet &type)
Check whether a reference to a typet is a bitvector_typet.