27 exprt &dest,
bool write)
30 if(
build(
object, dest, write))
43 !(dest.
type().
id()==ID_array && a_t.
id()==ID_pointer &&
46 warning() <<
"warning: inconsistent abstract type for " 47 <<
object.pretty() <<
eom;
56 return type.
id()==ID_pointer &&
62 return type.
id()==ID_pointer;
97 arg_suffix(
"#strarg"),
98 sym_suffix(
"#str$fcn"),
99 symbol_table(_symbol_table),
142 abstract(it->second.body);
147 goto_functionst::function_mapt::iterator
181 for(code_typet::parameterst::iterator
182 it=parameters.begin();
183 it!=parameters.end();
187 if(abstract_type.
is_nil())
190 const irep_idt &identifier=it->get_identifier();
201 parameters.insert(parameters.end(), str_args.begin(), str_args.end());
204 symb_parameters.insert(
205 symb_parameters.end(), str_args.begin(), str_args.end());
219 str_args.back().add_source_location()=fct_symbol.
location;
220 str_args.back().set_base_name(base_name);
221 str_args.back().set_identifier(identifier);
224 new_symbol.
type=final_type;
226 new_symbol.
location=str_args.back().source_location();
227 new_symbol.
name=str_args.back().get_identifier();
229 new_symbol.
base_name=str_args.back().get_base_name();
231 new_symbol.
pretty_name=str_args.back().get_base_name();
241 it=
abstract(dest, it);
253 typedef std::unordered_map<irep_idt, goto_programt::targett> available_declst;
254 available_declst available_decls;
260 available_decls.insert(std::make_pair(
264 for(
const auto &l :
locals)
269 available_declst::const_iterator entry=available_decls.find(l.first);
271 if(available_declst::const_iterator(available_decls.end())!=entry)
273 ref_instr=entry->second;
296 decl1->source_location=ref_instr->source_location;
297 decl1->function=ref_instr->function;
299 decl1->code.add_source_location()=ref_instr->source_location;
313 assignment1->make_assignment();
314 assignment1->source_location=ref_instr->source_location;
315 assignment1->function=ref_instr->function;
317 assignment1->code.add_source_location()=ref_instr->source_location;
327 if(eff_type.
id()==ID_array || eff_type.
id()==ID_pointer)
332 dest, ref_instr, symbol,
irep_idt(),
333 eff_type.
subtype(), source_subt);
335 if(eff_type.
id()==ID_array)
340 else if(eff_type.
id()==ID_union ||
351 struct_union_typet::componentst::const_iterator it2=components.begin();
352 for(struct_union_typet::componentst::const_iterator
353 it=s_components.begin();
354 it!=s_components.end() && it2!=components.end();
357 if(it->get_name()!=it2->get_name())
361 if(eff_sub_type.
id()==ID_pointer ||
362 eff_sub_type.
id()==ID_array ||
363 eff_sub_type.
id()==ID_struct ||
364 eff_sub_type.
id()==ID_union)
367 dest, ref_instr, symbol, it2->get_name(),
373 assignment1->make_assignment();
374 assignment1->source_location=ref_instr->source_location;
375 assignment1->function=ref_instr->function;
377 assignment1->code.add_source_location()=ref_instr->source_location;
385 components.size() == seen,
386 "some of the symbol's component names were not found in the source");
398 const typet &source_type)
400 std::string suffix=
"$strdummy";
401 if(!component_name.
empty())
402 suffix=
"#"+
id2string(component_name)+suffix;
407 new_symbol.
type=type;
409 new_symbol.
location=ref_instr->source_location;
410 new_symbol.
name=dummy_identifier;
422 decl->source_location=ref_instr->source_location;
423 decl->function=ref_instr->function;
425 decl->code.add_source_location()=ref_instr->source_location;
446 assignment1->make_assignment();
447 assignment1->source_location=ref_instr->source_location;
448 assignment1->function=ref_instr->function;
450 assignment1->code.add_source_location()=ref_instr->source_location;
526 if(type.
id()==ID_pointer || type.
id()==ID_array)
545 code_function_callt::argumentst::const_iterator it1=arguments.begin();
546 for(code_typet::parameterst::const_iterator it2=formal_params.begin();
547 it2!=formal_params.end();
551 if(abstract_type.
is_nil())
554 if(it1==arguments.end())
557 "function call: not enough arguments", target->source_location);
560 str_args.push_back(
exprt());
566 if(str_args.back().type().id()==ID_array &&
567 abstract_type.
id()==ID_pointer)
571 "argument array type differs from formal parameter pointer type");
575 idx.
set(
"bounds_check",
false);
584 arguments.insert(arguments.end(), str_args.begin(), str_args.end());
589 if(expr.
id()==
"is_zero_string" ||
590 expr.
id()==
"zero_string_length" ||
591 expr.
id()==
"buffer_size")
606 if(expr.
id()==
"is_zero_string")
612 else if(expr.
id()==
"zero_string_length")
618 else if(expr.
id()==
"buffer_size")
630 const exprt &pointer,
636 if(pointer.
id()==ID_typecast)
641 "pointer typecast takes exactly 1 argument");
642 if(pointer.
op0().
type().
id() != ID_pointer)
646 return build(pointer.
op0(), what, write, source_location);
668 abstraction_types_mapt::const_iterator map_entry=
671 return map_entry->second;
678 map_entry=tmp.find(eff_type);
681 std::make_pair(eff_type, map_entry->second)).first->second;
688 abstraction_types_mapt::const_iterator known_entry=known.
find(eff_type);
689 if(known_entry!=known.end())
690 return known_entry->second;
692 ::std::pair< abstraction_types_mapt::iterator, bool > map_entry(
695 if(!map_entry.second)
696 return map_entry.first->second;
698 if(eff_type.
id()==ID_array || eff_type.
id()==ID_pointer)
709 if(eff_type.
id()==ID_array)
710 map_entry.first->second=
717 else if(eff_type.
id()==ID_struct || eff_type.
id()==ID_union)
722 for(
const auto &comp : struct_union_type.
components())
724 if(comp.get_anonymous())
732 new_comp.back().set_name(comp.get_name());
733 new_comp.back().set_pretty_name(comp.get_pretty_name());
734 new_comp.back().type()=subt;
736 if(!new_comp.empty())
740 map_entry.first->second=t;
744 return map_entry.first->second;
750 if(abstract_type.
is_nil())
753 if(
object.
id()==ID_typecast)
759 (dest.
type().
id()==ID_array &&
760 abstract_type.
id()==ID_pointer &&
764 if(
object.
id()==ID_string_constant)
766 const std::string &str_value =
id2string(
object.get(ID_value));
769 const std::size_t str_len =
770 std::min(str_value.size(), str_value.find(
'\0'));
774 if(
object.
id()==ID_array &&
is_char_type(
object.type().subtype()))
778 if(
object.is_constant())
781 if(
object.
id()==ID_symbol)
784 if(
object.
id()==ID_if)
787 if(
object.
id()==ID_member)
794 if(
object.
id()==ID_dereference)
801 if(
object.
id()==ID_index)
809 if(
object.type().id()==ID_pointer)
816 exprt &dest,
bool write)
823 if(op1_err && op2_err)
828 new_if.type()=new_if.false_case().type();
833 new_if.
type()=new_if.true_case().type();
837 new_if.
type()=new_if.true_case().type();
844 exprt &dest,
bool write)
858 size ==
object.operands().size(),
"wrong number of array object arguments");
860 exprt::operandst::const_iterator it=
object.operands().begin();
869 exprt &dest,
bool write)
905 return exprt(ID_null_object, type);
927 return exprt(ID_null_object, type);
935 locals[identifier]=identifier;
938 new_symbol.
type=type;
940 new_symbol.
name=identifier;
943 new_symbol.
mode=ID_C;
948 return ns.
lookup(identifier).symbol_expr();
985 new_symbol.
type=type;
988 new_symbol.
name=identifier;
1003 dummy_loc->source_location=symbol.
location;
1024 new_symbol.
name=identifier;
1026 new_symbol.
mode=ID_C;
1042 assignment1->make_assignment();
1056 if(lhs.
id()==ID_minus)
1076 while(rhsp->
id()==ID_typecast)
1077 rhsp=&(rhsp->
op0());
1080 if(abstract_type.
is_nil())
1083 exprt new_lhs, new_rhs;
1092 if(lhs.
type().
id()==ID_pointer && !unknown)
1097 assignment.
function=target->function;
1120 while(rhsp->
id()==ID_typecast)
1121 rhsp=&(rhsp->
op0());
1128 if(lhs.
id()==ID_index)
1138 "failed to create length-component for the left-hand-side");
1146 return char_assign(dest, target, new_lhs, i2, min_expr);
1149 else if(lhs.
id()==ID_dereference)
1158 "failed to create length-component for the left-hand-side");
1179 const exprt &new_lhs,
1188 "failed to create is_zero-component for the left-hand-side");
1191 assignment1->make_assignment();
1192 assignment1->source_location=target->source_location;
1193 assignment1->function=target->function;
1195 assignment1->code.add_source_location()=target->source_location;
1198 assignment2->make_assignment();
1199 assignment2->source_location=target->source_location;
1200 assignment2->function=target->function;
1202 assignment2->code.add_source_location()=target->source_location;
1205 assignment2->code.op0(),
1206 assignment2->code.op1());
1226 if(lhs.
type().
id()==ID_array)
1238 else if(lhs.
type().
id()==ID_pointer)
1244 else if(lhs.
type().
id()==ID_struct || lhs.
type().
id()==ID_union)
1249 for(
const auto &comp : struct_union_type.
components())
1252 !comp.get_name().empty(),
"struct/union components must have a name");
1275 goto_else->function=target->function;
1276 goto_else->source_location=target->source_location;
1279 goto_out->function=target->function;
1280 goto_out->source_location=target->source_location;
1281 goto_out->make_goto(out_target,
true_exprt());
1283 else_target->function=target->function;
1284 else_target->source_location=target->source_location;
1286 out_target->function=target->function;
1287 out_target->source_location=target->source_location;
1313 assignment->code.add_source_location()=target->source_location;
1314 assignment->function=target->function;
1315 assignment->source_location=target->source_location;
1323 assignment->code.add_source_location()=target->source_location;
1324 assignment->function=target->function;
1325 assignment->source_location=target->source_location;
1333 assignment->code.add_source_location()=target->source_location;
1334 assignment->function=target->function;
1335 assignment->source_location=target->source_location;
1353 "either the expression is not a string or it is not a pointer to one");
1356 a.
type().
id()==ID_pointer?
1370 return std::move(
result);
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
bool type_eq(const typet &type1, const typet &type2, const namespacet &ns)
Check types for equality at the top level.
irep_idt function
The function this instruction belongs to.
goto_programt::targett abstract_pointer_assign(goto_programt &dest, goto_programt::targett it)
The type of an expression, extends irept.
bool build_array(const array_exprt &object, exprt &dest, bool write)
irep_idt name
The unique identifier.
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)
const typet & build_abstraction_type_rec(const typet &type, const abstraction_types_mapt &known)
A base class for relations, i.e., binary predicates.
const std::string & id2string(const irep_idt &d)
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
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)
void abstract_function_call(goto_programt::targett it)
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)
irep_idt mode
Language mode.
goto_programt initialization
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
const array_exprt & to_array_expr(const exprt &expr)
Cast an exprt to an array_exprt.
goto_programt::targett abstract_char_assign(goto_programt &dest, goto_programt::targett it)
Deprecated expression utility functions.
void move_lhs_arithmetic(exprt &lhs, exprt &rhs)
void declare_define_locals(goto_programt &dest)
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const irep_idt & get_identifier() const
const irep_idt & get_identifier() const
std::vector< componentt > componentst
std::vector< parametert > parameterst
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
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.
function_mapt function_map
irep_idt pretty_name
Language-specific display name.
typet & type()
Return the type of the expression.
void add_str_arguments(const irep_idt &name, goto_functionst::goto_functiont &fct)
exprt::operandst argumentst
unsignedbv_typet size_type()
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
symbol_tablet symbol_table
Symbol table.
#define CHECK_RETURN(CONDITION)
Structure type, corresponds to C style structs.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
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)
mstreamt & warning() const
This class represents an instruction in the GOTO intermediate representation.
virtual symbolt * get_writeable(const irep_idt &name) override
Find a symbol in the symbol table for read-write access.
void clear()
Clear the goto program.
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
void replace_string_macros(exprt &expr, bool lhs, const source_locationt &)
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)
instructionst::iterator targett
A codet representing the declaration of a local variable.
::std::map< typet, typet > abstraction_types_mapt
goto_programt::targett abstract_assign(goto_programt &dest, goto_programt::targett it)
Operator to dereference a pointer.
instructionst instructions
The list of instructions in the goto program.
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...
::goto_functiont goto_functiont
symbol_tablet & symbol_table
#define PRECONDITION(CONDITION)
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
A side_effect_exprt that returns a non-deterministically chosen value.
exprt build(const exprt &pointer, whatt what, bool write, const source_locationt &)
const exprt & size() const
codet representation of a function call statement.
#define forall_operands(it, expr)
The plus expression Associativity is not specified.
A collection of goto functions.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Array constructor from single element.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
Class that provides messages with a built-in verbosity 'level'.
bitvector_typet index_type()
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
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)
Operator to return the address of an object.
Various predicates over pointers in programs.
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 swap(goto_programt &program)
Swap the goto program.
A generic container class for the GOTO intermediate representation of one function.
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)
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
Base type for structs and unions.
mstreamt & result() const
Thrown when a goto program that's being processed is in an invalid format, for example passing the wr...
source_locationt source_location
The location of the instruction in the source file.
targett add_instruction()
Adds an instruction at the end.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
Base class for all expressions.
const exprt & struct_op() const
const parameterst & parameters() const
irep_idt base_name
Base (non-scoped) name.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
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)
#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.
unsigned temporary_counter
The NIL type, i.e., an invalid type, no value.
#define Forall_operands(it, expr)
bool is_zero() const
Return whether the expression is a constant representing 0.
source_locationt & add_source_location()
#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)
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
exprt boolean_negate(const exprt &src)
negate a Boolean expression, possibly removing a not_exprt, and swapping false and true
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const irept & find(const irep_namet &name) const
goto_functionst goto_functions
GOTO functions.
Array constructor from list of elements.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
A codet representing an assignment in the program.
void set(const irep_namet &name, const irep_idt &value)
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
const code_function_callt & to_code_function_call(const codet &code)