39 std::ostream &out)
const
41 for(valuest::const_iterator
48 const entryt &e=v_it->second;
60 identifier=symbol.
name;
76 const auto &entries = object_map.
read();
78 o_it != entries.end();
85 if(o.
id()==ID_invalid || o.
id()==ID_unknown)
90 if(o.
type().
id()==ID_unknown)
98 result=
"<"+
from_expr(ns, identifier, o)+
", ";
107 if(o.
type().
id()==ID_unknown)
117 width+=result.size();
122 if(next != entries.end())
146 std::cout <<
"FLATTEN: Done.\n";
160 assert(seen.find(identifier + e.
suffix)==seen.end());
162 bool generalize_index =
false;
164 seen.insert(identifier + e.
suffix);
170 if(o.
type().
id()==
"#REF#")
172 if(seen.find(o.
get(ID_identifier))!=seen.end())
174 generalize_index =
true;
178 valuest::const_iterator fi =
values.find(o.
get(ID_identifier));
194 if(t_it->second && object_entry.second)
196 *t_it->second += *object_entry.second;
199 t_it->second.reset();
202 for(
const auto &object_entry : temp.
read())
203 insert(dest, object_entry);
207 insert(dest, object_entry);
212 for(
auto &object_entry : dest.
write())
213 object_entry.second.reset();
216 seen.erase(identifier + e.
suffix);
223 if(
object.
id()==ID_invalid ||
224 object.
id()==ID_unknown)
236 return std::move(od);
244 for(valuest::const_iterator
245 it=new_values.begin();
246 it!=new_values.end();
249 valuest::iterator it2=
values.find(it->first);
255 "value_set::dynamic_object") ||
257 "value_set::return_value"))
267 const entryt &new_e=it->second;
282 for(
const auto &object_entry : src.
read())
284 if(
insert(dest, object_entry))
299 for(
const auto &object_entry : object_map.
read())
302 if(
object.type().
id()==
"#REF#")
304 assert(
object.
id()==ID_symbol);
306 const irep_idt &ident =
object.get(ID_identifier);
307 valuest::const_iterator v_it =
values.find(ident);
318 if(t_it->second && object_entry.second)
320 *t_it->second += *object_entry.second;
323 t_it->second.reset();
325 flat_map.
write()[t_it->first]=t_it->second;
330 flat_map.
write()[object_entry.first] = object_entry.second;
333 std::vector<exprt> result;
334 for(
const auto &object_entry : flat_map.
read())
335 result.push_back(
to_expr(object_entry));
339 for(std::list<exprt>::const_iterator it=value_set.begin();
342 assert(it->type().id()!=
"#REF");
346 for(expr_sett::const_iterator it=value_set.begin(); it!=value_set.end(); it++)
347 std::cout <<
"GET_VALUE_SET: " <<
format(*it) <<
'\n';
368 const std::string &suffix,
369 const typet &original_type,
374 std::cout <<
"GET_VALUE_SET_REC EXPR: " <<
format(expr)
376 std::cout <<
"GET_VALUE_SET_REC SUFFIX: " << suffix <<
'\n';
380 if(expr.
type().
id()==
"#REF#")
382 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
386 for(
const auto &object_entry : fi->second.object_map.read())
404 else if(expr.
id()==ID_unknown || expr.
id()==ID_invalid)
409 else if(expr.
id()==ID_index)
415 "operand 0 of index expression must be an array");
427 else if(expr.
id()==ID_member)
431 if(compound.is_not_nil())
436 type.
id() == ID_struct || type.
id() == ID_union,
437 "operand 0 of member expression must be struct or union");
439 const std::string &component_name =
445 "." + component_name + suffix,
453 else if(expr.
id()==ID_symbol)
458 valuest::const_iterator v_it=
values.find(ident);
465 else if(v_it!=
values.end())
474 else if(expr.
id()==ID_if)
493 else if(expr.
id()==ID_address_of)
499 else if(expr.
id()==ID_dereference)
505 if(object_map.
begin()!=object_map.
end())
507 for(
const auto &object_entry : object_map)
511 original_type, ns, recursion_set);
520 if(expr.
get(ID_value)==ID_NULL &&
521 expr.
type().
id()==ID_pointer)
527 else if(expr.
id()==ID_typecast)
539 else if(expr.
id()==ID_plus || expr.
id()==ID_minus)
542 throw expr.
id_string()+
" expected to have at least two operands";
544 if(expr.
type().
id()==ID_pointer)
547 const exprt *ptr_operand=
nullptr;
550 if(it->type().id()==ID_pointer)
552 if(ptr_operand==
nullptr)
555 throw "more than one pointer operand in pointer arithmetic";
558 if(ptr_operand==
nullptr)
559 throw "pointer type sum expected to have pointer operand";
563 ptr_operand->
type(), ns, recursion_set);
565 for(
const auto &object_entry : pointer_expr_set.
read())
567 offsett offset = object_entry.second;
573 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op0());
577 *offset = (expr.
id() == ID_plus) ? *i : -*i;
581 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op1());
585 *offset = (expr.
id() == ID_plus) ? *i : -*i;
591 insert(dest, object_entry.first, offset);
597 else if(expr.
id()==ID_side_effect)
601 if(statement==ID_function_call)
604 throw "unexpected function_call sideeffect";
606 else if(statement==ID_allocate)
608 if(expr.
type().
id()!=ID_pointer)
609 throw "malloc expected to return pointer type";
613 const typet &dynamic_type=
614 static_cast<const typet &
>(expr.
find(ID_C_cxx_alloc_type));
625 else if(statement==ID_cpp_new ||
626 statement==ID_cpp_new_array)
629 assert(expr.
type().
id()==ID_pointer);
640 else if(expr.
id()==ID_struct)
646 else if(expr.
id()==ID_with)
649 throw "unexpected value in get_value_set: "+expr.
id_string();
651 else if(expr.
id()==ID_array_of ||
658 else if(expr.
id()==ID_dynamic_object)
663 const std::string name=
664 "value_set::dynamic_object"+
669 valuest::const_iterator v_it=
values.find(name);
686 if(src.
id()==ID_typecast)
688 assert(src.
type().
id()==ID_pointer);
704 for(
const auto &object_entry : object_map.
read())
708 if(
object.type().
id() ==
"#REF#")
710 const irep_idt &ident =
object.get(ID_identifier);
711 valuest::const_iterator vit =
values.find(ident);
716 dest.insert(
exprt(ID_unknown,
object.type()));
727 if(t_it->second && object_entry.second)
729 *t_it->second += *object_entry.second;
732 t_it->second.reset();
735 for(
const auto &o : omt.
read())
740 dest.insert(
to_expr(object_entry));
752 for(
const auto &object_entry : object_map.
read())
753 dest.insert(
to_expr(object_entry));
762 std::cout <<
"GET_REFERENCE_SET_REC EXPR: " <<
format(expr)
766 if(expr.
type().
id()==
"#REF#")
768 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
771 for(
const auto &object_entry : fi->second.object_map.read())
779 else if(expr.
id()==ID_symbol ||
780 expr.
id()==ID_dynamic_object ||
781 expr.
id()==ID_string_constant)
783 if(expr.
type().
id()==ID_array &&
791 else if(expr.
id()==ID_dereference)
804 for(
const auto &object_entry : temp.
read())
807 if(obj.
type().
id()==
"#REF#")
810 valuest::const_iterator v_it =
values.find(ident);
821 if(t_it->second && object_entry.second)
823 *t_it->second += *object_entry.second;
826 t_it->second.reset();
829 for(
const auto &t2_object_entry : t2.
read())
830 insert(dest, t2_object_entry);
836 insert(dest, object_entry);
840 for(expr_sett::const_iterator it=value_set.begin();
843 std::cout <<
"VALUE_SET: " <<
format(*it) <<
'\n';
848 else if(expr.
id()==ID_index)
855 array_type.
id() == ID_array,
"index takes array-typed operand");
862 for(
const auto &object_entry : object_map)
866 if(
object.
id()==ID_unknown)
876 if(
object.type().
id() !=
"#REF#" &&
object.type() != array_type)
879 casted_index = index_expr;
881 offsett o = object_entry.second;
882 const auto i = numeric_cast<mp_integer>(offset);
892 insert(dest, casted_index, o);
898 else if(expr.
id()==ID_member)
900 const irep_idt &component_name=expr.
get(ID_component_name);
907 for(
const auto &object_entry : struct_references.
read())
910 const typet &obj_type =
object.type();
912 if(
object.
id()==ID_unknown)
915 object.
id() == ID_dynamic_object && obj_type.
id() != ID_struct &&
916 obj_type.
id() != ID_union && obj_type.
id() != ID_struct_tag &&
917 obj_type.
id() != ID_union_tag)
925 offsett o = object_entry.second;
936 insert(dest, member_expr, o);
942 else if(expr.
id()==ID_if)
958 std::cout <<
"ASSIGN LHS: " <<
format(lhs) <<
'\n';
959 std::cout <<
"ASSIGN RHS: " <<
format(rhs) <<
'\n';
971 if(type.
id()==ID_struct ||
978 for(struct_typet::componentst::const_iterator
983 const typet &subtype=c_it->type();
984 const irep_idt &name = c_it->get_name();
987 if(subtype.
id()==ID_code)
994 if(rhs.
id()==ID_unknown ||
995 rhs.
id()==ID_invalid)
997 rhs_member=
exprt(rhs.
id(), subtype);
1002 throw "value_set_fit::assign type mismatch: "
1006 if(rhs.
id()==ID_struct ||
1007 rhs.
id()==ID_constant)
1012 else if(rhs.
id()==ID_with)
1016 const exprt &member_operand = rhs_with.where();
1019 member_operand.
get(ID_component_name);
1021 if(component_name==name)
1024 rhs_member = rhs_with.new_value();
1029 rhs_member=
exprt(ID_member, subtype);
1031 rhs_member.
set(ID_component_name, name);
1036 rhs_member=
exprt(ID_member, subtype);
1038 rhs_member.
set(ID_component_name, name);
1041 assign(lhs_member, rhs_member, ns);
1045 else if(type.
id()==ID_array)
1050 if(rhs.
id()==ID_unknown ||
1051 rhs.
id()==ID_invalid)
1061 if(rhs.
type() != type)
1062 throw "value_set_fit::assign type mismatch: "
1066 if(rhs.
id()==ID_array_of)
1070 else if(rhs.
id()==ID_array ||
1071 rhs.
id()==ID_constant)
1075 assign(lhs_index, *o_it, ns);
1078 else if(rhs.
id()==ID_with)
1085 assign(lhs_index, op0_index, ns);
1092 assign(lhs_index, rhs_index, ns);
1111 const std::string &suffix,
1116 std::cout <<
"ASSIGN_REC LHS: " <<
format(lhs) <<
'\n';
1117 std::cout <<
"ASSIGN_REC SUFFIX: " << suffix <<
'\n';
1120 it!=values_rhs.
read().
end(); it++)
1121 std::cout <<
"ASSIGN_REC RHS: " <<
to_expr(it) <<
'\n';
1124 if(lhs.
type().
id()==
"#REF#")
1131 if(recursion_set.find(ident)!=recursion_set.end())
1133 recursion_set.insert(ident);
1135 for(
const auto &object_entry : temp.
read())
1139 if(
object.
id() != ID_unknown)
1140 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1143 recursion_set.erase(ident);
1146 else if(lhs.
id()==ID_symbol)
1151 "value_set::dynamic_object") ||
1153 "value_set::return_value") ||
1163 else if(lhs.
id()==ID_dynamic_object)
1168 const std::string name=
1169 "value_set::dynamic_object"+
1175 else if(lhs.
id()==ID_dereference)
1178 throw lhs.
id_string()+
" expected to have one operand";
1183 for(
const auto &object_entry : reference_set.
read())
1187 if(
object.
id()!=ID_unknown)
1188 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1191 else if(lhs.
id()==ID_index)
1197 "operand 0 of index expression must be an array");
1200 to_index_expr(lhs).array(), values_rhs,
"[]" + suffix, ns, recursion_set);
1202 else if(lhs.
id()==ID_member)
1207 const std::string &component_name=lhs.
get_string(ID_component_name);
1212 type.
id() == ID_struct || type.
id() == ID_union,
1213 "operand 0 of member expression must be struct or union");
1218 "." + component_name + suffix,
1222 else if(lhs.
id()==
"valid_object" ||
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) +
"::" +
1276 "argument$"+std::to_string(i);
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())
1299 "argument$"+std::to_string(i), it->type());
1302 assign(actual_lhs, v_expr, ns);
1314 std::string rvs =
"value_set::return_value" + std::to_string(
from_function);
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)
1382 std::string rvs =
"value_set::return_value" + std::to_string(
from_function);
1386 else if(statement==ID_fence)
1389 else if(statement==ID_array_copy ||
1390 statement==ID_array_replace ||
1391 statement==ID_array_set)
1401 "value_set_fit: unexpected statement: "+
id2string(statement);
Expression classes for byte-level operators.
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
bitvector_typet c_index_type()
Operator to return the address of an object.
codet representation of a "return from a function" statement.
const exprt & return_value() const
std::vector< parametert > parameterst
const parameterst & parameters() const
Data structure for representing an arbitrary statement in a program.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Representation of heap-allocated objects.
Base class for all expressions.
std::vector< exprt > operandst
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
bool is_zero() const
Return whether the expression is a constant representing 0.
bool is_constant() const
Return whether the expression is a constant.
typet & type()
Return the type of the expression.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const irept & find(const irep_idt &name) const
const irep_idt & get(const irep_idt &name) const
void set(const irep_idt &name, const irep_idt &value)
const std::string & id_string() const
const irep_idt & id() const
const std::string & get_string(const irep_idt &name) const
Extract member of struct or union.
const exprt & compound() 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...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Split an expression into a base object and a (byte) offset.
const irep_idt & get_statement() const
Base type for structs and unions.
const componentst & components() const
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
typet type
Type of symbol.
irep_idt name
The unique identifier.
const irep_idt & display_name() const
Return language specific display name if present.
The Boolean constant true.
Semantic type conversion.
The type of an expression, extends irept.
const typet & subtype() const
data_typet::value_type value_type
data_typet::const_iterator const_iterator
static const object_map_dt blank
data_typet::iterator iterator
void get_reference_set_sharing(const exprt &expr, expr_sett &expr_set, const namespacet &ns) const
optionalt< mp_integer > offsett
Represents the offset into an object: either a unique integer offset, or an unknown value,...
static object_numberingt object_numbering
std::unordered_set< idt, string_hash > gvs_recursion_sett
void get_reference_set(const exprt &expr, expr_sett &expr_set, const namespacet &ns) const
void assign(const exprt &lhs, const exprt &rhs, const namespacet &ns)
static numberingt< irep_idt > function_numbering
void add_var(const idt &id)
bool make_union(object_mapt &dest, const object_mapt &src) const
std::vector< exprt > get_value_set(const exprt &expr, const namespacet &ns) const
void apply_code(const codet &code, 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)
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
void dereference_rec(const exprt &src, exprt &dest) const
std::unordered_map< idt, entryt, string_hash > valuest
std::unordered_set< idt, string_hash > assign_recursion_sett
void output(const namespacet &ns, std::ostream &out) const
void flatten_rec(const entryt &, object_mapt &, flatten_seent &) const
std::unordered_set< exprt, irep_hash > expr_sett
void do_end_function(const exprt &lhs, const namespacet &ns)
void flatten(const entryt &e, object_mapt &dest) const
bool offset_is_zero(const offsett &offset) const
entryt & get_entry(const idt &id, const std::string &suffix)
unsigned from_target_index
bool insert(object_mapt &dest, const object_map_dt::value_type &it) const
std::unordered_set< idt, string_hash > flatten_seent
exprt to_expr(const object_map_dt::value_type &it) const
void do_function_call(const irep_idt &function, const exprt::operandst &arguments, const namespacet &ns)
void get_reference_set_sharing_rec(const exprt &expr, object_mapt &dest, const namespacet &ns) const
bool has_prefix(const std::string &s, const std::string &prefix)
#define forall_operands(it, expr)
bool can_cast_expr< code_inputt >(const exprt &base)
bool can_cast_expr< code_outputt >(const exprt &base)
const code_returnt & to_code_return(const codet &code)
const std::string & id2string(const irep_idt &d)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
const std::string integer2string(const mp_integer &n, unsigned base)
API to expression classes for Pointers.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
const dynamic_object_exprt & to_dynamic_object_expr(const exprt &expr)
Cast an exprt to a dynamic_object_exprt.
exprt dynamic_object(const exprt &pointer)
bool simplify(exprt &expr, const namespacet &ns)
static optionalt< smt_termt > get_identifier(const exprt &expr, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_handle_identifiers, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_identifiers)
#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)
side_effect_exprt & to_side_effect_expr(exprt &expr)
const code_blockt & to_code_block(const codet &code)
const array_of_exprt & to_array_of_expr(const exprt &expr)
Cast an exprt to an array_of_exprt.
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 binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_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 symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const with_exprt & to_with_expr(const exprt &expr)
Cast an exprt to a with_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
static const char * alloc_adapter_prefix
Value Set (Flow Insensitive, Sharing)