Go to the documentation of this file.
51 bool seen_symbol =
false;
54 if(it->id() == ID_symbol)
68 const std::vector<exprt> &points_to_set,
69 const std::vector<exprt> &retained_values,
74 json_result[
"PointsToSetSize"] =
78 for(
const auto &
object : points_to_set)
83 json_result[
"PointsToSet"] = points_to_set_json;
85 json_result[
"RetainedValuesSetSize"] =
89 for(
auto &retained_value : retained_values)
95 json_result[
"RetainedValuesSet"] = retained_values_set_json;
108 if(
const auto *index_expr = expr_try_dynamic_cast<index_exprt>(expr))
114 offset_elements, index_expr->index().
type())}};
116 else if(
const auto *if_expr = expr_try_dynamic_cast<if_exprt>(expr))
118 const auto true_case =
122 const auto false_case =
126 return if_exprt{if_expr->
cond(), *true_case, *false_case};
142 const exprt &pointer,
143 bool display_points_to_sets)
145 if(pointer.
type().
id()!=ID_pointer)
146 throw "dereference expected pointer type, but got "+
150 if(pointer.
id()==ID_if)
158 else if(pointer.
id() == ID_typecast)
160 const exprt *underlying = &pointer;
163 while(underlying->
id() == ID_typecast &&
164 underlying->
type().
id() == ID_pointer)
169 if(underlying->
id() == ID_if && underlying->
type().
id() == ID_pointer)
171 const auto &if_expr =
to_if_expr(*underlying);
176 display_points_to_sets),
179 display_points_to_sets));
182 else if(pointer.
id() == ID_plus && pointer.
operands().size() == 2)
193 std::swap(pointer_expr, offset_expr);
202 auto derefd_with_offset =
204 return *derefd_with_offset;
214 const exprt &pointer,
215 bool display_points_to_sets)
220 const std::vector<exprt> points_to_set =
224 const std::vector<exprt> retained_values =
229 exprt compare_against_pointer = pointer;
241 compare_against_pointer = fresh_binder.
symbol_expr();
246 .map([&](
const exprt &value) {
249 .collect<std::deque<valuet>>();
251 const bool may_fail =
253 std::any_of(values.begin(), values.end(), [](
const valuet &value) {
254 return value.value.is_nil();
266 for(
const auto &value : values)
271 result_value = value.
value;
277 if(compare_against_pointer != pointer)
281 if(display_points_to_sets)
284 pointer, points_to_set, retained_values, result_value);
291 const exprt &pointer,
302 failure_value = failed_symbol->symbol_expr();
303 failure_value.
set(ID_C_invalid_object,
true);
320 failure_value.
set(ID_C_invalid_object,
true);
324 result.
value = failure_value;
338 const typet &object_type,
339 const typet &dereference_type,
342 const typet *object_unwrapped = &object_type;
343 const typet *dereference_unwrapped = &dereference_type;
344 while(object_unwrapped->
id() == ID_pointer &&
345 dereference_unwrapped->
id() == ID_pointer)
348 dereference_unwrapped =
351 if(dereference_unwrapped->
id() == ID_empty)
355 else if(dereference_unwrapped->
id() == ID_pointer &&
356 object_unwrapped->
id() != ID_pointer)
359 std::cout <<
"value_set_dereference: the dereference type has "
360 "too many ID_pointer levels"
362 std::cout <<
" object_type: " << object_type.
pretty() << std::endl;
363 std::cout <<
" dereference_type: " << dereference_type.
pretty()
368 if(object_type == dereference_type)
374 dt_base=
ns.
follow(dereference_type);
376 if(ot_base.
id()==ID_struct &&
377 dt_base.id()==ID_struct)
385 if(dereference_type.
id()==ID_code &&
386 object_type.
id()==ID_code)
390 if((dereference_type.
id()==ID_signedbv ||
391 dereference_type.
id()==ID_unsignedbv) &&
392 (object_type.
id()==ID_signedbv ||
393 object_type.
id()==ID_unsignedbv) &&
418 bool exclude_null_derefs,
421 if(what.
id() == ID_unknown || what.
id() == ID_invalid)
429 if(root_object.
id() == ID_null_object)
433 else if(root_object.
id() == ID_integer_address)
455 const exprt &pointer_expr,
459 type_checked_cast<pointer_typet>(pointer_expr.
type());
462 if(what.
id()==ID_unknown ||
463 what.
id()==ID_invalid)
468 if(what.
id()!=ID_object_descriptor)
469 throw "unknown points-to: "+what.
id_string();
477 std::cout <<
"O: " <<
format(root_object) <<
'\n';
482 if(root_object.
id() == ID_null_object)
489 else if(root_object.
id()==ID_dynamic_object)
499 else if(root_object.
id()==ID_integer_address)
517 result.
value=index_expr;
565 const typet &object_type =
object.type();
566 const typet &root_object_type = root_object.
type();
568 exprt root_object_subexpression=root_object;
582 root_object_type.
id() == ID_array &&
584 to_array_type(root_object_type).element_type(), dereference_type,
ns) &&
602 if(!element_size.has_value() || *element_size == 0)
604 throw "unknown or invalid type size of:\n" +
610 exprt adjusted_offset =
613 index_exprt index_expr{root_object, adjusted_offset};
623 root_object_subexpression, o.
offset(), dereference_type,
ns);
624 if(subexpr.has_value())
627 subexpr.has_value() &&
628 subexpr.value().id() != ID_byte_extract_little_endian &&
629 subexpr.value().id() != ID_byte_extract_big_endian)
633 result.
value = subexpr.value();
667 return type.
id()==ID_unsignedbv ||
668 type.
id()==ID_signedbv ||
670 type.
id()==ID_fixedbv ||
671 type.
id()==ID_floatbv ||
672 type.
id()==ID_c_enum_tag;
685 const typet &to_type,
699 (
from_type.id() == ID_pointer && to_type.
id() == ID_pointer))
708 to_type.
id() != ID_fixedbv && to_type.
id() != ID_floatbv &&
732 const typet &to_type,
739 if(
from_type.id()==ID_code || to_type.
id()==ID_code)
753 auto from_type_element_type_size =
761 from_type.id() == ID_array && from_type_element_type_size.has_value() &&
762 *from_type_element_type_size == 1 && to_type_size.has_value() &&
763 *to_type_size == 1 &&
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
byte_extract_exprt make_byte_extract(const exprt &_op, const exprt &_offset, const typet &_type)
Construct a byte_extract_exprt with endianness and byte width matching the current configuration.
static exprt conditional_cast(const exprt &expr, const typet &type)
static optionalt< exprt > try_add_offset_to_indices(const exprt &expr, const exprt &offset_elements)
If expr is of the form (c1 ? e1[o1] : c2 ? e2[o2] : c3 ? ...) then return c1 ? e1[o1 + offset] : e2[o...
Return value for build_reference_to; see that method for documentation.
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
depth_iteratort depth_end()
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
static bool memory_model(exprt &value, const typet &type, const exprt &offset, const namespacet &ns)
Replace value by an expression of type to_type corresponding to the value at memory address value + o...
The type of an expression, extends irept.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
mstreamt & status() const
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
typet type
Type of symbol.
Operator to dereference a pointer.
The trinary if-then-else operator.
Evaluates to true if the operand is a pointer to a dynamic object.
static json_objectt value_set_dereference_stats_to_json(const exprt &pointer, const std::vector< exprt > &points_to_set, const std::vector< exprt > &retained_values, const exprt &value)
const irep_idt language_mode
language_mode: ID_java, ID_C or another language identifier if we know the source language in use,...
Split an expression into a base object and a (byte) offset.
The plus expression Associativity is not specified.
static bool should_ignore_value(const exprt &what, bool exclude_null_derefs, const irep_idt &language_mode)
Determine whether possible alias what should be ignored when replacing a pointer by its referees.
const bool exclude_null_derefs
Flag indicating whether value_set_dereferencet::dereference should disregard an apparent attempt to d...
Base class for all expressions.
valuet get_failure_value(const exprt &pointer, const typet &type)
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
virtual const symbolt * get_or_create_failed_symbol(const exprt &expr)=0
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
static bool dereference_type_compare(const typet &object_type, const typet &dereference_type, const namespacet &ns)
Check if the two types have matching number of ID_pointer levels, with the dereference type eventuall...
struct configt::ansi_ct ansi_c
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
Expression to hold a symbol (variable)
virtual std::vector< exprt > get_value_set(const exprt &expr) const =0
bool can_cast_type< pointer_typet >(const typet &type)
Check whether a reference to a typet is a pointer_typet.
static const exprt & root_object(const exprt &expr)
symbol_tablet & new_symbol_table
const object_descriptor_exprt & to_object_descriptor_expr(const exprt &expr)
Cast an exprt to an object_descriptor_exprt.
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.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Expression classes for byte-level operators.
The null pointer constant.
static bool should_use_local_definition_for(const exprt &expr)
Returns true if expr is complicated enough that a local definition (using a let expression) is prefer...
void set(const irep_idt &name, const irep_idt &value)
optionalt< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
const plus_exprt & to_plus_expr(const exprt &expr)
Cast an exprt to a plus_exprt.
dereference_callbackt & dereference_callback
const std::string & id_string() const
bool simplify(exprt &expr, const namespacet &ns)
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
exprt simplify_expr(exprt src, const namespacet &ns)
pointer_typet pointer_type(const typet &subtype)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
static bool memory_model_bytes(exprt &value, const typet &type, const exprt &offset, const namespacet &ns)
Replace value by an expression of type to_type corresponding to the value at memory address value + o...
nonstd::optional< T > optionalt
exprt pointer_offset(const exprt &pointer)
bool is_zero() const
Return whether the expression is a constant representing 0.
Deprecated expression utility functions.
static bool is_a_bv_type(const typet &type)
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.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
depth_iteratort depth_begin()
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
optionalt< exprt > get_subexpression_at_offset(const exprt &expr, const mp_integer &offset_bytes, const typet &target_type_raw, const namespacet &ns)
bool is_constant() const
Return whether the expression is a constant.
const typet & base_type() const
The type of the data what we point to.
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)
static valuet build_reference_to(const exprt &what, const exprt &pointer, const namespacet &ns)
bool can_cast_expr< typecast_exprt >(const exprt &base)
bool can_cast_expr< constant_exprt >(const exprt &base)
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 ...
The Boolean constant true.
const source_locationt & source_location() const
ranget< iteratort > make_range(iteratort begin, iteratort end)
symbolt & get_fresh_aux_symbol(const typet &type, const std::string &name_prefix, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &symbol_mode, const namespacet &ns, symbol_table_baset &symbol_table)
Installs a fresh-named symbol with respect to the given namespace ns with the requested name pattern ...
irep_idt name
The unique identifier.
jsont & push_back(const jsont &json)
const typet & element_type() const
The type of the elements of the array.
exprt dereference(const exprt &pointer, bool display_points_to_sets=false)
Dereference the given pointer-expression.
exprt handle_dereference_base_case(const exprt &pointer, bool display_points_to_sets)