Go to the documentation of this file.
37 std::ostream &out)
const
39 for(valuest::const_iterator
46 const entryt &e=v_it->second;
58 identifier=symbol.
name;
74 const auto &entries = object_map.
read();
76 o_it != entries.end();
83 if(o.
id()==ID_invalid || o.
id()==ID_unknown)
88 if(o.
type().
id()==ID_unknown)
96 result=
"<"+
from_expr(ns, identifier, o)+
", ";
105 if(o.
type().
id()==ID_unknown)
115 width+=result.size();
120 if(next != entries.end())
144 std::cout <<
"FLATTEN: Done.\n";
158 assert(seen.find(identifier + e.
suffix)==seen.end());
160 bool generalize_index =
false;
162 seen.insert(identifier + e.
suffix);
168 if(o.
type().
id()==
"#REF#")
170 if(seen.find(o.
get(ID_identifier))!=seen.end())
172 generalize_index =
true;
176 valuest::const_iterator fi =
values.find(o.
get(ID_identifier));
192 if(t_it->second && object_entry.second)
194 *t_it->second += *object_entry.second;
197 t_it->second.reset();
200 for(
const auto &object_entry : temp.
read())
201 insert(dest, object_entry);
205 insert(dest, object_entry);
210 for(
auto &object_entry : dest.
write())
211 object_entry.second.reset();
214 seen.erase(identifier + e.
suffix);
221 if(
object.
id()==ID_invalid ||
222 object.
id()==ID_unknown)
234 return std::move(od);
242 for(valuest::const_iterator
243 it=new_values.begin();
244 it!=new_values.end();
247 valuest::iterator it2=
values.find(it->first);
253 "value_set::dynamic_object") ||
255 "value_set::return_value"))
265 const entryt &new_e=it->second;
280 for(
const auto &object_entry : src.
read())
282 if(
insert(dest, object_entry))
297 for(
const auto &object_entry : object_map.
read())
300 if(
object.type().
id()==
"#REF#")
302 assert(
object.
id()==ID_symbol);
304 const irep_idt &ident =
object.get(ID_identifier);
305 valuest::const_iterator v_it =
values.find(ident);
316 if(t_it->second && object_entry.second)
318 *t_it->second += *object_entry.second;
321 t_it->second.reset();
323 flat_map.
write()[t_it->first]=t_it->second;
328 flat_map.
write()[object_entry.first] = object_entry.second;
331 std::vector<exprt> result;
332 for(
const auto &object_entry : flat_map.
read())
333 result.push_back(
to_expr(object_entry));
337 for(std::list<exprt>::const_iterator it=value_set.begin();
340 assert(it->type().id()!=
"#REF");
344 for(expr_sett::const_iterator it=value_set.begin(); it!=value_set.end(); it++)
345 std::cout <<
"GET_VALUE_SET: " <<
format(*it) <<
'\n';
366 const std::string &suffix,
367 const typet &original_type,
372 std::cout <<
"GET_VALUE_SET_REC EXPR: " <<
format(expr)
374 std::cout <<
"GET_VALUE_SET_REC SUFFIX: " << suffix <<
'\n';
378 if(expr.
type().
id()==
"#REF#")
380 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
384 for(
const auto &object_entry : fi->second.object_map.read())
402 else if(expr.
id()==ID_unknown || expr.
id()==ID_invalid)
407 else if(expr.
id()==ID_index)
413 "operand 0 of index expression must be an array");
425 else if(expr.
id()==ID_member)
429 if(compound.is_not_nil())
434 type.
id() == ID_struct || type.
id() == ID_union,
435 "operand 0 of member expression must be struct or union");
437 const std::string &component_name =
443 "." + component_name + suffix,
451 else if(expr.
id()==ID_symbol)
456 valuest::const_iterator v_it=
values.find(ident);
463 else if(v_it!=
values.end())
472 else if(expr.
id()==ID_if)
491 else if(expr.
id()==ID_address_of)
497 else if(expr.
id()==ID_dereference)
503 if(object_map.
begin()!=object_map.
end())
505 for(
const auto &object_entry : object_map)
509 original_type, ns, recursion_set);
518 if(expr.
get(ID_value)==ID_NULL &&
519 expr.
type().
id()==ID_pointer)
525 else if(expr.
id()==ID_typecast)
537 else if(expr.
id()==ID_plus || expr.
id()==ID_minus)
540 throw expr.
id_string()+
" expected to have at least two operands";
542 if(expr.
type().
id()==ID_pointer)
545 const exprt *ptr_operand=
nullptr;
548 if(it->type().id()==ID_pointer)
550 if(ptr_operand==
nullptr)
553 throw "more than one pointer operand in pointer arithmetic";
556 if(ptr_operand==
nullptr)
557 throw "pointer type sum expected to have pointer operand";
561 ptr_operand->
type(), ns, recursion_set);
563 for(
const auto &object_entry : pointer_expr_set.
read())
565 offsett offset = object_entry.second;
571 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op0());
575 *offset = (expr.
id() == ID_plus) ? *i : -*i;
579 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op1());
583 *offset = (expr.
id() == ID_plus) ? *i : -*i;
589 insert(dest, object_entry.first, offset);
595 else if(expr.
id()==ID_side_effect)
599 if(statement==ID_function_call)
602 throw "unexpected function_call sideeffect";
604 else if(statement==ID_allocate)
606 if(expr.
type().
id()!=ID_pointer)
607 throw "malloc expected to return pointer type";
611 const typet &dynamic_type=
612 static_cast<const typet &
>(expr.
find(ID_C_cxx_alloc_type));
623 else if(statement==ID_cpp_new ||
624 statement==ID_cpp_new_array)
627 assert(expr.
type().
id()==ID_pointer);
638 else if(expr.
id()==ID_struct)
644 else if(expr.
id()==ID_with)
647 throw "unexpected value in get_value_set: "+expr.
id_string();
649 else if(expr.
id()==ID_array_of ||
656 else if(expr.
id()==ID_dynamic_object)
661 const std::string name=
662 "value_set::dynamic_object"+
667 valuest::const_iterator v_it=
values.find(name);
684 if(src.
id()==ID_typecast)
686 assert(src.
type().
id()==ID_pointer);
702 for(
const auto &object_entry : object_map.
read())
706 if(
object.type().
id() ==
"#REF#")
708 const irep_idt &ident =
object.get(ID_identifier);
709 valuest::const_iterator vit =
values.find(ident);
714 dest.insert(
exprt(ID_unknown,
object.type()));
725 if(t_it->second && object_entry.second)
727 *t_it->second += *object_entry.second;
730 t_it->second.reset();
733 for(
const auto &o : omt.
read())
738 dest.insert(
to_expr(object_entry));
750 for(
const auto &object_entry : object_map.
read())
751 dest.insert(
to_expr(object_entry));
760 std::cout <<
"GET_REFERENCE_SET_REC EXPR: " <<
format(expr)
764 if(expr.
type().
id()==
"#REF#")
766 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
769 for(
const auto &object_entry : fi->second.object_map.read())
777 else if(expr.
id()==ID_symbol ||
778 expr.
id()==ID_dynamic_object ||
779 expr.
id()==ID_string_constant)
781 if(expr.
type().
id()==ID_array &&
789 else if(expr.
id()==ID_dereference)
802 for(
const auto &object_entry : temp.
read())
805 if(obj.
type().
id()==
"#REF#")
808 valuest::const_iterator v_it =
values.find(ident);
819 if(t_it->second && object_entry.second)
821 *t_it->second += *object_entry.second;
824 t_it->second.reset();
827 for(
const auto &t2_object_entry : t2.
read())
828 insert(dest, t2_object_entry);
834 insert(dest, object_entry);
838 for(expr_sett::const_iterator it=value_set.begin();
841 std::cout <<
"VALUE_SET: " <<
format(*it) <<
'\n';
846 else if(expr.
id()==ID_index)
853 array_type.
id() == ID_array,
"index takes array-typed operand");
860 for(
const auto &object_entry : object_map)
864 if(
object.
id()==ID_unknown)
874 if(
object.type().
id() !=
"#REF#" &&
object.type() != array_type)
877 casted_index = index_expr;
879 offsett o = object_entry.second;
880 const auto i = numeric_cast<mp_integer>(offset);
890 insert(dest, casted_index, o);
896 else if(expr.
id()==ID_member)
898 const irep_idt &component_name=expr.
get(ID_component_name);
905 for(
const auto &object_entry : struct_references.
read())
908 const typet &obj_type =
object.type();
910 if(
object.
id()==ID_unknown)
913 object.
id() == ID_dynamic_object && obj_type.
id() != ID_struct &&
914 obj_type.
id() != ID_union && obj_type.
id() != ID_struct_tag &&
915 obj_type.
id() != ID_union_tag)
923 offsett o = object_entry.second;
934 insert(dest, member_expr, o);
940 else if(expr.
id()==ID_if)
956 std::cout <<
"ASSIGN LHS: " <<
format(lhs) <<
'\n';
957 std::cout <<
"ASSIGN RHS: " <<
format(rhs) <<
'\n';
969 if(type.
id()==ID_struct ||
976 for(struct_typet::componentst::const_iterator
981 const typet &subtype=c_it->type();
982 const irep_idt &name = c_it->get_name();
985 if(subtype.
id()==ID_code)
992 if(rhs.
id()==ID_unknown ||
993 rhs.
id()==ID_invalid)
995 rhs_member=
exprt(rhs.
id(), subtype);
1000 throw "value_set_fit::assign type mismatch: "
1004 if(rhs.
id()==ID_struct ||
1005 rhs.
id()==ID_constant)
1010 else if(rhs.
id()==ID_with)
1014 const exprt &member_operand = rhs_with.where();
1017 member_operand.
get(ID_component_name);
1019 if(component_name==name)
1022 rhs_member = rhs_with.new_value();
1027 rhs_member=
exprt(ID_member, subtype);
1029 rhs_member.
set(ID_component_name, name);
1034 rhs_member=
exprt(ID_member, subtype);
1036 rhs_member.
set(ID_component_name, name);
1039 assign(lhs_member, rhs_member, ns);
1043 else if(type.
id()==ID_array)
1048 if(rhs.
id()==ID_unknown ||
1049 rhs.
id()==ID_invalid)
1059 if(rhs.
type() != type)
1060 throw "value_set_fit::assign type mismatch: "
1064 if(rhs.
id()==ID_array_of)
1068 else if(rhs.
id()==ID_array ||
1069 rhs.
id()==ID_constant)
1073 assign(lhs_index, *o_it, ns);
1076 else if(rhs.
id()==ID_with)
1083 assign(lhs_index, op0_index, ns);
1090 assign(lhs_index, rhs_index, ns);
1109 const std::string &suffix,
1114 std::cout <<
"ASSIGN_REC LHS: " <<
format(lhs) <<
'\n';
1115 std::cout <<
"ASSIGN_REC SUFFIX: " << suffix <<
'\n';
1118 it!=values_rhs.
read().
end(); it++)
1119 std::cout <<
"ASSIGN_REC RHS: " <<
to_expr(it) <<
'\n';
1122 if(lhs.
type().
id()==
"#REF#")
1129 if(recursion_set.find(ident)!=recursion_set.end())
1131 recursion_set.insert(ident);
1133 for(
const auto &object_entry : temp.
read())
1137 if(
object.
id() != ID_unknown)
1138 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1141 recursion_set.erase(ident);
1144 else if(lhs.
id()==ID_symbol)
1149 "value_set::dynamic_object") ||
1151 "value_set::return_value") ||
1161 else if(lhs.
id()==ID_dynamic_object)
1166 const std::string name=
1167 "value_set::dynamic_object"+
1173 else if(lhs.
id()==ID_dereference)
1176 throw lhs.
id_string()+
" expected to have one operand";
1181 for(
const auto &object_entry : reference_set.
read())
1185 if(
object.
id()!=ID_unknown)
1186 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1189 else if(lhs.
id()==ID_index)
1195 "operand 0 of index expression must be an array");
1198 to_index_expr(lhs).array(), values_rhs,
"[]" + suffix, ns, recursion_set);
1200 else if(lhs.
id()==ID_member)
1205 const std::string &component_name=lhs.
get_string(ID_component_name);
1210 type.
id() == ID_struct || type.
id() == ID_union,
1211 "operand 0 of member expression must be struct or union");
1216 "." + component_name + suffix,
1220 else if(lhs.
id()==
"valid_object" ||
1221 lhs.
id()==
"dynamic_type")
1225 else if(lhs.
id()==ID_string_constant)
1230 else if(lhs.
id() == ID_null_object)
1234 else if(lhs.
id()==ID_typecast)
1238 assign_rec(typecast_expr.
op(), values_rhs, suffix, ns, recursion_set);
1240 else if(lhs.
id()==
"zero_string" ||
1241 lhs.
id()==
"is_zero_string" ||
1242 lhs.
id()==
"zero_string_length")
1246 else if(lhs.
id()==ID_byte_extract_little_endian ||
1247 lhs.
id()==ID_byte_extract_big_endian)
1253 throw "assign NYI: '" + lhs.
id_string() +
"'";
1271 for(std::size_t i=0; i<arguments.size(); i++)
1273 const std::string identifier=
"value_set::" +
id2string(
function) +
"::" +
1276 const symbol_exprt dummy_lhs(identifier, arguments[i].type());
1277 assign(dummy_lhs, arguments[i], ns);
1284 for(code_typet::parameterst::const_iterator
1285 it=parameter_types.begin();
1286 it!=parameter_types.end();
1289 const irep_idt &identifier=it->get_identifier();
1290 if(identifier.
empty())
1300 assign(actual_lhs, v_expr, ns);
1322 if(statement==ID_block)
1327 else if(statement==ID_function_call)
1332 else if(statement==ID_assign)
1335 throw "assignment expected to have two operands";
1339 else if(statement==ID_decl)
1342 throw "decl expected to have one operand";
1346 if(lhs.
id()!=ID_symbol)
1347 throw "decl expected to have symbol on lhs";
1351 else if(statement==ID_expression)
1355 else if(statement==ID_cpp_delete ||
1356 statement==ID_cpp_delete_array)
1360 else if(statement==
"lock" || statement==
"unlock")
1364 else if(statement==ID_asm)
1368 else if(statement==ID_nondet)
1372 else if(statement==ID_printf)
1376 else if(statement==ID_return)
1387 else if(statement==ID_fence)
1390 else if(statement==ID_array_copy ||
1391 statement==ID_array_replace ||
1392 statement==ID_array_set)
1402 "value_set_fit: unexpected statement: "+
id2string(statement);
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
#define UNREACHABLE
This should be used to mark dead code.
const componentst & components() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
entryt & get_entry(const idt &id, const std::string &suffix)
static const char * alloc_adapter_prefix
std::unordered_set< idt, string_hash > assign_recursion_sett
const typet & subtype() const
bool can_cast_expr< code_inputt >(const exprt &base)
std::unordered_map< idt, entryt, string_hash > valuest
bool offset_is_zero(const offsett &offset) const
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
Value Set (Flow Insensitive, Sharing)
data_typet::iterator iterator
const irep_idt & display_name() const
Return language specific display name if present.
The type of an expression, extends irept.
std::vector< parametert > parameterst
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
void assign(const exprt &lhs, const exprt &rhs, const namespacet &ns)
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.
void get_reference_set_sharing_rec(const exprt &expr, object_mapt &dest, const namespacet &ns) const
Base type for structs and unions.
typet type
Type of symbol.
Representation of heap-allocated objects.
std::unordered_set< idt, string_hash > flatten_seent
std::unordered_set< exprt, irep_hash > expr_sett
Split an expression into a base object and a (byte) offset.
const irept & find(const irep_namet &name) const
void do_function_call(const irep_idt &function, const exprt::operandst &arguments, const namespacet &ns)
const array_of_exprt & to_array_of_expr(const exprt &expr)
Cast an exprt to an array_of_exprt.
Base class for all expressions.
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
std::unordered_set< idt, string_hash > gvs_recursion_sett
void dereference_rec(const exprt &src, exprt &dest) const
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
exprt dynamic_object(const exprt &pointer)
unsigned from_target_index
side_effect_exprt & to_side_effect_expr(exprt &expr)
void flatten(const entryt &e, object_mapt &dest) const
Expression to hold a symbol (variable)
void flatten_rec(const entryt &, object_mapt &, flatten_seent &) const
bitvector_typet index_type()
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_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().
void apply_code(const codet &code, const namespacet &ns)
Expression classes for byte-level operators.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
bool has_prefix(const std::string &s, const std::string &prefix)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
const std::string & id2string(const irep_idt &d)
const exprt & compound() const
#define forall_operands(it, expr)
data_typet::const_iterator const_iterator
#define PRECONDITION(CONDITION)
const irep_idt & get_identifier() const
std::vector< exprt > get_value_set(const exprt &expr, const namespacet &ns) const
API to expression classes for Pointers.
const std::string & id_string() const
bool simplify(exprt &expr, const namespacet &ns)
void assign_rec(const exprt &lhs, const object_mapt &values_rhs, const std::string &suffix, const namespacet &ns, assign_recursion_sett &recursion_set)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
std::vector< exprt > operandst
const code_returnt & to_code_return(const codet &code)
const parameterst & parameters() const
const dynamic_object_exprt & to_dynamic_object_expr(const exprt &expr)
Cast an exprt to a dynamic_object_exprt.
static const object_map_dt blank
const with_exprt & to_with_expr(const exprt &expr)
Cast an exprt to a with_exprt.
const irep_idt & get_statement() const
bool is_zero() const
Return whether the expression is a constant representing 0.
Extract member of struct or union.
bool make_union(object_mapt &dest, const object_mapt &src) const
const std::string & get_string(const irep_namet &name) const
bool has_return_value() const
void output(const namespacet &ns, std::ostream &out) const
bool can_cast_expr< code_outputt >(const exprt &base)
codet representation of a "return from a function" statement.
exprt to_expr(const object_map_dt::value_type &it) const
void do_end_function(const exprt &lhs, const namespacet &ns)
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
const irep_idt & get(const irep_namet &name) const
void set(const irep_namet &name, const irep_idt &value)
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
bool is_constant() const
Return whether the expression is a constant.
static object_numberingt object_numbering
static numberingt< irep_idt > function_numbering
const code_blockt & to_code_block(const codet &code)
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
void get_reference_set_sharing(const exprt &expr, expr_sett &expr_set, const namespacet &ns) const
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
optionalt< mp_integer > offsett
Represents the offset into an object: either a unique integer offset, or an unknown value,...
Operator to return the address of an object.
data_typet::value_type value_type
Semantic type conversion.
const exprt & return_value() const
The Boolean constant true.
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
void get_reference_set(const exprt &expr, expr_sett &expr_set, const namespacet &ns) const
irep_idt name
The unique identifier.
void add_var(const idt &id)
bool insert(object_mapt &dest, const object_map_dt::value_type &it) const
void get_value_set_rec(const exprt &expr, object_mapt &dest, const std::string &suffix, const typet &original_type, const namespacet &ns, gvs_recursion_sett &recursion_set) const
Data structure for representing an arbitrary statement in a program.
const std::string integer2string(const mp_integer &n, unsigned base)