1#ifndef CPROVER_POINTER_ANALYSIS_VALUE_SET_H
2#define CPROVER_POINTER_ANALYSIS_VALUE_SET_H
57 const std::vector<irep_idt> &names,
58 const std::string &rest);
70 xchg_name(
"value_sett::__ESBMC_xchg_ptr"),
81 xchg_name(
"value_sett::__ESBMC_xchg_ptr"),
119 objectt(
bool offset_set,
unsigned int operand)
168 return !(*
this == o);
184 for (
auto const &it :
themap)
197 for (
auto const &it :
themap)
265 entryt(std::string _identifier,
const std::string &_suffix)
280 return !(*
this == e);
308 if (is_null_object2t(e))
311 assert(!is_symbol_type(t));
312 if (is_array_type(t))
328 if ((m % nat_align) == 0)
334 unsigned int max_align = 8;
340 if ((m % max_align) == 0)
356 std::pair<object_mapt::iterator, bool> res =
357 dest.insert(object_mapt::value_type(it->first, it->second));
363 res.first->second = it->second;
368 return insert(dest, it->first, it->second);
395 object_mapt::const_iterator it = dest.find(n);
396 if (it == dest.end())
399 dest.insert(object_mapt::value_type(n,
object));
403 object_mapt::iterator it2 = dest.find(n);
409 if (old.
offset ==
object.offset)
415 unsigned long new_align =
offset2align(expr_obj,
object.offset);
424 if (!
object.offset_is_set)
435 unsigned int new_alignment =
offset2align(expr_obj,
object.offset);
458 return values.erase(name);
466 const std::string &
id,
468 const std::string &suffix =
"");
500 void add_var(
const std::string &
id,
const std::string &suffix)
511 void del_var(
const std::string &
id,
const std::string &suffix)
527 if (e.suffix.empty())
551 entryt fresh(e.identifier, e.suffix);
583 key.reserve(
id.size() + suffix.size());
592 for (
const auto &var : vars)
598 void output(std::ostream &out)
const;
652 const std::vector<expr2tc> &arguments);
717 const std::string &suffix,
719 bool under_deref =
true)
const;
727 using rec_cache_keyt =
728 std::tuple<const expr2t *, std::string, const type2t *, bool>;
730 std::map<rec_cache_keyt, std::tuple<expr2tc, type2tc, object_mapt>>;
735 mutable rec_cachet *rec_cache =
nullptr;
739 void get_value_set_rec(
742 const std::string &suffix,
744 bool under_deref)
const;
753 bool subtracting)
const;
761 const std::optional<BigInt> &total_offs,
770 const std::string &suffix,
779 const std::string &suffix,
781 bool under_deref)
const;
789 const std::string &suffix,
791 bool under_deref)
const;
796 const std::string &suffix,
797 const type2tc &original_type)
const;
804 const std::string &suffix,
805 const type2tc &original_type)
const;
835 const std::string &suffix,
uint64_t to_uint64() const
Definition bigint.cpp:659
Array type.
Definition irep2_type.h:422
type2tc subtype
Definition irep2_type.h:504
Definition numbering.h:79
Definition namespace.h:10
Persistent (structurally shared) map with O(1) copy.
Definition persistent_map.h:31
Symbol type.
Definition irep2_expr.h:625
std::list< expr2tc > valuest
Definition value_sets.h:15
object_map_dt(const object_map_dt &ref)
Definition value_set.h:194
const_iterator end() const
Definition value_set.h:225
object_map_dt & operator=(const object_map_dt &other)=default
object_mapt::const_iterator const_iterator
Definition value_set.h:200
object_map_dt()
Definition value_set.h:188
iterator find(unsigned i)
Definition value_set.h:215
std::size_t size(void) const
Definition value_set.h:230
const_iterator find(unsigned i) const
Definition value_set.h:210
const_iterator begin() const
Definition value_set.h:220
object_mapt themap
Definition value_set.h:235
objectt & operator[](unsigned i)
Definition value_set.h:203
object_mapt::iterator iterator
Definition value_set.h:201
~object_map_dt()
Definition value_set.h:182
Record for an object reference.
Definition value_set.h:113
BigInt offset
Record of the explicit offset into the object.
Definition value_set.h:144
bool offset_is_set
Whether or not the offset field of this objectt is valid; if this is true, then the reference has a f...
Definition value_set.h:149
objectt(bool offset_set, unsigned int operand)
Definition value_set.h:119
objectt()
Definition value_set.h:115
objectt(bool offset_set, const BigInt &_offset)
Definition value_set.h:135
bool operator==(const objectt &o) const
Definition value_set.h:160
unsigned int offset_alignment
Least alignment of the offset.
Definition value_set.h:155
bool offset_is_zero() const
Definition value_set.h:156
bool operator!=(const objectt &o) const
Definition value_set.h:166
bool insert(object_mapt &dest, unsigned n, const objectt &object) const
Insert an object record into the given object map.
Definition value_set.h:393
void touch_entry(const entryt &e)
Ensure a record exists for the given entry, without changing an existing one.
Definition value_set.h:535
void get_value_set_rec_cached(const expr2tc &expr, object_mapt &dest, const std::string &suffix, const type2tc &original_type, bool under_deref=true) const
The entry point for the recursive value-set walk: memoises, then calls get_value_set_rec.
Definition value_set.cpp:597
expr2tc to_expr(object_mapt::const_iterator it) const
Convert an object map element to an expression.
Definition value_set.cpp:105
void get_constant_union_value_set(const expr2tc &expr, object_mapt &dest, const std::string &suffix, const type2tc &original_type) const
Definition value_set.cpp:406
void do_function_call(const symbolt &symbol, const std::vector< expr2tc > &arguments)
Interpret a function call during static analysis.
Definition value_set.cpp:1847
std::unordered_map< unsigned, objectt > object_mapt
Datatype for a value set: stores a mapping between some integers and additional reference data in an ...
Definition value_set.h:176
void assign_rec(const expr2tc &lhs, const object_mapt &values_rhs, const std::string &suffix, bool add_to_sets)
Recursive assign method implementation – descends through the left hand side looking for symbols to a...
Definition value_set.cpp:1734
std::set< expr2tc > expr_sett
A type for a set of expressions.
Definition value_set.h:100
persistent_map< irep_idt, entryt, irep_id_hash > valuest
Maps each variable to the entryt holding the set of objects it may point at.
Definition value_set.h:290
void do_free(const expr2tc &op)
Mark dynamic objects as (possibly) deallocated, and thus invalid.
Definition value_set.cpp:1660
void get_byte_stitching_value_set(const expr2tc &expr, object_mapt &dest, const std::string &suffix, const type2tc &original_type) const
Definition value_set.cpp:1111
void get_constant_struct_value_set(const expr2tc &expr, object_mapt &dest, const std::string &suffix, const type2tc &original_type, bool under_deref) const
The two aggregate literals of get_constant_value_set.
Definition value_set.cpp:373
bool get_symbol_value_set(const symbol2t &sym, const expr2tc &expr, const std::string &suffix, const type2tc &original_type, object_mapt &dest) const
What sym points at: the values keyed under the path the read spells, falling back to the paths a unio...
Definition value_set.cpp:560
void del_var(const std::string &id, const std::string &suffix)
Delete the value set for the given variable name and suffix.
Definition value_set.h:511
void dump() const
Write a textual representation of the value set to stderr.
Definition value_set.cpp:2048
bool make_union(const value_sett &new_values, bool keepnew=false)
Definition value_set.h:618
expr2tc make_member(const expr2tc &src, const irep_idt &component_name)
Attempt to extract the member of an expression statically.
Definition value_set.cpp:1988
std::optional< BigInt > constant_pointer_arith_offset(const expr2tc &non_ptr_op, const type2tc &subtype, bool subtracting) const
The byte offset a constant operand of pointer arithmetic contributes, already signed by subtracting; ...
Definition value_set.cpp:426
bool erase(const std::string &name)
Remove the given pointer value set from the map.
Definition value_set.h:456
unsigned int get_natural_alignment(const expr2tc &e) const
Get the natural alignment unit of a reference to e.
Definition value_set.h:302
void output(std::ostream &out) const
Dump the value set's textual representation to the given iostream.
Definition value_set.cpp:23
value_sett & operator=(const value_sett &ref)
Definition value_set.h:86
void add_vars(const std::list< entryt > &vars)
Add a value set for each variable in the given list.
Definition value_set.h:590
void assign(const expr2tc &lhs, const expr2tc &rhs, bool add_to_sets=false)
Interpret an assignment, and update value sets to reflect it.
Definition value_set.cpp:1551
valuest values
Storage for all the value sets for all the variables in the program.
Definition value_set.h:873
unsigned location_number
Location number of the instruction this value set is attached to; used to identify allocation sites f...
Definition value_set.h:860
void get_reference_set(const expr2tc &expr, value_setst::valuest &dest) const
Determine the set of variables that expr refers to.
Definition value_set.cpp:1143
void clear()
Clear all value records from this value set.
Definition value_set.h:493
bool insert(object_mapt &dest, const expr2tc &expr, const objectt &object) const
Definition value_set.h:448
const namespacet & ns
Namespace for looking up types against.
Definition value_set.h:876
static object_numberingt object_numbering
Object to assign numbers to objects – i.e., the numbers in the map of a object_mapt.
Definition value_set.h:868
static std::string concat_key(const std::string &id, const std::string &suffix)
Compose the identifier + suffix map key into a single pre-sized buffer, avoiding the temporary that i...
Definition value_set.h:580
static void obj_numbering_ref(unsigned int num)
Definition value_set.cpp:2055
bool insert(object_mapt &dest, object_mapt::const_iterator it) const
Definition value_set.h:366
unsigned int offset2align(const expr2tc &e, const BigInt &m) const
Definition value_set.h:321
unsigned long xchg_num
Definition value_set.h:879
value_sett(const value_sett &ref)
Definition value_set.h:77
void retire_objectless_operand(object_mapt &op0_set, object_mapt &op1_set, object_mapt &dest) const
Recursive body of get_value_set.
Definition value_set.cpp:208
void assign_struct_union(const expr2tc &lhs, const expr2tc &rhs, const type2tc &lhs_type, bool add_to_sets)
assign()'s struct/union arm, split out to keep assign() one dispatch.
Definition value_set.cpp:1464
bool insert(object_mapt &dest, const expr2tc &src, const BigInt &offset) const
Definition value_set.h:371
void do_end_function(const expr2tc &lhs)
During static analysis, simulate the return values assignment to the given lhs at the end of the func...
Definition value_set.cpp:1917
static void obj_numbering_deref(unsigned int num)
Definition value_set.cpp:2060
irep_idt xchg_name
Definition value_set.h:878
void get_reference_set_rec(const expr2tc &expr, object_mapt &dest) const
Recursive implementation of get_reference_set.
Definition value_set.cpp:1158
void get_reference_set(const expr2tc &expr, object_mapt &dest) const
Internal get_reference_set method.
Definition value_set.h:812
void offset_pointer_arith_objects(const object_mapt &pointer_expr_set, const expr2tc &ptr_op, const std::optional< BigInt > &total_offs, object_mapt &dest) const
Fold total_offs into every object of pointer_expr_set, tracking alignment where the offset or the obj...
Definition value_set.cpp:491
void apply_code(const expr2tc &code)
When using value_sett for static analysis, takes a code statement and sends any assignments contained...
Definition value_set.cpp:1927
bool make_union(object_mapt &dest, const object_mapt &src) const
Join the two given object maps.
Definition value_set.cpp:160
static irep_idt entry_key(const entryt &e)
The map key is identifier + suffix.
Definition value_set.h:525
void get_constant_value_set(const expr2tc &expr, object_mapt &dest, const std::string &suffix, const type2tc &original_type, bool under_deref) const
The constant cases of get_value_set_rec: what a value reaches this code as once constant propagation ...
Definition value_set.cpp:335
value_sett(const namespacet &_ns)
Primary constructor.
Definition value_set.h:67
void add_var(const entryt &e)
Definition value_set.h:505
static object_number_numberingt obj_numbering_refset
Definition value_set.h:869
void add_var(const std::string &id, const std::string &suffix)
Add a value set for the given variable name and suffix.
Definition value_set.h:500
void set(object_mapt &dest, object_mapt::const_iterator it) const
Insert an object record element into an object map.
Definition value_set.h:353
void erase_object(const std::string &id, const type2tc &type, const std::string &suffix="")
Remove the value sets of an object of type named id: its own and those of its members and elements,...
Definition value_set.cpp:2070
void get_value_set(const expr2tc &expr, value_setst::valuest &dest) const
Get the set of things that an expression might point at.
Definition value_set.cpp:174
bool update_object_map(const entryt &e, const object_mapt &om, bool merge)
Overwrite (merge=false) or union-into (merge=true) the object map recorded for the given entry.
Definition value_set.h:545
Definition value_set.h:885
@ other
Definition converter_compare.cpp:887
Classes and definitions for non-stringy internal representation.
irep_container< type2t > type2tc
Definition irep2.h:430
irep_container< expr2t > expr2tc
Definition irep2.h:431
Definition exception.cpp:51
const T & min(const T &left, const T &right)
Definition min_max.h:19
uint256_t key
Definition solidity_mapping.c:1
const array_typet & to_array_type(const typet &type)
Definition std_types.h:425
#define true
Definition stdbool.h:11
Record for a particular value set: stores the identity of the variable that points at this set of obj...
Definition value_set.h:247
bool operator!=(const entryt &e) const
Definition value_set.h:278
entryt(std::string _identifier, const std::string &_suffix)
Definition value_set.h:265
std::string suffix
Additional suffix data – an L1 variable might actually contain several pointers.
Definition value_set.h:261
std::string identifier
The L1 name of the pointer variable that's doing the pointing.
Definition value_set.h:253
bool operator==(const entryt &e) const
Definition value_set.h:273
object_mapt object_map
The map of objects -> their offset data.
Definition value_set.h:251
BigInt type_byte_size_default(const type2tc &type, const BigInt &defaultval, const namespacet *ns)
Definition type_byte_size.cpp:225
hash_numbering< expr2tc, irep2_hash > object_numberingt
Definition value_set.h:60
std::optional< std::pair< size_t, size_t > > match_leading_component(const std::vector< irep_idt > &names, const std::string &rest)
Code for tracking "value sets" across assignments in ESBMC.
Definition value_set.cpp:235
hash_numbering< unsigned, std::hash< unsigned > > object_number_numberingt
Definition value_set.h:61