Go to the documentation of this file.
36 build(type, little_endian);
49 if(!width_opt.has_value())
52 const std::size_t new_size =
map.size() + *width_opt;
53 map.reserve(new_size);
55 for(std::size_t i =
map.size(); i < new_size; ++i)
61 if(src.
id() == ID_pointer)
81 const std::size_t pointer_width = type.
get_width();
84 return pointer_width - object_width;
100 bv.begin() + offset_width, bv.begin() + offset_width + object_width);
109 return bvt(bv.begin(), bv.begin() + offset_width);
115 result.reserve(offset.size() +
object.size());
116 result.insert(result.end(), offset.begin(), offset.end());
117 result.insert(result.end(),
object.begin(),
object.end());
128 if(expr.
id() == ID_is_invalid_pointer)
130 if(operands.size()==1 &&
131 operands[0].type().id()==ID_pointer)
145 bvt equal_invalid_bv;
146 equal_invalid_bv.reserve(object_bits);
148 for(std::size_t i=0; i<object_bits; i++)
150 equal_invalid_bv.push_back(
prop.
lequal(object_bv[i], invalid_bv[i]));
157 else if(expr.
id() == ID_is_dynamic_object)
159 if(operands.size()==1 &&
160 operands[0].type().id()==ID_pointer)
170 else if(expr.
id()==ID_lt || expr.
id()==ID_le ||
171 expr.
id()==ID_gt || expr.
id()==ID_ge)
173 if(operands.size()==2 &&
174 operands[0].type().id()==ID_pointer &&
175 operands[1].type().id()==ID_pointer)
195 return same_object_lit;
214 bool get_array_constraints)
215 :
boolbvt(_ns, _prop, message_handler, get_array_constraints),
222 if(expr.
id()==ID_symbol)
226 else if(expr.
id()==ID_label)
230 else if(expr.
id() == ID_null_object)
235 else if(expr.
id()==ID_index)
248 if(array_type.id()==ID_pointer)
254 else if(array_type.id()==ID_array ||
255 array_type.id()==ID_string_constant)
258 if(!bv_opt.has_value())
260 bv = std::move(*bv_opt);
273 return std::move(bv);
275 else if(expr.
id()==ID_byte_extract_little_endian ||
276 expr.
id()==ID_byte_extract_big_endian)
282 if(!bv_opt.has_value())
291 return std::move(bv);
293 else if(expr.
id()==ID_member)
301 if(!bv_opt.has_value())
304 bvt bv = std::move(*bv_opt);
305 if(struct_op_type.
id()==ID_struct)
318 struct_op_type.
id() == ID_union,
319 "member expression should operate on struct or union");
323 return std::move(bv);
325 else if(expr.
id()==ID_constant ||
326 expr.
id()==ID_string_constant ||
331 else if(expr.
id()==ID_if)
340 if(!bv1_opt.has_value())
344 if(!bv2_opt.has_value())
359 if(expr.
id()==ID_symbol)
365 else if(expr.
id()==ID_nondet_symbol)
369 else if(expr.
id()==ID_typecast)
373 const exprt &op = typecast_expr.
op();
376 if(op_type.
id()==ID_pointer)
380 op_type.
id() == ID_c_enum || op_type.
id() == ID_c_enum_tag)
390 else if(expr.
id()==ID_if)
394 else if(expr.
id()==ID_index)
398 else if(expr.
id()==ID_member)
402 else if(expr.
id()==ID_address_of)
407 if(!bv_opt.has_value())
413 else if(expr.
id()==ID_constant)
425 else if(expr.
id()==ID_plus)
438 if(it->type().id()==ID_pointer)
446 if(pointer_base_type.
id() == ID_empty)
463 "there should be exactly one pointer-type operand in a pointer-type sum");
470 if(it->type().id()==ID_pointer)
473 if(it->type().id()!=ID_unsignedbv &&
474 it->type().id()!=ID_signedbv)
493 else if(expr.
id()==ID_minus)
500 minus_expr.
lhs().
type().
id() == ID_pointer,
501 "first operand should be of pointer type");
504 minus_expr.
rhs().
type().
id() != ID_unsignedbv &&
505 minus_expr.
rhs().
type().
id() != ID_signedbv)
514 typet pointer_base_type =
518 if(pointer_base_type.
id() == ID_empty)
527 CHECK_RETURN(element_size_opt.has_value() && *element_size_opt > 0);
528 element_size = *element_size_opt;
533 else if(expr.
id()==ID_byte_extract_little_endian ||
534 expr.
id()==ID_byte_extract_big_endian)
539 expr.
id() == ID_byte_update_little_endian ||
540 expr.
id() == ID_byte_update_big_endian)
544 else if(expr.
id() == ID_field_address)
547 const typet &compound_type =
ns.
follow(field_address_expr.compound_type());
552 if(compound_type.
id() == ID_struct)
561 else if(compound_type.
id() == ID_union)
567 INVARIANT(
false,
"field address expressions operate on struct or union");
572 else if(expr.
id() == ID_element_address)
585 element_address_expr.type(), bv, *size, element_address_expr.index());
595 if(expr.
id() != ID_minus)
600 return minus_expr.lhs().type().id() == ID_pointer &&
601 minus_expr.rhs().type().id() == ID_pointer;
606 if(expr.
type().
id()==ID_pointer)
624 const bvt object_size_bv =
633 const bvt lhs_offset =
646 const bvt rhs_offset =
665 CHECK_RETURN(element_size_opt.has_value() && *element_size_opt > 0);
667 if(*element_size_opt != 1)
669 bvt element_size_bv =
684 expr.
id() == ID_pointer_offset &&
699 const auto object_size = expr_try_dynamic_cast<object_size_exprt>(expr))
712 expr.
id() == ID_pointer_object &&
726 expr.
id() == ID_typecast &&
737 else if(expr.
id() == ID_object_address)
740 return add_addr(object_address_expr.object_expr());
750 for(
const auto &literal : bv)
763 result = ch + result;
772 std::size_t offset)
const
776 if(type.
id() != ID_pointer)
781 bvt value_bv(bv.begin() + offset, bv.begin() + offset + bits);
785 std::string value_offset =
792 return value[value.size() - 1 - i] ==
'1';
879 const std::size_t max_objects=std::size_t(1)<<object_bits;
883 "too many addressed objects: maximum number of objects is set to 2^n=" +
886 "use the `--object-bits n` option to increase the maximum number");
894 if(postponed.
expr.
id() == ID_is_dynamic_object)
899 std::size_t number=0;
901 for(
auto it = objects.cbegin(); it != objects.cend(); ++it, ++number)
903 const exprt &expr=*it;
926 const auto postponed_object_size =
927 expr_try_dynamic_cast<object_size_exprt>(postponed.
expr))
929 const auto &type =
to_pointer_type(postponed_object_size->pointer().type());
931 std::size_t number=0;
933 for(
auto it = objects.cbegin(); it != objects.cend(); ++it, ++number)
935 const exprt &expr=*it;
937 if(expr.
id() != ID_symbol && expr.
id() != ID_string_constant)
942 if(!size_expr.has_value())
946 size_expr.value(), postponed_object_size->type());
963 for(std::size_t i = 0; i < postponed.
bv.size(); ++i)
969 #define COMPACT_OBJECT_SIZE_EQ
970 #ifndef COMPACT_OBJECT_SIZE_EQ
975 for(std::size_t i = 0; i < postponed.
bv.size(); ++i)
977 prop.
lcnf({!l1, !postponed.
bv[i], size_bv[i]});
978 prop.
lcnf({!l1, postponed.
bv[i], !size_bv[i]});
992 for(postponed_listt::const_iterator
const element_address_exprt & to_element_address_expr(const exprt &expr)
Cast an exprt to an element_address_exprt.
bvt encode(const mp_integer &object, const pointer_typet &) const
void build_big_endian(const typet &type) override
#define UNREACHABLE
This should be used to mark dead code.
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.
void finish_eager_conversion() override
virtual bvt convert_member(const member_exprt &expr)
bv_endianness_mapt(const typet &type, bool little_endian, const namespacet &_ns, const boolbv_widtht &_boolbv_width)
void build(const typet &type, bool little_endian)
const boolbv_widtht & boolbv_width
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...
virtual bvt convert_byte_update(const byte_update_exprt &expr)
struct configt::bv_encodingt bv_encoding
static bvt zero_extension(const bvt &bv, std::size_t new_size)
void finish_eager_conversion() override
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
virtual bvt new_variables(std::size_t width)
generates a bitvector of given width with new variables
virtual bvt convert_bitvector(const exprt &expr)
Converts an expression into its gate-level representation and returns a vector of literals correspond...
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.
virtual exprt bv_get_rec(const exprt &expr, const bvt &bv, std::size_t offset) const
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
std::vector< literalt > bvt
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
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.
bvt signed_multiplier(const bvt &op0, const bvt &op1)
Map bytes according to the configured endianness.
postponed_listt postponed_list
The trinary if-then-else operator.
const bvt & get_literals(const irep_idt &identifier, const typet &type, std::size_t width)
virtual void set_equal(literalt a, literalt b)
asserts a==b in the propositional formula
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...
The plus expression Associativity is not specified.
void do_postponed(const postponedt &postponed)
virtual literalt new_variable()=0
virtual bvt convert_index(const exprt &array, const mp_integer &index)
index operator with constant index
Base class for all expressions.
static bvt sign_extension(const bvt &bv, std::size_t new_size)
optionalt< bvt > convert_address_of_rec(const exprt &)
void l_set_to_true(literalt a)
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
const mp_integer & get_invalid_object() const
endianness_mapt endianness_map(const typet &, bool little_endian) const override
virtual void build_big_endian(const typet &type)
virtual literalt land(literalt a, literalt b)=0
bvt select(literalt s, const bvt &a, const bvt &b)
If s is true, selects a otherwise selects b.
const minus_exprt & to_minus_expr(const exprt &expr)
Cast an exprt to a minus_exprt.
virtual optionalt< std::size_t > get_width_opt(const typet &type) const
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
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.
virtual bvt convert_byte_extract(const byte_extract_exprt &expr)
bvt add(const bvt &op0, const bvt &op1)
Expression classes for byte-level operators.
virtual bvt add_addr(const exprt &)
std::vector< size_t > map
virtual literalt limplies(literalt a, literalt b)=0
const object_address_exprt & to_object_address_expr(const exprt &expr)
Cast an exprt to an object_address_exprt.
virtual std::size_t boolbv_width(const typet &type) const
const exprt & compound() const
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...
#define forall_operands(it, expr)
const byte_update_exprt & to_byte_update_expr(const exprt &expr)
#define PRECONDITION(CONDITION)
const irep_idt & get_identifier() const
virtual bvt convert_if(const if_exprt &expr)
const plus_exprt & to_plus_expr(const exprt &expr)
Cast an exprt to a plus_exprt.
literalt const_literal(bool value)
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
pointer_logict pointer_logic
pointer_typet pointer_type(const typet &subtype)
The unary minus expression.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
exprt object_size(const exprt &pointer)
const irep_idt & id() const
std::vector< exprt > operandst
Pointer-typed bitvector constant annotated with the pointer expression that the bitvector is the nume...
bvt offset_arithmetic(const pointer_typet &, const bvt &, const mp_integer &)
nonstd::optional< T > optionalt
literalt convert(const exprt &expr) override
Convert a Boolean expression and return the corresponding literal.
numberingt< exprt, irep_hash > objects
std::size_t get_address_width(const pointer_typet &) const
std::size_t get_width() const
Extract member of struct or union.
Deprecated expression utility functions.
std::size_t get_object_width(const pointer_typet &) const
static bvt build_constant(const mp_integer &i, std::size_t width)
virtual literalt lequal(literalt a, literalt b)=0
literalt rel(const bvt &bv0, irep_idt id, const bvt &bv1, representationt rep)
#define POSTCONDITION(CONDITION)
void build_little_endian(const typet &type) override
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.
bool is_dynamic_object(const exprt &expr) const
virtual tvt l_get(literalt a) const =0
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
static literalt sign_bit(const bvt &op)
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
static bvt extension(const bvt &bv, std::size_t new_size, representationt rep)
const mp_integer binary2integer(const std::string &n, bool is_signed)
convert binary string representation to mp_integer
static std::string bits_to_string(const propt &prop, const bvt &bv)
const field_address_exprt & to_field_address_expr(const exprt &expr)
Cast an exprt to an field_address_exprt.
const typet & base_type() const
The type of the data what we point to.
literalt convert_rest(const exprt &) override
std::size_t get_offset_width(const pointer_typet &) const
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
exprt same_object(const exprt &p1, const exprt &p2)
bvt divider(const bvt &op0, const bvt &op1, representationt rep)
Maps a big-endian offset to a little-endian offset.
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.
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
irep_idt get_component_name() const
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
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 &)
mp_integer add_object(const exprt &expr)
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.
literalt equal(const bvt &op0, const bvt &op1)
Bit-blasting ID_equal and use in other encodings.
Semantic type conversion.
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
tv_enumt get_value() const
literalt convert_rest(const exprt &expr) override
A constant literal expression.
static bool is_pointer_subtraction(const exprt &expr)
const irep_idt & get_value() const
optionalt< mp_integer > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
void lcnf(literalt l0, literalt l1)
bool can_cast_type< bitvector_typet >(const typet &type)
Check whether a reference to a typet is a bitvector_typet.
const mp_integer & get_null_object() const
bvt sub(const bvt &op0, const bvt &op1)
exprt pointer_expr(const pointert &pointer, const pointer_typet &type) const
Convert an (object,offset) pair to an expression.
Thrown when an unexpected error occurs during the analysis (e.g., when the SAT solver returns an erro...
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.