35 build(type, little_endian);
52 const std::size_t new_size =
map.size() + width;
53 map.reserve(new_size);
55 for(std::size_t i =
map.size(); i < new_size; ++i)
61 if(src.
id() == ID_pointer)
76 if(type.
id() != ID_pointer)
80 std::pair<cachet::iterator, bool> cache_result =
81 cache.insert(std::pair<typet, entryt>(type,
entryt()));
83 if(cache_result.second)
85 std::size_t &total_width = cache_result.first->second.total_width;
88 DATA_INVARIANT(total_width > 0,
"pointer width shall be greater than zero");
91 return cache_result.first->second.total_width;
105 const std::size_t pointer_width = type.
get_width();
106 const std::size_t object_width = get_object_width(type);
108 return pointer_width - object_width;
123 if(expr.
id() == ID_is_invalid_pointer)
125 if(operands.size()==1 &&
126 operands[0].type().id()==ID_pointer)
138 const std::size_t object_bits =
141 bvt equal_invalid_bv;
142 equal_invalid_bv.reserve(object_bits);
144 for(std::size_t i=0; i<object_bits; i++)
146 equal_invalid_bv.push_back(
prop.
lequal(object_bv[i], invalid_bv[i]));
153 else if(expr.
id() == ID_is_dynamic_object)
155 if(operands.size()==1 &&
156 operands[0].type().id()==ID_pointer)
166 else if(expr.
id()==ID_lt || expr.
id()==ID_le ||
167 expr.
id()==ID_gt || expr.
id()==ID_ge)
169 if(operands.size()==2 &&
170 operands[0].type().id()==ID_pointer &&
171 operands[1].type().id()==ID_pointer)
191 return same_object_lit;
219 if(expr.
id()==ID_symbol)
223 else if(expr.
id()==ID_label)
227 else if(expr.
id() == ID_null_object)
232 else if(expr.
id()==ID_index)
245 if(array_type.id()==ID_pointer)
251 else if(array_type.id()==ID_array ||
252 array_type.id()==ID_string_constant)
255 if(!bv_opt.has_value())
257 bv = std::move(*bv_opt);
270 return std::move(bv);
272 else if(expr.
id()==ID_byte_extract_little_endian ||
273 expr.
id()==ID_byte_extract_big_endian)
279 if(!bv_opt.has_value())
288 return std::move(bv);
290 else if(expr.
id()==ID_member)
298 if(!bv_opt.has_value())
301 bvt bv = std::move(*bv_opt);
302 if(struct_op_type.
id()==ID_struct)
315 struct_op_type.
id() == ID_union,
316 "member expression should operate on struct or union");
320 return std::move(bv);
322 else if(expr.
id()==ID_constant ||
323 expr.
id()==ID_string_constant ||
328 else if(expr.
id()==ID_if)
337 if(!bv1_opt.has_value())
341 if(!bv2_opt.has_value())
356 if(expr.
id()==ID_symbol)
362 else if(expr.
id()==ID_nondet_symbol)
366 else if(expr.
id()==ID_typecast)
370 const exprt &op = typecast_expr.
op();
373 if(op_type.
id()==ID_pointer)
377 op_type.
id() == ID_c_enum || op_type.
id() == ID_c_enum_tag)
387 else if(expr.
id()==ID_if)
391 else if(expr.
id()==ID_index)
395 else if(expr.
id()==ID_member)
399 else if(expr.
id()==ID_address_of)
404 if(!bv_opt.has_value())
410 else if(expr.
id()==ID_constant)
422 else if(expr.
id()==ID_plus)
435 if(it->type().id()==ID_pointer)
443 if(pointer_base_type.
id() == ID_empty)
460 "there should be exactly one pointer-type operand in a pointer-type sum");
467 if(it->type().id()==ID_pointer)
470 if(it->type().id()!=ID_unsignedbv &&
471 it->type().id()!=ID_signedbv)
490 else if(expr.
id()==ID_minus)
497 minus_expr.
lhs().
type().
id() == ID_pointer,
498 "first operand should be of pointer type");
501 minus_expr.
rhs().
type().
id() != ID_unsignedbv &&
502 minus_expr.
rhs().
type().
id() != ID_signedbv)
511 typet pointer_base_type =
515 if(pointer_base_type.
id() == ID_empty)
524 CHECK_RETURN(element_size_opt.has_value() && *element_size_opt > 0);
525 element_size = *element_size_opt;
530 else if(expr.
id()==ID_byte_extract_little_endian ||
531 expr.
id()==ID_byte_extract_big_endian)
536 expr.
id() == ID_byte_update_little_endian ||
537 expr.
id() == ID_byte_update_big_endian)
547 if(expr.
id() != ID_minus)
552 return minus_expr.lhs().type().id() == ID_pointer &&
553 minus_expr.rhs().type().id() == ID_pointer;
558 if(expr.
type().
id()==ID_pointer)
579 const bvt object_size_bv =
588 const bvt lhs_offset =
601 const bvt rhs_offset =
620 CHECK_RETURN(element_size_opt.has_value() && *element_size_opt > 0);
622 if(*element_size_opt != 1)
624 bvt element_size_bv =
639 expr.
id() == ID_pointer_offset &&
656 expr.
id() == ID_object_size &&
668 expr.
id() == ID_pointer_object &&
684 expr.
id() == ID_typecast &&
699 else if(expr.
id() == ID_object_address)
702 return add_addr(object_address_expr.object_expr());
704 else if(expr.
id() == ID_field_address)
707 const typet &compound_type =
ns.
follow(field_address_expr.compound_type());
712 if(compound_type.
id() == ID_struct)
721 else if(compound_type.
id() == ID_union)
727 INVARIANT(
false,
"field address expressions operate on struct or union");
732 else if(expr.
id() == ID_element_address)
745 element_address_expr.type(), bv, *size, element_address_expr.index());
757 for(
const auto &literal : bv)
770 result = ch + result;
780 const typet &type)
const
782 if(type.
id() != ID_pointer)
787 bvt value_bv(bv.begin() + offset, bv.begin() + offset + bits);
791 std::string value_offset =
798 return value[value.size() - 1 - i] ==
'1';
811 return std::move(result);
823 object.reserve(object_bits);
824 for(std::size_t i=0; i<object_bits; i++)
825 object.push_back(
const_literal((addr & (std::size_t(1) << i)) != 0));
891 const std::size_t max_objects=std::size_t(1)<<object_bits;
895 "too many addressed objects: maximum number of objects is set to 2^n=" +
898 "use the `--object-bits n` option to increase the maximum number");
906 if(postponed.
expr.
id() == ID_is_dynamic_object)
911 std::size_t number=0;
913 for(
auto it = objects.cbegin(); it != objects.cend(); ++it, ++number)
915 const exprt &expr=*it;
937 else if(postponed.
expr.
id()==ID_object_size)
942 std::size_t number=0;
944 for(
auto it = objects.cbegin(); it != objects.cend(); ++it, ++number)
946 const exprt &expr=*it;
948 if(expr.
id() != ID_symbol && expr.
id() != ID_string_constant)
953 if(!size_expr.has_value())
957 size_expr.value(), postponed.
expr.
type());
986 for(postponed_listt::const_iterator
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...
message_handlert & message_handler
bool get_array_constraints
std::size_t get_width() const
const bvt & get_literals(const irep_idt &identifier, const typet &type, std::size_t width)
virtual std::size_t operator()(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 const bvt & convert_bv(const exprt &expr, const optionalt< std::size_t > expected_width=nullopt)
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
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
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
virtual exprt bv_get_rec(const exprt &expr, const bvt &bv, std::size_t offset, 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 &type) const
std::size_t get_address_width(const pointer_typet &type) const
std::size_t get_offset_width(const pointer_typet &type) const
std::size_t operator()(const typet &type) const override
bv_pointerst(const namespacet &_ns, propt &_prop, message_handlert &message_handler, bool get_array_constraints=false)
static bvt object_offset_encoding(const bvt &object, const bvt &offset)
Construct a pointer encoding from given encodings of object and offset.
bv_pointers_widtht bv_pointers_width
void do_postponed(const postponedt &postponed)
literalt convert_rest(const exprt &expr) override
pointer_logict pointer_logic
NODISCARD bvt encode(std::size_t object, const pointer_typet &type) const
virtual NODISCARD bvt add_addr(const exprt &expr)
virtual bvt convert_pointer_type(const exprt &expr)
postponed_listt postponed_list
endianness_mapt endianness_map(const typet &type, bool little_endian) const override
NODISCARD bvt offset_arithmetic(const pointer_typet &type, const bvt &bv, const mp_integer &x)
void finish_eager_conversion() override
exprt bv_get_rec(const exprt &expr, const bvt &bv, std::size_t offset, const typet &type) const override
NODISCARD optionalt< bvt > convert_address_of_rec(const exprt &expr)
std::size_t boolbv_width(const typet &type) const override
bvt convert_bitvector(const exprt &expr) 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...
static literalt sign_bit(const bvt &op)
bvt add(const bvt &op0, const bvt &op1)
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 sign_extension(const bvt &bv, std::size_t new_size)
bvt sub(const bvt &op0, const bvt &op1)
bvt divider(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
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.
std::size_t get_null_object() const
std::size_t get_invalid_object() const
numberingt< exprt, irep_hash > objects
std::size_t add_object(const exprt &expr)
exprt pointer_expr(const pointert &pointer, const pointer_typet &type) const
Convert an (object,offset) pair to an expression.
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.
literalt convert(const exprt &expr) override
Convert a Boolean expression and return the corresponding literal.
void l_set_to_true(literalt a)
virtual literalt land(literalt a, literalt b)=0
virtual literalt limplies(literalt a, literalt b)=0
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 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.
#define forall_operands(it, expr)
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
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 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)
Various predicates over pointers in programs.
#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 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.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.