29 exprt &dest,
bool write)
32 if(
build(
object, dest, write))
45 !(dest.
type().
id()==ID_array && a_t.
id()==ID_pointer &&
48 warning() <<
"warning: inconsistent abstract type for " 49 <<
object.pretty() <<
eom;
58 return type.
id()==ID_pointer &&
64 return type.
id()==ID_pointer;
89 arg_suffix(
"#strarg"),
90 sym_suffix(
"#str$fcn"),
91 symbol_table(_symbol_table),
134 abstract(it->second.body);
139 goto_functionst::function_mapt::iterator
169 symbolt &fct_symbol=sym_entry->second;
175 for(code_typet::parameterst::iterator
176 it=parameters.begin();
177 it!=parameters.end();
181 if(abstract_type.
is_nil())
184 const irep_idt &identifier=it->get_identifier();
195 parameters.insert(parameters.end(), str_args.begin(), str_args.end());
198 symb_parameters.insert(
199 symb_parameters.end(), str_args.begin(), str_args.end());
213 str_args.back().add_source_location()=fct_symbol.
location;
214 str_args.back().set_base_name(base_name);
215 str_args.back().set_identifier(identifier);
218 new_symbol.
type=final_type;
220 new_symbol.
location=str_args.back().source_location();
221 new_symbol.
name=str_args.back().get_identifier();
223 new_symbol.
base_name=str_args.back().get_base_name();
225 new_symbol.
pretty_name=str_args.back().get_base_name();
235 it=
abstract(dest, it);
247 typedef std::unordered_map<irep_idt, goto_programt::targett, irep_id_hash>
249 available_declst available_decls;
255 available_decls.insert(std::make_pair(
259 for(
const auto &l :
locals)
264 available_declst::const_iterator entry=available_decls.find(l.first);
266 if(available_declst::const_iterator(available_decls.end())!=entry)
268 ref_instr=entry->second;
291 decl1->source_location=ref_instr->source_location;
292 decl1->function=ref_instr->function;
294 decl1->code.add_source_location()=ref_instr->source_location;
308 assignment1->make_assignment();
309 assignment1->source_location=ref_instr->source_location;
310 assignment1->function=ref_instr->function;
312 assignment1->code.add_source_location()=ref_instr->source_location;
322 if(eff_type.
id()==ID_array || eff_type.
id()==ID_pointer)
327 dest, ref_instr, symbol,
irep_idt(),
328 eff_type.
subtype(), source_subt);
330 if(eff_type.
id()==ID_array)
335 else if(eff_type.
id()==ID_union ||
346 struct_union_typet::componentst::const_iterator it2=components.begin();
347 for(struct_union_typet::componentst::const_iterator
348 it=s_components.begin();
349 it!=s_components.end() && it2!=components.end();
352 if(it->get_name()!=it2->get_name())
356 if(eff_sub_type.
id()==ID_pointer ||
357 eff_sub_type.
id()==ID_array ||
358 eff_sub_type.
id()==ID_struct ||
359 eff_sub_type.
id()==ID_union)
362 dest, ref_instr, symbol, it2->get_name(),
368 assignment1->make_assignment();
369 assignment1->source_location=ref_instr->source_location;
370 assignment1->function=ref_instr->function;
372 assignment1->code.add_source_location()=ref_instr->source_location;
379 assert(components.size()==seen);
391 const typet &source_type)
393 std::string suffix=
"$strdummy";
394 if(!component_name.
empty())
395 suffix=
"#"+
id2string(component_name)+suffix;
400 new_symbol.
type=type;
402 new_symbol.
location=ref_instr->source_location;
403 new_symbol.
name=dummy_identifier;
415 decl->source_location=ref_instr->source_location;
416 decl->function=ref_instr->function;
418 decl->code.add_source_location()=ref_instr->source_location;
439 assignment1->make_assignment();
440 assignment1->source_location=ref_instr->source_location;
441 assignment1->function=ref_instr->function;
443 assignment1->code.add_source_location()=ref_instr->source_location;
517 if(type.
id()==ID_pointer || type.
id()==ID_array)
537 code_function_callt::argumentst::const_iterator it1=arguments.begin();
538 for(code_typet::parameterst::const_iterator it2=formal_params.begin();
539 it2!=formal_params.end();
543 if(abstract_type.
is_nil())
546 if(it1==arguments.end())
548 error() <<
"function call: not enough arguments" <<
eom;
552 str_args.push_back(
exprt());
558 if(str_args.back().type().id()==ID_array &&
559 abstract_type.
id()==ID_pointer)
561 assert(
type_eq(str_args.back().type().subtype(),
566 idx.
set(
"bounds_check",
false);
575 arguments.insert(arguments.end(), str_args.begin(), str_args.end());
580 if(expr.
id()==
"is_zero_string" ||
581 expr.
id()==
"zero_string_length" ||
582 expr.
id()==
"buffer_size")
597 if(expr.
id()==
"is_zero_string")
603 else if(expr.
id()==
"zero_string_length")
609 else if(expr.
id()==
"buffer_size")
621 const exprt &pointer,
627 if(pointer.
id()==ID_typecast)
630 assert(pointer.
operands().size()==1);
631 if(pointer.
op0().
type().
id()!=ID_pointer)
635 return build(pointer.
op0(), what, write, source_location);
657 abstraction_types_mapt::const_iterator map_entry=
660 return map_entry->second;
667 map_entry=tmp.find(eff_type);
668 assert(map_entry!=tmp.end());
670 std::make_pair(eff_type, map_entry->second)).first->second;
677 abstraction_types_mapt::const_iterator known_entry=known.
find(eff_type);
678 if(known_entry!=known.end())
679 return known_entry->second;
681 ::std::pair< abstraction_types_mapt::iterator, bool > map_entry(
684 if(!map_entry.second)
685 return map_entry.first->second;
687 if(eff_type.
id()==ID_array || eff_type.
id()==ID_pointer)
698 if(eff_type.
id()==ID_array)
699 map_entry.first->second=
706 else if(eff_type.
id()==ID_struct || eff_type.
id()==ID_union)
711 for(
const auto &comp : struct_union_type.
components())
713 if(comp.get_anonymous())
721 new_comp.back().set_name(comp.get_name());
722 new_comp.back().set_pretty_name(comp.get_pretty_name());
723 new_comp.back().type()=subt;
725 if(!new_comp.empty())
729 map_entry.first->second=t;
733 return map_entry.first->second;
739 if(abstract_type.
is_nil())
742 if(
object.
id()==ID_typecast)
748 (dest.
type().
id()==ID_array &&
749 abstract_type.
id()==ID_pointer &&
753 if(
object.
id()==ID_string_constant)
755 mp_integer str_len=strlen(
object.
get(ID_value).c_str());
759 if(
object.
id()==ID_array &&
is_char_type(
object.type().subtype()))
763 if(
object.is_constant())
766 if(
object.
id()==ID_symbol)
769 if(
object.
id()==ID_if)
772 if(
object.
id()==ID_member)
779 if(
object.
id()==ID_dereference)
786 if(
object.
id()==ID_index)
794 if(
object.type().id()==ID_pointer)
801 exprt &dest,
bool write)
808 if(op1_err && op2_err)
813 new_if.type()=new_if.false_case().type();
818 new_if.
type()=new_if.true_case().type();
822 new_if.
type()=new_if.true_case().type();
829 exprt &dest,
bool write)
842 assert(size==
object.operands().size());
844 exprt::operandst::const_iterator it=
object.operands().begin();
853 exprt &dest,
bool write)
855 assert(
object.type().
id()==ID_pointer);
889 return exprt(
"NULL-object", type);
911 return exprt(
"NULL-object", type);
919 locals[identifier]=identifier;
922 new_symbol.
type=type;
924 new_symbol.
name=identifier;
927 new_symbol.
mode=ID_C;
932 return ns.
lookup(identifier).symbol_expr();
940 assert(!abstract_type.
is_nil());
969 new_symbol.
type=type;
972 new_symbol.
name=identifier;
987 dummy_loc->source_location=symbol.
location;
1008 new_symbol.
name=identifier;
1010 new_symbol.
mode=ID_C;
1026 assignment1->make_assignment();
1040 if(lhs.
id()==ID_minus)
1060 while(rhsp->
id()==ID_typecast)
1061 rhsp=&(rhsp->
op0());
1064 if(abstract_type.
is_nil())
1067 exprt new_lhs, new_rhs;
1076 if(lhs.
type().
id()==ID_pointer && !unknown)
1078 goto_programt::instructiont assignment;
1079 assignment.make_assignment();
1080 assignment.source_location=target->source_location;
1081 assignment.function=target->function;
1083 assignment.code.add_source_location()=target->source_location;
1104 while(rhsp->
id()==ID_typecast)
1105 rhsp=&(rhsp->
op0());
1112 if(lhs.
id()==ID_index)
1128 return char_assign(dest, target, new_lhs, i2, min_expr);
1131 else if(lhs.
id()==ID_dereference)
1159 const exprt &new_lhs,
1169 assignment1->make_assignment();
1170 assignment1->source_location=target->source_location;
1171 assignment1->function=target->function;
1173 assignment1->code.add_source_location()=target->source_location;
1176 assignment2->make_assignment();
1177 assignment2->source_location=target->source_location;
1178 assignment2->function=target->function;
1180 assignment2->code.add_source_location()=target->source_location;
1183 assignment2->code.op0(),
1184 assignment2->code.op1());
1204 if(lhs.
type().
id()==ID_array)
1216 else if(lhs.
type().
id()==ID_pointer)
1222 else if(lhs.
type().
id()==ID_struct || lhs.
type().
id()==ID_union)
1227 for(
const auto &comp : struct_union_type.
components())
1229 assert(!comp.get_name().empty());
1252 goto_else->function=target->function;
1253 goto_else->source_location=target->source_location;
1254 goto_else->make_goto(else_target, rhs.
cond());
1255 goto_else->guard.make_not();
1257 goto_out->function=target->function;
1258 goto_out->source_location=target->source_location;
1259 goto_out->make_goto(out_target,
true_exprt());
1261 else_target->function=target->function;
1262 else_target->source_location=target->source_location;
1264 out_target->function=target->function;
1265 out_target->source_location=target->source_location;
1291 assignment->code.add_source_location()=target->source_location;
1292 assignment->function=target->function;
1293 assignment->source_location=target->source_location;
1301 assignment->code.add_source_location()=target->source_location;
1302 assignment->function=target->function;
1303 assignment->source_location=target->source_location;
1311 assignment->code.add_source_location()=target->source_location;
1312 assignment->function=target->function;
1313 assignment->source_location=target->source_location;
bool type_eq(const typet &type1, const typet &type2, const namespacet &ns)
goto_programt::targett abstract_pointer_assign(goto_programt &dest, goto_programt::targett it)
The type of an expression.
bool build_array(const array_exprt &object, exprt &dest, bool write)
irep_idt name
The unique identifier.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast a generic exprt to a typecast_exprt.
const typet & follow(const typet &src) const
const std::string arg_suffix
const code_declt & to_code_decl(const codet &code)
void string_abstraction(symbol_tablet &symbol_table, message_handlert &message_handler, goto_programt &dest)
virtual bool lookup(const irep_idt &name, const symbolt *&symbol) const
const typet & build_abstraction_type_rec(const typet &type, const abstraction_types_mapt &known)
targett add_instruction()
Adds an instruction at the end.
A generic base class for relations, i.e., binary predicates.
const std::string & id2string(const irep_idt &d)
pointer_typet pointer_type(const typet &subtype)
const std::string integer2string(const mp_integer &n, unsigned base)
void make_type(exprt &dest, const typet &type)
exprt build_unknown(whatt what, bool write)
goto_programt::targett char_assign(goto_programt &dest, goto_programt::targett target, const exprt &new_lhs, const exprt &lhs, const exprt &rhs)
void clear()
Clear the goto program.
irep_idt mode
Language mode.
goto_programt initialization
goto_programt::targett abstract_char_assign(goto_programt &dest, goto_programt::targett it)
instructionst instructions
The list of instructions in the goto program.
void move_lhs_arithmetic(exprt &lhs, exprt &rhs)
void declare_define_locals(goto_programt &dest)
const irep_idt & get_identifier() const
std::vector< componentt > componentst
const member_exprt & to_member_expr(const exprt &expr)
Cast a generic exprt to a member_exprt.
std::vector< parametert > parameterst
exprt value
Initial value of symbol.
const componentst & components() const
bool build_wrap(const exprt &object, exprt &dest, bool write)
void build_new_symbol(const symbolt &symbol, const irep_idt &identifier, const typet &type)
The trinary if-then-else operator.
static typet build_type(whatt what)
irep_idt module
Name of module the symbol belongs to.
irep_idt pretty_name
Language-specific display name.
void add_str_arguments(const irep_idt &name, goto_functionst::goto_functiont &fct)
exprt::operandst argumentst
unsignedbv_typet size_type()
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
static mstreamt & eom(mstreamt &m)
Extract member of struct or union.
void add_argument(code_typet::parameterst &str_args, const symbolt &fct_symbol, const typet &type, const irep_idt &base_name, const irep_idt &identifier)
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast a generic exprt to a dereference_exprt.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a generic typet to a struct_union_typet.
const index_exprt & to_index_expr(const exprt &expr)
Cast a generic exprt to an index_exprt.
void make_decl_and_def(goto_programt &dest, goto_programt::targett ref_instr, const irep_idt &identifier, const irep_idt &source_sym)
const code_assignt & to_code_assign(const codet &code)
const irep_idt & id() const
::std::set< irep_idt > current_args
const array_typet & to_array_type(const typet &type)
Cast a generic typet to an array_typet.
void replace_string_macros(exprt &expr, bool lhs, const source_locationt &)
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast a generic exprt to an address_of_exprt.
bool build_symbol(const symbol_exprt &sym, exprt &dest)
class symbol_exprt symbol_expr() const
produces a symbol_exprt for a symbol
bool build_symbol_constant(const mp_integer &zero_length, const mp_integer &buf_size, exprt &dest)
The boolean constant true.
bool is_char_type(const typet &type) const
static bool is_ptr_argument(const typet &type)
A declaration of a local variable.
::std::map< typet, typet > abstraction_types_mapt
const if_exprt & to_if_expr(const exprt &expr)
Cast a generic exprt to an if_exprt.
goto_programt::targett abstract_assign(goto_programt &dest, goto_programt::targett it)
Operator to dereference a pointer.
static irep_idt entry_point()
API to expression classes.
const irep_idt & get_identifier() const
exprt make_val_or_dummy_rec(goto_programt &dest, goto_programt::targett ref_instr, const symbolt &symbol, const typet &source_type)
const irep_idt & get(const irep_namet &name) const
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
symbol_tablet & symbol_table
A side effect that returns a non-deterministically chosen value.
exprt build(const exprt &pointer, whatt what, bool write, const source_locationt &)
const exprt & size() const
#define forall_operands(it, expr)
array constructor from single element
bitvector_typet index_type()
goto_function_templatet< goto_programt > goto_functiont
goto_programt::targett abstract(goto_programt &dest, goto_programt::targett it)
goto_programt::targett value_assignments(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt &rhs)
const array_exprt & to_array_expr(const exprt &expr)
Cast a generic exprt to an array_exprt.
Operator to return the address of an object.
function_mapt function_map
Various predicates over pointers in programs.
bool move(symbolt &symbol, symbolt *&new_symbol)
Move a symbol into the symbol table.
goto_programt::targett value_assignments_string_struct(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt &rhs)
The boolean constant false.
const typet & build_abstraction_type(const typet &type)
void abstract_function_call(goto_programt &dest, goto_programt::targett it)
A specialization of goto_program_templatet over goto programs in which instructions have codet type...
typet type
Type of symbol.
void operator()(goto_programt &dest)
source_locationt location
Source code location of definition of symbol.
string_abstractiont(symbol_tablet &_symbol_table, message_handlert &_message_handler)
Base type of C structs and unions, and C++ classes.
Base class for all expressions.
const exprt & struct_op() const
const parameterst & parameters() const
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
irep_idt base_name
Base (non-scoped) name.
exprt pointer_offset(const exprt &pointer)
#define Forall_goto_functions(it, functions)
const source_locationt & source_location() const
irep_idt get_component_name() const
symbol_exprt add_dummy_symbol_and_value(goto_programt &dest, goto_programt::targett ref_instr, const symbolt &symbol, const irep_idt &component_name, const typet &type, const typet &source_type)
unsigned temporary_counter
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
const code_typet & to_code_type(const typet &type)
Cast a generic typet to a code_typet.
#define Forall_operands(it, expr)
#define Forall_goto_program_instructions(it, program)
bool build_pointer(const exprt &object, exprt &dest, bool write)
bool build_if(const if_exprt &o_if, exprt &dest, bool write)
Expression to hold a symbol (variable)
void destructive_append(goto_program_templatet< codeT, guardT > &p)
Appends the given program, which is destroyed.
bool is_ptr_string_struct(const typet &type) const
goto_programt::targett value_assignments_if(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const if_exprt &rhs)
const typet & subtype() const
static bool has_string_macros(const exprt &expr)
struct constructor from list of elements
exprt member(const exprt &a, whatt what)
abstraction_types_mapt abstraction_types_map
const irept & find(const irep_namet &name) const
array constructor from list of elements
void set(const irep_namet &name, const irep_idt &value)
void swap(goto_program_templatet< codeT, guardT > &program)
Swap the goto program.
const code_function_callt & to_code_function_call(const codet &code)
instructionst::iterator targett