35 #define forall_objects(it, map) \ 36 for(object_map_dt::const_iterator it = (map).begin(); \ 40 #define forall_valid_objects(it, map) \ 41 for(object_map_dt::const_iterator it = (map).begin(); \ 44 if((map).is_valid_at((it)->first, from_function, from_target_index)) 46 #define Forall_objects(it, map) \ 47 for(object_map_dt::iterator it = (map).begin(); \ 51 #define Forall_valid_objects(it, map) \ 52 for(object_map_dt::iterator it = (map).begin(); \ 55 if((map).is_valid_at((it)->first, from_function, from_target_index)) 59 std::ostream &out)
const 61 for(valuest::const_iterator
71 std::ostream &out)
const 89 identifier=symbol.
name;
97 out << display_name <<
" = { ";
107 std::string result=
"<";
109 if(o.
id()==ID_invalid)
113 if(o.
type().
id()==ID_unknown)
115 else if(o.
type().
id()==ID_invalid)
121 else if(o.
id()==ID_unknown)
125 if(o.
type().
id()==ID_unknown)
127 else if(o.
type().
id()==ID_invalid)
135 result+=
from_expr(ns, identifier, o)+
", ";
144 if(o.
type().
id()==ID_unknown)
155 out << result <<
'\n';
158 object_map_dt::validity_rangest::const_iterator vr =
163 if(vr->second.empty())
164 std::cout <<
" Empty validity record\n";
167 for(object_map_dt::vrange_listt::const_iterator vit =
169 vit!=vr->second.end();
173 " [" << vit->from <<
"," << vit->to <<
"]";
176 from_target_index<=vit->to)
184 out <<
" No validity information\n";
188 width+=result.size();
193 if(next!=object_map.
read().
end())
206 if(
object.
id()==ID_invalid ||
207 object.
id()==ID_unknown)
219 return std::move(od);
258 dest.
write()[it->first] = it->second;
268 std::list<exprt> &value_set,
275 value_set.push_back(
to_expr(it));
278 for(std::list<exprt>::const_iterator it=value_set.begin();
279 it!=value_set.end(); it++)
280 std::cout <<
"GET_VALUE_SET: " <<
format(*it) <<
'\n';
298 const std::string &suffix,
299 const typet &original_type,
303 std::cout <<
"GET_VALUE_SET_REC EXPR: " << expr <<
'\n';
304 std::cout <<
"GET_VALUE_SET_REC SUFFIX: " << suffix <<
'\n';
308 if(expr.id()==ID_unknown || expr.id()==ID_invalid)
313 else if(expr.id()==ID_index)
315 assert(expr.operands().size()==2);
320 type.id()==ID_incomplete_array,
321 "operand 0 of index expression must be an array");
327 else if(expr.id()==ID_member)
329 assert(expr.operands().size()==1);
331 if(expr.op0().is_not_nil())
336 type.
id()==ID_union ||
337 type.
id()==ID_incomplete_struct ||
338 type.
id()==ID_incomplete_union,
339 "operand 0 of member expression must be struct or union");
341 const std::string &component_name=
342 expr.get_string(ID_component_name);
350 else if(expr.id()==ID_symbol)
363 valuest::const_iterator v_it=
values.find(ident);
372 else if(expr.id()==ID_if)
374 if(expr.operands().size()!=3)
375 throw "if takes three operands";
384 else if(expr.id()==ID_address_of)
386 if(expr.operands().size()!=1)
387 throw expr.id_string()+
" expected to have one operand";
393 else if(expr.id()==ID_dereference)
399 if(object_map.
begin()!=object_map.
end())
411 else if(expr.id()==
"reference_to")
419 if(object_map.
begin()!=object_map.
end())
431 else if(expr.is_constant())
434 if(expr.get(ID_value)==ID_NULL &&
435 expr.type().id()==ID_pointer)
441 else if(expr.id()==ID_typecast)
443 if(expr.operands().size()!=1)
444 throw "typecast takes one operand";
451 else if(expr.id()==ID_plus || expr.id()==ID_minus)
453 if(expr.operands().size()<2)
454 throw expr.id_string()+
" expected to have at least two operands";
456 if(expr.type().id()==ID_pointer)
459 const exprt *ptr_operand=
nullptr;
462 if(it->type().id()==ID_pointer)
464 if(ptr_operand==
nullptr)
467 throw "more than one pointer operand in pointer arithmetic";
470 if(ptr_operand==
nullptr)
471 throw "pointer type sum expected to have pointer operand";
475 ptr_operand->
type(), ns);
483 if(expr.op0().type().id()!=ID_pointer)
489 *offset = (expr.id() == ID_plus) ? i : -i;
497 *offset = (expr.id() == ID_plus) ? i : -i;
509 else if(expr.id()==ID_side_effect)
511 const irep_idt &statement=expr.get(ID_statement);
513 if(statement==ID_function_call)
516 throw "unexpected function_call sideeffect";
518 else if(statement==ID_allocate)
520 if(expr.type().id()!=ID_pointer)
521 throw "malloc expected to return pointer type";
525 const typet &dynamic_type=
526 static_cast<const typet &
>(expr.find(ID_C_cxx_alloc_type));
537 else if(statement==ID_cpp_new ||
538 statement==ID_cpp_new_array)
541 assert(expr.type().id()==ID_pointer);
553 else if(expr.id()==ID_struct)
559 else if(expr.id()==ID_with ||
560 expr.id()==ID_array_of ||
564 throw "unexpected value in get_value_set: "+expr.id_string();
566 else if(expr.id()==ID_dynamic_object)
571 const std::string name=
572 "value_set::dynamic_object"+
577 valuest::const_iterator v_it=
values.find(name);
594 if(src.
id()==ID_typecast)
596 assert(src.
type().
id()==ID_pointer);
599 throw "typecast expects one operand";
625 std::cout <<
"GET_REFERENCE_SET_REC EXPR: " <<
format(expr) <<
'\n';
628 if(expr.
id()==ID_symbol ||
629 expr.
id()==ID_dynamic_object ||
630 expr.
id()==ID_string_constant)
632 if(expr.
type().
id()==ID_array &&
640 else if(expr.
id()==ID_dereference)
643 throw expr.
id_string()+
" expected to have one operand";
648 for(expr_sett::const_iterator it=value_set.begin();
649 it!=value_set.end(); it++)
650 std::cout <<
"VALUE_SET: " <<
format(*it) <<
'\n';
655 else if(expr.
id()==ID_index)
658 throw "index expected to have two operands";
664 assert(array_type.
id()==ID_array ||
665 array_type.
id()==ID_incomplete_array);
677 if(
object.
id()==ID_unknown)
685 if(ns.
follow(
object.type())!=array_type)
705 else if(expr.
id()==ID_member)
707 const irep_idt &component_name=expr.
get(ID_component_name);
710 throw "member expected to have one operand";
724 if(
object.
id()==ID_unknown)
726 else if(
object.
id()==ID_dynamic_object &&
727 obj_type.
id()!=ID_struct &&
728 obj_type.
id()!=ID_union)
750 else if(expr.
id()==ID_if)
753 throw "if takes three operands";
770 std::cout <<
"ASSIGN LHS: " << lhs <<
'\n';
771 std::cout <<
"ASSIGN LTYPE: " <<
format(ns.
follow(lhs.type())) <<
'\n';
772 std::cout <<
"ASSIGN RHS: " <<
format(rhs) <<
'\n';
778 throw "if takes three operands";
787 if(type.
id()==ID_struct ||
794 for(struct_typet::componentst::const_iterator
799 const typet &subtype=c_it->type();
800 const irep_idt &name = c_it->get_name();
803 if(subtype.
id()==ID_code)
810 if(rhs.
id()==ID_unknown ||
811 rhs.
id()==ID_invalid)
813 rhs_member=
exprt(rhs.
id(), subtype);
819 "type mismatch:\nRHS: "+rhs.
type().
pretty()+
"\n"+
822 if(rhs.
id()==ID_struct ||
823 rhs.
id()==ID_constant)
828 else if(rhs.
id()==ID_with)
833 const exprt &member_operand=rhs.
op1();
836 member_operand.get(ID_component_name);
838 if(component_name==name)
841 rhs_member=rhs.
op2();
846 rhs_member=
exprt(ID_member, subtype);
848 rhs_member.
set(ID_component_name, name);
853 rhs_member=
exprt(ID_member, subtype);
855 rhs_member.
set(ID_component_name, name);
858 assign(lhs_member, rhs_member, ns, add_to_sets);
862 else if(type.
id()==ID_array)
867 if(rhs.
id()==ID_unknown ||
868 rhs.
id()==ID_invalid)
876 if(rhs.
id()==ID_array_of)
880 assign(lhs_index, rhs.
op0(), ns, add_to_sets);
882 else if(rhs.
id()==ID_array ||
883 rhs.
id()==ID_constant)
887 assign(lhs_index, *o_it, ns, add_to_sets);
890 else if(rhs.
id()==ID_with)
897 assign(lhs_index, op0_index, ns, add_to_sets);
904 assign(lhs_index, rhs_index, ns,
true);
915 assign_rec(lhs, values_rhs,
"", ns, add_to_sets);
922 const std::string &suffix,
927 std::cout <<
"ASSIGN_REC LHS: " << lhs <<
'\n';
928 std::cout <<
"ASSIGN_REC SUFFIX: " << suffix <<
'\n';
931 it!=values_rhs.
read().
end(); it++)
932 std::cout <<
"ASSIGN_REC RHS: " <<
to_expr(it) <<
'\n';
935 if(lhs.id()==ID_symbol)
940 "value_set::dynamic_object") ||
942 "value_set::return_value") ||
957 else if(lhs.id()==ID_dynamic_object)
962 const std::string name=
963 "value_set::dynamic_object"+
974 make_union(temp_entry.object_map, values_rhs);
976 else if(lhs.id()==ID_dereference)
978 if(lhs.operands().size()!=1)
979 throw lhs.id_string()+
" expected to have one operand";
988 if(
object.
id()!=ID_unknown)
989 assign_rec(
object, values_rhs, suffix, ns, add_to_sets);
992 else if(lhs.id()==ID_index)
994 if(lhs.operands().size()!=2)
995 throw "index expected to have two operands";
1000 "operand 0 of index expression must be an array");
1002 assign_rec(lhs.op0(), values_rhs,
"[]"+suffix, ns, add_to_sets);
1004 else if(lhs.id()==ID_member)
1006 if(lhs.operands().size()!=1)
1007 throw "member expected to have one operand";
1009 if(lhs.op0().is_nil())
1012 const std::string &component_name=lhs.get_string(ID_component_name);
1017 type.
id()==ID_union ||
1018 type.
id()==ID_incomplete_struct ||
1019 type.
id()==ID_incomplete_union,
1020 "operand 0 of member expression must be struct or union");
1022 assign_rec(lhs.op0(), values_rhs,
"."+component_name+suffix,
1025 else if(lhs.id()==
"valid_object" ||
1026 lhs.id()==
"dynamic_size" ||
1027 lhs.id()==
"dynamic_type")
1031 else if(lhs.id()==ID_string_constant)
1036 else if(lhs.id() == ID_null_object)
1040 else if(lhs.id()==ID_typecast)
1047 else if(lhs.id()==
"zero_string" ||
1048 lhs.id()==
"is_zero_string" ||
1049 lhs.id()==
"zero_string_length")
1053 else if(lhs.id()==ID_byte_extract_little_endian ||
1054 lhs.id()==ID_byte_extract_big_endian)
1056 assert(lhs.operands().size()==2);
1057 assign_rec(lhs.op0(), values_rhs, suffix, ns,
true);
1060 throw "assign NYI: `"+lhs.id_string()+
"'";
1085 for(std::size_t i=0; i<arguments.size(); i++)
1087 const std::string identifier=
"value_set::" +
id2string(
function) +
"::" +
1090 const symbol_exprt dummy_lhs(identifier, arguments[i].type());
1092 assign(dummy_lhs, arguments[i], ns,
true);
1108 for(code_typet::parameterst::const_iterator
1109 it=parameter_types.begin();
1110 it!=parameter_types.end();
1113 const irep_idt &identifier=it->get_identifier();
1124 assign(actual_lhs, v_expr, ns,
true);
1136 irep_idt rvs = std::string(
"value_set::return_value") +
1150 if(statement==ID_block)
1155 else if(statement==ID_function_call)
1160 else if(statement==ID_assign)
1163 throw "assignment expected to have two operands";
1167 else if(statement==ID_decl)
1170 throw "decl expected to have one operand";
1174 if(lhs.
id()!=ID_symbol)
1175 throw "decl expected to have symbol on lhs";
1179 else if(statement==ID_expression)
1183 else if(statement==ID_cpp_delete ||
1184 statement==ID_cpp_delete_array)
1188 else if(statement==
"lock" || statement==
"unlock")
1192 else if(statement==ID_asm)
1196 else if(statement==ID_nondet)
1200 else if(statement==ID_printf)
1204 else if(statement==ID_return)
1209 irep_idt rvs = std::string(
"value_set::return_value") +
1216 else if(statement==ID_input || statement==ID_output)
1224 "value_set_fivrnst: unexpected statement: "+
id2string(statement);
1249 if(old_offset && offset)
1251 if(*old_offset == *offset)
1259 else if(!old_offset)
1290 if(old_offset && offset)
1292 if(*old_offset == *offset)
1300 else if(!old_offset)
1319 vrange_listt::iterator it=ranges.begin();
1321 while(it->function!=f && it!=ranges.end()) it++;
1324 it!=ranges.end() && it->function==f && it->from <= line;
1329 if( line == it->to+1)
1334 vrange_listt::iterator n_it = it; n_it++;
1335 if(n_it!=ranges.end() &&
1336 it->function == n_it->function &&
1337 it->to+1 == n_it->from)
1339 n_it->from = it->from;
1340 it = ranges.erase(it);
1350 if(it!=ranges.end())
1354 if( line == it->from - 1)
1359 if(it!=ranges.begin())
1361 vrange_listt::iterator p_it = it; p_it--;
1362 if(p_it->function == it->function &&
1363 p_it->to+1 == it->from)
1366 it = ranges.erase(it);
1376 ranges.insert(it, insr);
1384 unsigned line)
const 1387 std::cout <<
"IS_VALID_AT: " << inx <<
", " << f <<
", line " << line <<
1391 validity_rangest::const_iterator vrs = validity_ranges.find(inx);
1392 if(vrs!=validity_ranges.end())
1396 object_map_dt::vrange_listt::const_iterator it = ranges.begin();
1398 while(it->function!=f &&
1403 it!=ranges.end() && it->function==f && it->from<=line;
1405 if(it->contains(f, line))
1416 for(valuest::iterator it=
values.begin();
1440 if(
make_union(state_map, t_it->second.object_map))
The type of an expression, extends irept.
irep_idt name
The unique identifier.
Semantic type conversion.
const std::string & id2string(const irep_idt &d)
void do_function_call(const irep_idt &function, const exprt::operandst &arguments, const namespacet &ns)
const std::string integer2string(const mp_integer &n, unsigned base)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
static object_numberingt object_numbering
const dynamic_object_exprt & to_dynamic_object_expr(const exprt &expr)
Cast an exprt to a dynamic_object_exprt.
void output(const namespacet &ns, std::ostream &out) const
bool base_type_eq(const typet &type1, const typet &type2, const namespacet &ns)
Check types for equality across all levels of hierarchy.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
bool insert_from(object_mapt &dest, object_map_dt::const_iterator it) const
bool set_valid_at(unsigned inx, unsigned f, unsigned line)
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
const irep_idt & get_identifier() const
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
std::vector< parametert > parameterst
void apply_code(const exprt &code, const namespacet &ns)
const_iterator find(object_numberingt::number_type k)
const componentst & components() const
void copy_objects(object_mapt &dest, const object_mapt &src) const
static const object_map_dt blank
optionalt< mp_integer > offsett
Represents the offset into an object: either a unique integer offset, or an unknown value...
void dereference_rec(const exprt &src, exprt &dest) const
typet & type()
Return the type of the expression.
static const char * alloc_adapter_prefix
Structure type, corresponds to C style structs.
Extract member of struct or union.
bool make_union(object_mapt &dest, const object_mapt &src) const
bool offset_is_zero(offsett offset) const
bool insert_to(object_mapt &dest, object_map_dt::const_iterator it) const
void get_value_set_rec(const exprt &expr, object_mapt &dest, const std::string &suffix, const typet &original_type, const namespacet &ns) const
const irep_idt & id() const
void output_entry(const entryt &e, const namespacet &ns, std::ostream &out) const
The Boolean constant true.
#define forall_valid_objects(it, map)
void do_end_function(const exprt &lhs, const namespacet &ns)
entryt & get_entry(const idt &id, const std::string &suffix)
API to expression classes.
const irep_idt & get(const irep_namet &name) const
void assign(const exprt &lhs, const exprt &rhs, const namespacet &ns, bool add_to_sets=false)
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool has_prefix(const std::string &s, const std::string &prefix)
Split an expression into a base object and a (byte) offset.
Value Set (Flow Insensitive, Validity Regions)
#define forall_operands(it, expr)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
exprt to_expr(object_map_dt::const_iterator it) const
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
bitvector_typet index_type()
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
typename Map::mapped_type number_type
objmapt::const_iterator const_iterator
validity_rangest validity_ranges
Operator to return the address of an object.
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
#define forall_objects(it, map)
void add_var(const idt &id, const std::string &suffix)
std::vector< exprt > operandst
std::list< validity_ranget > vrange_listt
const irep_idt & display_name() const
Return language specific display name if present.
typet type
Type of symbol.
void get_reference_set_rec(const exprt &expr, object_mapt &dest, const namespacet &ns) const
static hash_numbering< irep_idt, irep_id_hash > function_numbering
std::unordered_set< exprt, irep_hash > expr_sett
void assign_rec(const exprt &lhs, const object_mapt &values_rhs, const std::string &suffix, const namespacet &ns, bool add_to_sets)
Base class for all expressions.
const parameterst & parameters() const
bool is_valid_at(unsigned inx, unsigned f, unsigned line) const
#define UNREACHABLE
This should be used to mark dead code.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
void get_reference_set(const exprt &expr, expr_sett &expr_set, const namespacet &ns) const
const std::string & id_string() const
bool make_valid_union(object_mapt &dest, const object_mapt &src) const
bool is_zero() const
Return whether the expression is a constant representing 0.
Expression to hold a symbol (variable)
exprt dynamic_object(const exprt &pointer)
void get_value_set(const exprt &expr, std::list< exprt > &expr_set, const namespacet &ns) const
const typet & subtype() const
entryt & get_temporary_entry(const idt &id, const std::string &suffix)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions, goto_programs, exprts, etc.
Representation of heap-allocated objects.
void make_typecast(const typet &_type)
Create a typecast_exprt to the given type.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
unsigned from_target_index
void set(const irep_namet &name, const irep_idt &value)
#define Forall_valid_objects(it, map)
bool simplify(exprt &expr, const namespacet &ns)