Go to the documentation of this file.
38 std::ostream &out)
const
40 for(valuest::const_iterator
47 const entryt &e=v_it->second;
59 identifier=symbol.
name;
75 const auto &entries = object_map.
read();
77 o_it != entries.end();
84 if(o.
id()==ID_invalid || o.
id()==ID_unknown)
89 if(o.
type().
id()==ID_unknown)
97 result=
"<"+
from_expr(ns, identifier, o)+
", ";
106 if(o.
type().
id()==ID_unknown)
116 width+=result.size();
121 if(next != entries.end())
145 std::cout <<
"FLATTEN: Done.\n";
159 assert(seen.find(identifier + e.
suffix)==seen.end());
161 bool generalize_index =
false;
163 seen.insert(identifier + e.
suffix);
169 if(o.
type().
id()==
"#REF#")
171 if(seen.find(o.
get(ID_identifier))!=seen.end())
173 generalize_index =
true;
177 valuest::const_iterator fi =
values.find(o.
get(ID_identifier));
193 if(t_it->second && object_entry.second)
195 *t_it->second += *object_entry.second;
198 t_it->second.reset();
201 for(
const auto &object_entry : temp.
read())
202 insert(dest, object_entry);
206 insert(dest, object_entry);
211 for(
auto &object_entry : dest.
write())
212 object_entry.second.reset();
215 seen.erase(identifier + e.
suffix);
222 if(
object.
id()==ID_invalid ||
223 object.
id()==ID_unknown)
235 return std::move(od);
243 for(valuest::const_iterator
244 it=new_values.begin();
245 it!=new_values.end();
248 valuest::iterator it2=
values.find(it->first);
254 "value_set::dynamic_object") ||
256 "value_set::return_value"))
266 const entryt &new_e=it->second;
281 for(
const auto &object_entry : src.
read())
283 if(
insert(dest, object_entry))
298 for(
const auto &object_entry : object_map.
read())
301 if(
object.type().
id()==
"#REF#")
303 assert(
object.
id()==ID_symbol);
305 const irep_idt &ident =
object.get(ID_identifier);
306 valuest::const_iterator v_it =
values.find(ident);
317 if(t_it->second && object_entry.second)
319 *t_it->second += *object_entry.second;
322 t_it->second.reset();
324 flat_map.
write()[t_it->first]=t_it->second;
329 flat_map.
write()[object_entry.first] = object_entry.second;
332 std::vector<exprt> result;
333 for(
const auto &object_entry : flat_map.
read())
334 result.push_back(
to_expr(object_entry));
338 for(std::list<exprt>::const_iterator it=value_set.begin();
341 assert(it->type().id()!=
"#REF");
345 for(expr_sett::const_iterator it=value_set.begin(); it!=value_set.end(); it++)
346 std::cout <<
"GET_VALUE_SET: " <<
format(*it) <<
'\n';
367 const std::string &suffix,
368 const typet &original_type,
373 std::cout <<
"GET_VALUE_SET_REC EXPR: " <<
format(expr)
375 std::cout <<
"GET_VALUE_SET_REC SUFFIX: " << suffix <<
'\n';
379 if(expr.
type().
id()==
"#REF#")
381 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
385 for(
const auto &object_entry : fi->second.object_map.read())
403 else if(expr.
id()==ID_unknown || expr.
id()==ID_invalid)
408 else if(expr.
id()==ID_index)
414 "operand 0 of index expression must be an array");
426 else if(expr.
id()==ID_member)
430 if(compound.is_not_nil())
435 type.
id() == ID_struct || type.
id() == ID_union,
436 "operand 0 of member expression must be struct or union");
438 const std::string &component_name =
444 "." + component_name + suffix,
452 else if(expr.
id()==ID_symbol)
457 valuest::const_iterator v_it=
values.find(ident);
464 else if(v_it!=
values.end())
473 else if(expr.
id()==ID_if)
492 else if(expr.
id()==ID_address_of)
498 else if(expr.
id()==ID_dereference)
504 if(object_map.
begin()!=object_map.
end())
506 for(
const auto &object_entry : object_map)
510 original_type, ns, recursion_set);
519 if(expr.
get(ID_value)==ID_NULL &&
520 expr.
type().
id()==ID_pointer)
526 else if(expr.
id()==ID_typecast)
538 else if(expr.
id()==ID_plus || expr.
id()==ID_minus)
541 throw expr.
id_string()+
" expected to have at least two operands";
543 if(expr.
type().
id()==ID_pointer)
546 const exprt *ptr_operand=
nullptr;
549 if(it->type().id()==ID_pointer)
551 if(ptr_operand==
nullptr)
554 throw "more than one pointer operand in pointer arithmetic";
557 if(ptr_operand==
nullptr)
558 throw "pointer type sum expected to have pointer operand";
562 ptr_operand->
type(), ns, recursion_set);
564 for(
const auto &object_entry : pointer_expr_set.
read())
566 offsett offset = object_entry.second;
572 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op0());
576 *offset = (expr.
id() == ID_plus) ? *i : -*i;
580 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op1());
584 *offset = (expr.
id() == ID_plus) ? *i : -*i;
590 insert(dest, object_entry.first, offset);
596 else if(expr.
id()==ID_side_effect)
600 if(statement==ID_function_call)
603 throw "unexpected function_call sideeffect";
605 else if(statement==ID_allocate)
607 if(expr.
type().
id()!=ID_pointer)
608 throw "malloc expected to return pointer type";
612 const typet &dynamic_type=
613 static_cast<const typet &
>(expr.
find(ID_C_cxx_alloc_type));
624 else if(statement==ID_cpp_new ||
625 statement==ID_cpp_new_array)
628 assert(expr.
type().
id()==ID_pointer);
639 else if(expr.
id()==ID_struct)
645 else if(expr.
id()==ID_with)
648 throw "unexpected value in get_value_set: "+expr.
id_string();
650 else if(expr.
id()==ID_array_of ||
657 else if(expr.
id()==ID_dynamic_object)
662 const std::string name=
663 "value_set::dynamic_object"+
668 valuest::const_iterator v_it=
values.find(name);
685 if(src.
id()==ID_typecast)
687 assert(src.
type().
id()==ID_pointer);
703 for(
const auto &object_entry : object_map.
read())
707 if(
object.type().
id() ==
"#REF#")
709 const irep_idt &ident =
object.get(ID_identifier);
710 valuest::const_iterator vit =
values.find(ident);
715 dest.insert(
exprt(ID_unknown,
object.type()));
726 if(t_it->second && object_entry.second)
728 *t_it->second += *object_entry.second;
731 t_it->second.reset();
734 for(
const auto &o : omt.
read())
739 dest.insert(
to_expr(object_entry));
751 for(
const auto &object_entry : object_map.
read())
752 dest.insert(
to_expr(object_entry));
761 std::cout <<
"GET_REFERENCE_SET_REC EXPR: " <<
format(expr)
765 if(expr.
type().
id()==
"#REF#")
767 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
770 for(
const auto &object_entry : fi->second.object_map.read())
778 else if(expr.
id()==ID_symbol ||
779 expr.
id()==ID_dynamic_object ||
780 expr.
id()==ID_string_constant)
782 if(expr.
type().
id()==ID_array &&
790 else if(expr.
id()==ID_dereference)
803 for(
const auto &object_entry : temp.
read())
806 if(obj.
type().
id()==
"#REF#")
809 valuest::const_iterator v_it =
values.find(ident);
820 if(t_it->second && object_entry.second)
822 *t_it->second += *object_entry.second;
825 t_it->second.reset();
828 for(
const auto &t2_object_entry : t2.
read())
829 insert(dest, t2_object_entry);
835 insert(dest, object_entry);
839 for(expr_sett::const_iterator it=value_set.begin();
842 std::cout <<
"VALUE_SET: " <<
format(*it) <<
'\n';
847 else if(expr.
id()==ID_index)
854 array_type.
id() == ID_array,
"index takes array-typed operand");
861 for(
const auto &object_entry : object_map)
865 if(
object.
id()==ID_unknown)
875 if(
object.type().
id() !=
"#REF#" &&
object.type() != array_type)
878 casted_index = index_expr;
880 offsett o = object_entry.second;
881 const auto i = numeric_cast<mp_integer>(offset);
891 insert(dest, casted_index, o);
897 else if(expr.
id()==ID_member)
899 const irep_idt &component_name=expr.
get(ID_component_name);
906 for(
const auto &object_entry : struct_references.
read())
909 const typet &obj_type =
object.type();
911 if(
object.
id()==ID_unknown)
914 object.
id() == ID_dynamic_object && obj_type.
id() != ID_struct &&
915 obj_type.
id() != ID_union && obj_type.
id() != ID_struct_tag &&
916 obj_type.
id() != ID_union_tag)
924 offsett o = object_entry.second;
935 insert(dest, member_expr, o);
941 else if(expr.
id()==ID_if)
957 std::cout <<
"ASSIGN LHS: " <<
format(lhs) <<
'\n';
958 std::cout <<
"ASSIGN RHS: " <<
format(rhs) <<
'\n';
970 if(type.
id()==ID_struct ||
977 for(struct_typet::componentst::const_iterator
982 const typet &subtype=c_it->type();
983 const irep_idt &name = c_it->get_name();
986 if(subtype.
id()==ID_code)
993 if(rhs.
id()==ID_unknown ||
994 rhs.
id()==ID_invalid)
996 rhs_member=
exprt(rhs.
id(), subtype);
1001 throw "value_set_fit::assign type mismatch: "
1005 if(rhs.
id()==ID_struct ||
1006 rhs.
id()==ID_constant)
1011 else if(rhs.
id()==ID_with)
1015 const exprt &member_operand = rhs_with.where();
1018 member_operand.
get(ID_component_name);
1020 if(component_name==name)
1023 rhs_member = rhs_with.new_value();
1028 rhs_member=
exprt(ID_member, subtype);
1030 rhs_member.
set(ID_component_name, name);
1035 rhs_member=
exprt(ID_member, subtype);
1037 rhs_member.
set(ID_component_name, name);
1040 assign(lhs_member, rhs_member, ns);
1044 else if(type.
id()==ID_array)
1049 if(rhs.
id()==ID_unknown ||
1050 rhs.
id()==ID_invalid)
1060 if(rhs.
type() != type)
1061 throw "value_set_fit::assign type mismatch: "
1065 if(rhs.
id()==ID_array_of)
1069 else if(rhs.
id()==ID_array ||
1070 rhs.
id()==ID_constant)
1074 assign(lhs_index, *o_it, ns);
1077 else if(rhs.
id()==ID_with)
1084 assign(lhs_index, op0_index, ns);
1091 assign(lhs_index, rhs_index, ns);
1110 const std::string &suffix,
1115 std::cout <<
"ASSIGN_REC LHS: " <<
format(lhs) <<
'\n';
1116 std::cout <<
"ASSIGN_REC SUFFIX: " << suffix <<
'\n';
1119 it!=values_rhs.
read().
end(); it++)
1120 std::cout <<
"ASSIGN_REC RHS: " <<
to_expr(it) <<
'\n';
1123 if(lhs.
type().
id()==
"#REF#")
1130 if(recursion_set.find(ident)!=recursion_set.end())
1132 recursion_set.insert(ident);
1134 for(
const auto &object_entry : temp.
read())
1138 if(
object.
id() != ID_unknown)
1139 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1142 recursion_set.erase(ident);
1145 else if(lhs.
id()==ID_symbol)
1150 "value_set::dynamic_object") ||
1152 "value_set::return_value") ||
1162 else if(lhs.
id()==ID_dynamic_object)
1167 const std::string name=
1168 "value_set::dynamic_object"+
1174 else if(lhs.
id()==ID_dereference)
1177 throw lhs.
id_string()+
" expected to have one operand";
1182 for(
const auto &object_entry : reference_set.
read())
1186 if(
object.
id()!=ID_unknown)
1187 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1190 else if(lhs.
id()==ID_index)
1196 "operand 0 of index expression must be an array");
1199 to_index_expr(lhs).array(), values_rhs,
"[]" + suffix, ns, recursion_set);
1201 else if(lhs.
id()==ID_member)
1206 const std::string &component_name=lhs.
get_string(ID_component_name);
1211 type.
id() == ID_struct || type.
id() == ID_union,
1212 "operand 0 of member expression must be struct or union");
1217 "." + component_name + suffix,
1221 else if(lhs.
id()==
"valid_object" ||
1222 lhs.
id()==
"dynamic_size" ||
1223 lhs.
id()==
"dynamic_type")
1227 else if(lhs.
id()==ID_string_constant)
1232 else if(lhs.
id() == ID_null_object)
1236 else if(lhs.
id()==ID_typecast)
1240 assign_rec(typecast_expr.
op(), values_rhs, suffix, ns, recursion_set);
1242 else if(lhs.
id()==
"zero_string" ||
1243 lhs.
id()==
"is_zero_string" ||
1244 lhs.
id()==
"zero_string_length")
1248 else if(lhs.
id()==ID_byte_extract_little_endian ||
1249 lhs.
id()==ID_byte_extract_big_endian)
1255 throw "assign NYI: '" + lhs.
id_string() +
"'";
1273 for(std::size_t i=0; i<arguments.size(); i++)
1275 const std::string identifier=
"value_set::" +
id2string(
function) +
"::" +
1278 const symbol_exprt dummy_lhs(identifier, arguments[i].type());
1279 assign(dummy_lhs, arguments[i], ns);
1286 for(code_typet::parameterst::const_iterator
1287 it=parameter_types.begin();
1288 it!=parameter_types.end();
1291 const irep_idt &identifier=it->get_identifier();
1292 if(identifier.
empty())
1302 assign(actual_lhs, v_expr, ns);
1324 if(statement==ID_block)
1329 else if(statement==ID_function_call)
1334 else if(statement==ID_assign)
1337 throw "assignment expected to have two operands";
1341 else if(statement==ID_decl)
1344 throw "decl expected to have one operand";
1348 if(lhs.
id()!=ID_symbol)
1349 throw "decl expected to have symbol on lhs";
1353 else if(statement==ID_expression)
1357 else if(statement==ID_cpp_delete ||
1358 statement==ID_cpp_delete_array)
1362 else if(statement==
"lock" || statement==
"unlock")
1366 else if(statement==ID_asm)
1370 else if(statement==ID_nondet)
1374 else if(statement==ID_printf)
1378 else if(statement==ID_return)
1389 else if(statement==ID_fence)
1392 else if(statement==ID_array_copy ||
1393 statement==ID_array_replace ||
1394 statement==ID_array_set)
1404 "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.
API to expression classes.
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)