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";
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));
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 it->second.identifier.starts_with(
"value_set::dynamic_object") ||
256 it->second.identifier.starts_with(
"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 DATA_INVARIANT(
object.
id() == ID_symbol,
"reference to symbol required");
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';
361 bool includes_nondet_pointer =
false;
363 tmp, dest, includes_nondet_pointer,
"", tmp.
type(), ns, recset);
369 bool &includes_nondet_pointer,
370 const std::string &suffix,
371 const typet &original_type,
376 std::cout <<
"GET_VALUE_SET_REC EXPR: " <<
format(expr)
378 std::cout <<
"GET_VALUE_SET_REC SUFFIX: " << suffix <<
'\n';
382 if(expr.
type().
id()==
"#REF#")
384 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
388 for(
const auto &object_entry : fi->second.object_map.read())
393 includes_nondet_pointer,
407 else if(expr.
id()==ID_unknown || expr.
id()==ID_invalid)
412 else if(expr.
id()==ID_index)
416 if(type.
id() == ID_array)
421 includes_nondet_pointer,
432 else if(expr.
id()==ID_member)
436 if(compound.is_not_nil())
439 compound.type().id() == ID_struct ||
440 compound.type().id() == ID_struct_tag ||
441 compound.type().id() == ID_union ||
442 compound.type().id() == ID_union_tag,
443 "operand 0 of member expression must be struct or union");
445 const std::string &component_name =
451 includes_nondet_pointer,
452 "." + component_name + suffix,
460 else if(expr.
id()==ID_symbol)
465 valuest::const_iterator v_it=
values.find(ident);
472 else if(v_it!=
values.end())
480 else if(expr.
id()==ID_if)
485 includes_nondet_pointer,
493 includes_nondet_pointer,
501 else if(expr.
id()==ID_address_of)
507 else if(expr.
id()==ID_dereference)
513 if(object_map.
begin()!=object_map.
end())
515 for(
const auto &object_entry : object_map)
521 includes_nondet_pointer,
543 else if(expr.
id()==ID_typecast)
548 includes_nondet_pointer,
556 else if(expr.
id()==ID_plus || expr.
id()==ID_minus)
559 throw expr.
id_string()+
" expected to have at least two operands";
561 if(expr.
type().
id()==ID_pointer)
564 const exprt *ptr_operand=
nullptr;
566 for(
const auto &op : expr.
operands())
568 if(op.type().id() == ID_pointer)
570 if(ptr_operand==
nullptr)
573 throw "more than one pointer operand in pointer arithmetic";
577 if(ptr_operand==
nullptr)
578 throw "pointer type sum expected to have pointer operand";
584 includes_nondet_pointer,
590 for(
const auto &object_entry : pointer_expr_set.
read())
592 offsett offset = object_entry.second;
598 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op0());
602 *offset = (expr.
id() == ID_plus) ? *i : -*i;
606 const auto i = numeric_cast<mp_integer>(
to_binary_expr(expr).op1());
610 *offset = (expr.
id() == ID_plus) ? *i : -*i;
616 insert(dest, object_entry.first, offset);
622 else if(expr.
id()==ID_side_effect)
626 if(statement==ID_function_call)
629 throw "unexpected function_call sideeffect";
631 else if(statement==ID_allocate)
633 if(expr.
type().
id()!=ID_pointer)
634 throw "malloc expected to return pointer type";
638 const typet &dynamic_type=
639 static_cast<const typet &
>(expr.
find(ID_C_cxx_alloc_type));
650 else if(statement==ID_cpp_new ||
651 statement==ID_cpp_new_array)
666 else if(expr.
id()==ID_struct)
672 else if(expr.
id()==ID_with)
675 throw "unexpected value in get_value_set: "+expr.
id_string();
677 else if(expr.
id()==ID_array_of ||
681 for(
const auto &op : expr.
operands())
686 includes_nondet_pointer,
693 else if(expr.
id()==ID_dynamic_object)
698 const std::string name=
699 "value_set::dynamic_object"+
704 valuest::const_iterator v_it=
values.find(name);
721 if(src.
id()==ID_typecast)
739 for(
const auto &object_entry : object_map.
read())
743 if(
object.type().
id() ==
"#REF#")
745 const irep_idt &ident =
object.get(ID_identifier);
746 valuest::const_iterator vit =
values.find(ident);
751 dest.insert(
exprt(ID_unknown,
object.type()));
762 if(t_it->second && object_entry.second)
764 *t_it->second += *object_entry.second;
767 t_it->second.reset();
770 for(
const auto &o : omt.
read())
775 dest.insert(
to_expr(object_entry));
787 for(
const auto &object_entry : object_map.
read())
788 dest.insert(
to_expr(object_entry));
797 std::cout <<
"GET_REFERENCE_SET_REC EXPR: " <<
format(expr)
801 if(expr.
type().
id()==
"#REF#")
803 valuest::const_iterator fi =
values.find(expr.
get(ID_identifier));
806 for(
const auto &object_entry : fi->second.object_map.read())
814 else if(expr.
id()==ID_symbol ||
815 expr.
id()==ID_dynamic_object ||
816 expr.
id()==ID_string_constant)
819 expr.
type().
id() == ID_array &&
829 else if(expr.
id()==ID_dereference)
833 bool includes_nondet_pointer =
false;
837 includes_nondet_pointer,
844 for(
const auto &object_entry : temp.
read())
847 if(obj.
type().
id()==
"#REF#")
850 valuest::const_iterator v_it =
values.find(ident);
861 if(t_it->second && object_entry.second)
863 *t_it->second += *object_entry.second;
866 t_it->second.reset();
869 for(
const auto &t2_object_entry : t2.
read())
870 insert(dest, t2_object_entry);
878 insert(dest, object_entry);
882 for(expr_sett::const_iterator it=value_set.begin();
885 std::cout <<
"VALUE_SET: " <<
format(*it) <<
'\n';
890 else if(expr.
id()==ID_index)
897 array_type.
id() == ID_array,
"index takes array-typed operand");
904 for(
const auto &object_entry : object_map)
908 if(
object.
id()==ID_unknown)
918 if(
object.type().
id() !=
"#REF#" &&
object.type() != array_type)
921 casted_index = index_expr;
923 offsett o = object_entry.second;
924 const auto i = numeric_cast<mp_integer>(offset);
934 insert(dest, casted_index, o);
940 else if(expr.
id()==ID_member)
942 const irep_idt &component_name=expr.
get(ID_component_name);
949 for(
const auto &object_entry : struct_references.
read())
952 const typet &obj_type =
object.type();
954 if(
object.
id()==ID_unknown)
957 obj_type.
id() != ID_struct && obj_type.
id() != ID_union &&
958 obj_type.
id() != ID_struct_tag && obj_type.
id() != ID_union_tag)
966 offsett o = object_entry.second;
971 if(struct_op.
type() !=
object.type())
977 insert(dest, member_expr, o);
983 else if(expr.
id()==ID_if)
999 std::cout <<
"ASSIGN LHS: " <<
format(lhs) <<
'\n';
1000 std::cout <<
"ASSIGN RHS: " <<
format(rhs) <<
'\n';
1011 lhs.
type().
id() == ID_struct || lhs.
type().
id() == ID_struct_tag ||
1012 lhs.
type().
id() == ID_union || lhs.
type().
id() == ID_union_tag)
1014 const auto &components =
1015 (lhs.
type().
id() == ID_struct_tag || lhs.
type().
id() == ID_union_tag)
1021 for(struct_typet::componentst::const_iterator c_it = components.begin();
1022 c_it != components.end();
1025 const typet &subtype=c_it->type();
1026 const irep_idt &name = c_it->get_name();
1030 subtype.
id() != ID_code,
1031 "struct/union member must not be of code type");
1032 if(c_it->get_is_padding())
1039 if(rhs.
id()==ID_unknown ||
1040 rhs.
id()==ID_invalid)
1042 rhs_member=
exprt(rhs.
id(), subtype);
1047 throw "value_set_fit::assign type mismatch: "
1054 no < rhs.
operands().size(),
"component index must be in bounds");
1057 else if(rhs.
id()==ID_with)
1061 const exprt &member_operand = rhs_with.where();
1064 member_operand.
get(ID_component_name);
1066 if(component_name==name)
1069 rhs_member = rhs_with.new_value();
1074 rhs_member=
exprt(ID_member, subtype);
1076 rhs_member.
set(ID_component_name, name);
1081 rhs_member=
exprt(ID_member, subtype);
1083 rhs_member.
set(ID_component_name, name);
1086 assign(lhs_member, rhs_member, ns);
1090 else if(lhs.
type().
id() == ID_array)
1097 if(rhs.
id()==ID_unknown ||
1098 rhs.
id()==ID_invalid)
1112 throw "value_set_fit::assign type mismatch: "
1116 if(rhs.
id()==ID_array_of)
1122 for(
const auto &op : rhs.
operands())
1124 assign(lhs_index, op, ns);
1127 else if(rhs.
id()==ID_with)
1134 assign(lhs_index, op0_index, ns);
1143 assign(lhs_index, rhs_index, ns);
1162 const std::string &suffix,
1167 std::cout <<
"ASSIGN_REC LHS: " <<
format(lhs) <<
'\n';
1168 std::cout <<
"ASSIGN_REC SUFFIX: " << suffix <<
'\n';
1171 it!=values_rhs.
read().
end(); it++)
1172 std::cout <<
"ASSIGN_REC RHS: " <<
to_expr(it) <<
'\n';
1175 if(lhs.
type().
id()==
"#REF#")
1180 bool includes_nondet_pointer =
false;
1184 includes_nondet_pointer,
1190 if(recursion_set.find(ident)!=recursion_set.end())
1192 recursion_set.insert(ident);
1194 for(
const auto &object_entry : temp.
read())
1198 if(
object.
id() != ID_unknown)
1199 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1202 recursion_set.erase(ident);
1205 else if(lhs.
id()==ID_symbol)
1210 identifier.
starts_with(
"value_set::dynamic_object") ||
1211 identifier.
starts_with(
"value_set::return_value") ||
1221 else if(lhs.
id()==ID_dynamic_object)
1226 const std::string name=
1227 "value_set::dynamic_object"+
1233 else if(lhs.
id()==ID_dereference)
1236 throw lhs.
id_string()+
" expected to have one operand";
1241 for(
const auto &object_entry : reference_set.
read())
1245 if(
object.
id()!=ID_unknown)
1246 assign_rec(
object, values_rhs, suffix, ns, recursion_set);
1249 else if(lhs.
id()==ID_index)
1253 if(type.
id() == ID_array)
1263 else if(lhs.
id()==ID_member)
1268 const std::string &component_name=lhs.
get_string(ID_component_name);
1272 compound.
type().
id() == ID_struct ||
1273 compound.
type().
id() == ID_struct_tag ||
1274 compound.
type().
id() == ID_union ||
1275 compound.
type().
id() == ID_union_tag,
1276 "operand 0 of member expression must be struct or union");
1279 compound, values_rhs,
"." + component_name + suffix, ns, recursion_set);
1281 else if(lhs.
id()==
"valid_object" ||
1282 lhs.
id()==
"dynamic_type")
1286 else if(lhs.
id()==ID_string_constant)
1291 else if(lhs.
id() == ID_null_object)
1295 else if(lhs.
id()==ID_typecast)
1299 assign_rec(typecast_expr.
op(), values_rhs, suffix, ns, recursion_set);
1302 lhs.
id() ==
"zero_string" || lhs.
id() ==
"is_zero_string" ||
1303 lhs.
id() ==
"zero_string_length" || lhs.
id() == ID_address_of)
1307 else if(lhs.
id()==ID_byte_extract_little_endian ||
1308 lhs.
id()==ID_byte_extract_big_endian)
1314 throw "assign NYI: '" + lhs.
id_string() +
"'";
1332 for(std::size_t i=0; i<arguments.size(); i++)
1334 const std::string identifier=
"value_set::" +
id2string(
function) +
"::" +
1337 const symbol_exprt dummy_lhs(identifier, arguments[i].type());
1338 assign(dummy_lhs, arguments[i], ns);
1345 for(code_typet::parameterst::const_iterator
1346 it=parameter_types.begin();
1347 it!=parameter_types.end();
1350 const irep_idt &identifier=it->get_identifier();
1351 if(identifier.
empty())
1361 assign(actual_lhs, v_expr, ns);
1383 if(statement==ID_block)
1388 else if(statement==ID_function_call)
1393 else if(statement==ID_assign)
1396 throw "assignment expected to have two operands";
1400 else if(statement==ID_decl)
1403 throw "decl expected to have one operand";
1407 if(lhs.
id()!=ID_symbol)
1408 throw "decl expected to have symbol on lhs";
1412 else if(statement==ID_expression)
1416 else if(statement==ID_cpp_delete ||
1417 statement==ID_cpp_delete_array)
1421 else if(statement==
"lock" || statement==
"unlock")
1425 else if(statement==ID_asm)
1429 else if(statement==ID_nondet)
1433 else if(statement==ID_printf)
1437 else if(statement==ID_return)
1445 else if(statement==ID_fence)
1449 statement == ID_array_copy || statement == ID_array_replace ||
1450 statement == ID_array_set || statement == ID_array_equal)
1457 else if(statement == ID_havoc_object)
1463 "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.
const typet & element_type() const
The type of the elements of the array.
goto_instruction_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.
bool starts_with(const char *s) const
equivalent of as_string().starts_with(s)
Representation of heap-allocated objects.
unsigned int get_instance() const
void set_instance(unsigned int instance)
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.
typet & type()
Return the type of the expression.
bool is_constant() const
Return whether the expression is a constant.
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
const std::string & id_string() const
void set(const irep_idt &name, const irep_idt &value)
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 union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
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 typet & base_type() const
The type of the data what we point to.
const irep_idt & get_statement() const
const componentst & components() const
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
const irep_idt & display_name() const
Return language specific display name if present.
typet type
Type of symbol.
irep_idt name
The unique identifier.
The Boolean constant true.
Type with a single subtype.
const typet & subtype() const
Semantic type conversion.
The type of an expression, extends irept.
data_typet::value_type value_type
data_typet::const_iterator const_iterator
static const object_map_dt blank
data_typet::iterator iterator
std::optional< mp_integer > offsett
Represents the offset into an object: either a unique integer offset, or an unknown value,...
void get_reference_set_sharing(const exprt &expr, expr_sett &expr_set, const namespacet &ns) const
static object_numberingt object_numbering
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)
std::unordered_set< idt > assign_recursion_sett
entryt & get_entry(const idt &id, const std::string &suffix)
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 get_value_set_rec(const exprt &expr, object_mapt &dest, bool &includes_nondet_pointer, const std::string &suffix, const typet &original_type, const namespacet &ns, gvs_recursion_sett &recursion_set) const
void assign_rec(const exprt &lhs, const object_mapt &values_rhs, const std::string &suffix, const namespacet &ns, assign_recursion_sett &recursion_set)
void dereference_rec(const exprt &src, exprt &dest) const
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)
std::set< idt > flatten_seent
void flatten(const entryt &e, object_mapt &dest) const
bool offset_is_zero(const offsett &offset) const
unsigned from_target_index
bool insert(object_mapt &dest, const object_map_dt::value_type &it) const
std::unordered_set< idt > gvs_recursion_sett
std::map< idt, entryt > valuest
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 is_null_pointer(const constant_exprt &expr)
Returns true if expr has a pointer type and a value NULL; it also returns true when expr has value ze...
const code_returnt & to_code_return(const goto_instruction_codet &code)
bool can_cast_expr< code_inputt >(const exprt &base)
bool can_cast_expr< code_outputt >(const exprt &base)
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 dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const dynamic_object_exprt & to_dynamic_object_expr(const exprt &expr)
Cast an exprt to a dynamic_object_exprt.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
bool simplify(exprt &expr, const namespacet &ns)
#define CHECK_RETURN(CONDITION)
#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 if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const with_exprt & to_with_expr(const exprt &expr)
Cast an exprt to a with_exprt.
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
const array_of_exprt & to_array_of_expr(const exprt &expr)
Cast an exprt to an array_of_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
const struct_or_union_tag_typet & to_struct_or_union_tag_type(const typet &type)
Cast a typet to a struct_or_union_tag_typet.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
const type_with_subtypet & to_type_with_subtype(const typet &type)
static const char * alloc_adapter_prefix
Value Set (Flow Insensitive, Sharing)