Go to the documentation of this file.
27 exprt &dest,
bool write)
30 if(
build(
object, dest, write))
44 !(dest.
type().
id() == ID_array && a_t.
id() == ID_pointer &&
47 warning() <<
"warning: inconsistent abstract type for "
48 <<
object.pretty() <<
eom;
62 return type.
id()==ID_pointer;
97 arg_suffix(
"#strarg"),
98 sym_suffix(
"#str$fcn"),
99 symbol_table(_symbol_table),
107 s.components()[1].set_pretty_name(
"length");
108 s.components()[2].set_pretty_name(
"size");
133 abstract(it->second.body);
138 goto_functionst::function_mapt::iterator
170 for(
const auto &identifier : fct.parameter_identifiers)
172 if(identifier.empty())
177 if(abstract_type.
is_nil())
190 for(
const auto &new_param : str_args)
191 fct.parameter_identifiers.push_back(new_param.get_identifier());
194 symb_parameters.insert(
195 symb_parameters.end(), str_args.begin(), str_args.end());
209 str_args.back().add_source_location()=fct_symbol.
location;
210 str_args.back().set_base_name(base_name);
211 str_args.back().set_identifier(identifier);
214 new_symbol.
type=final_type;
216 new_symbol.
location=str_args.back().source_location();
217 new_symbol.
name=str_args.back().get_identifier();
219 new_symbol.
base_name=str_args.back().get_base_name();
221 new_symbol.
pretty_name=str_args.back().get_base_name();
231 it=
abstract(dest, it);
243 typedef std::unordered_map<irep_idt, goto_programt::targett> available_declst;
244 available_declst available_decls;
250 available_decls.insert(
251 std::make_pair(it->get_decl().get_identifier(), it));
254 for(
const auto &l :
locals)
259 available_declst::const_iterator entry=available_decls.find(l.first);
261 if(available_declst::const_iterator(available_decls.end())!=entry)
263 ref_instr=entry->second;
286 decl1->code.add_source_location()=ref_instr->source_location;
302 assignment1->code.add_source_location()=ref_instr->source_location;
312 if(eff_type.
id()==ID_array || eff_type.
id()==ID_pointer)
317 dest, ref_instr, symbol,
irep_idt(),
318 eff_type.
subtype(), source_subt);
320 if(eff_type.
id()==ID_array)
326 eff_type.
id() == ID_union ||
337 struct_union_typet::componentst::const_iterator it2=components.begin();
338 for(struct_union_typet::componentst::const_iterator
339 it=s_components.begin();
340 it!=s_components.end() && it2!=components.end();
343 if(it->get_name()!=it2->get_name())
347 if(eff_sub_type.
id()==ID_pointer ||
348 eff_sub_type.
id()==ID_array ||
349 eff_sub_type.
id()==ID_struct ||
350 eff_sub_type.
id()==ID_union)
353 dest, ref_instr, symbol, it2->get_name(),
361 assignment1->code.add_source_location()=ref_instr->source_location;
369 components.size() == seen,
370 "some of the symbol's component names were not found in the source");
382 const typet &source_type)
384 std::string suffix=
"$strdummy";
385 if(!component_name.
empty())
386 suffix=
"#"+
id2string(component_name)+suffix;
391 new_symbol.
type=type;
393 new_symbol.
location=ref_instr->source_location;
394 new_symbol.
name=dummy_identifier;
406 decl->code.add_source_location()=ref_instr->source_location;
432 assignment1->code.add_source_location()=ref_instr->source_location;
455 exprt tmp = it->get_condition();
457 it->set_condition(tmp);
512 target->set_assign(assign);
515 const typet &type = target->get_assign().lhs().type();
517 if(type.
id() == ID_pointer)
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())
549 "function call: not enough arguments", target->source_location);
552 str_args.push_back(
exprt());
558 if(str_args.back().type().id()==ID_array &&
559 abstract_type.
id()==ID_pointer)
562 str_args.back().type().subtype() == abstract_type.
subtype(),
563 "argument array type differs from formal parameter pointer type");
567 idx.
set(
"bounds_check",
false);
576 arguments.insert(arguments.end(), str_args.begin(), str_args.end());
578 target->set_function_call(call);
583 if(expr.
id()==
"is_zero_string" ||
584 expr.
id()==
"zero_string_length" ||
585 expr.
id()==
"buffer_size")
600 if(expr.
id()==
"is_zero_string")
607 else if(expr.
id()==
"zero_string_length")
614 else if(expr.
id()==
"buffer_size")
627 const exprt &pointer,
633 if(pointer.
id()==ID_typecast)
663 abstraction_types_mapt::const_iterator map_entry=
666 return map_entry->second;
673 map_entry=tmp.find(eff_type);
676 std::make_pair(eff_type, map_entry->second)).first->second;
683 abstraction_types_mapt::const_iterator known_entry=known.
find(eff_type);
684 if(known_entry!=known.end())
685 return known_entry->second;
687 ::std::pair<abstraction_types_mapt::iterator, bool> map_entry(
689 if(!map_entry.second)
690 return map_entry.first->second;
692 if(eff_type.
id()==ID_array || eff_type.
id()==ID_pointer)
703 if(eff_type.
id()==ID_array)
704 map_entry.first->second=
711 else if(eff_type.
id()==ID_struct || eff_type.
id()==ID_union)
716 for(
const auto &comp : struct_union_type.
components())
718 if(comp.get_anonymous())
726 new_comp.back().set_name(comp.get_name());
727 new_comp.back().set_pretty_name(comp.get_pretty_name());
728 new_comp.back().type()=subt;
730 if(!new_comp.empty())
734 map_entry.first->second=t;
738 return map_entry.first->second;
744 if(abstract_type.
is_nil())
747 if(
object.
id()==ID_typecast)
752 return dest.
type() != abstract_type ||
753 (dest.
type().
id() == ID_array && abstract_type.
id() == ID_pointer &&
757 if(
object.
id()==ID_string_constant)
759 const std::string &str_value =
763 const std::size_t str_len =
764 std::min(str_value.size(), str_value.find(
'\0'));
768 if(
object.
id()==ID_array &&
is_char_type(
object.type().subtype()))
775 if(
object.
id()==ID_symbol)
778 if(
object.
id()==ID_if)
781 if(
object.
id()==ID_member)
789 if(
object.
id()==ID_dereference)
797 if(
object.
id()==ID_index)
805 if(
object.type().
id()==ID_pointer)
812 exprt &dest,
bool write)
819 if(op1_err && op2_err)
840 exprt &dest,
bool write)
849 const auto size = numeric_cast<mp_integer>(a_size);
851 if(!size.has_value())
854 *size ==
object.operands().size(),
855 "wrong number of array object arguments");
857 exprt::operandst::const_iterator it=
object.operands().begin();
866 exprt &dest,
bool write)
902 return exprt(ID_null_object, type);
924 return exprt(ID_null_object, type);
932 locals[identifier]=identifier;
935 new_symbol.
type=type;
937 new_symbol.
name=identifier;
940 new_symbol.
mode=ID_C;
945 return ns.
lookup(identifier).symbol_expr();
982 new_symbol.
type=type;
985 new_symbol.
name=identifier;
1001 dummy_loc->source_location=symbol.
location;
1022 new_symbol.
name=identifier;
1024 new_symbol.
mode=ID_C;
1052 if(lhs.
id()==ID_minus)
1070 const exprt *rhsp = &(assign.
rhs());
1072 while(rhsp->
id()==ID_typecast)
1076 if(abstract_type.
is_nil())
1079 exprt new_lhs, new_rhs;
1088 if(lhs.
type().
id()==ID_pointer && !unknown)
1096 return std::next(target);
1111 const exprt *rhsp = &(assign.
rhs());
1113 while(rhsp->
id()==ID_typecast)
1121 if(lhs.
id()==ID_index)
1131 "failed to create length-component for the left-hand-side");
1139 return char_assign(dest, target, new_lhs, i2, min_expr);
1142 else if(lhs.
id()==ID_dereference)
1151 "failed to create length-component for the left-hand-side");
1172 const exprt &new_lhs,
1181 "failed to create is_zero-component for the left-hand-side");
1185 assignment1->code.add_source_location()=target->source_location;
1189 assignment2->code.add_source_location()=target->source_location;
1192 assignment2->code.op0(),
1193 assignment2->code.op1());
1213 if(lhs.
type().
id()==ID_array)
1216 const auto size = numeric_cast<mp_integer>(a_size);
1218 if(!size.has_value())
1225 else if(lhs.
type().
id() == ID_pointer)
1230 else if(lhs.
type().
id()==ID_struct || lhs.
type().
id()==ID_union)
1235 for(
const auto &comp : struct_union_type.
components())
1238 !comp.get_name().empty(),
"struct/union components must have a name");
1266 goto_else->complete_goto(else_target);
1267 goto_out->complete_goto(out_target);
1293 assignment->code.add_source_location()=target->source_location;
1301 assignment->code.add_source_location()=target->source_location;
1309 assignment->code.add_source_location()=target->source_location;
1327 "either the expression is not a string or it is not a pointer to one");
1330 a.
type().
id()==ID_pointer?
Class that provides messages with a built-in verbosity 'level'.
#define Forall_goto_program_instructions(it, program)
#define UNREACHABLE
This should be used to mark dead code.
const componentst & components() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
string_abstractiont(symbol_tablet &_symbol_table, message_handlert &_message_handler)
static exprt conditional_cast(const exprt &expr, const typet &type)
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const typet & subtype() const
exprt member(const exprt &a, whatt what)
static typet build_type(whatt what)
exprt build(const exprt &pointer, whatt what, bool write, const source_locationt &)
goto_programt::targett abstract_assign(goto_programt &dest, goto_programt::targett it)
#define Forall_operands(it, expr)
const array_exprt & to_array_expr(const exprt &expr)
Cast an exprt to an array_exprt.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
std::vector< parametert > parameterst
bool build_pointer(const exprt &object, exprt &dest, bool write)
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
abstraction_types_mapt abstraction_types_map
Base type for structs and unions.
typet type
Type of symbol.
Operator to dereference a pointer.
The trinary if-then-else operator.
Various predicates over pointers in programs.
const irept & find(const irep_namet &name) const
::std::set< irep_idt > current_args
goto_programt::targett abstract(goto_programt &dest, goto_programt::targett it)
const string_constantt & to_string_constant(const exprt &expr)
targett add(instructiont &&instruction)
Adds a given instruction at the end.
The plus expression Associativity is not specified.
Base class for all expressions.
std::vector< componentt > componentst
irep_idt base_name
Base (non-scoped) name.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
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)
function_mapt function_map
Expression to hold a symbol (variable)
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
bool is_ptr_string_struct(const typet &type) const
void abstract_function_call(goto_programt::targett it)
bitvector_typet index_type()
const minus_exprt & to_minus_expr(const exprt &expr)
Cast an exprt to a minus_exprt.
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
goto_programt::targett abstract_char_assign(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)
Thrown when a goto program that's being processed is in an invalid format, for example passing the wr...
void make_type(exprt &dest, const typet &type)
irep_idt pretty_name
Language-specific display name.
bool is_char_type(const typet &type) const
Struct constructor from list of elements.
const exprt & size() const
typet & type()
Return the type of the expression.
::std::map< typet, typet > abstraction_types_mapt
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
codet representation of a function call statement.
static bool has_string_macros(const exprt &expr)
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
symbol_tablet & symbol_table
Replace all uses of char * by a struct that carries that string, and also the underlying allocation a...
exprt build_unknown(whatt what, bool write)
irep_idt mode
Language mode.
mstreamt & result() const
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
const std::string & id2string(const irep_idt &d)
codet code
Do not read or modify directly – use get_X() instead.
#define forall_operands(it, expr)
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
void declare_define_locals(goto_programt &dest)
const exprt & struct_op() const
#define PRECONDITION(CONDITION)
const irep_idt & get_identifier() const
Array constructor from single element.
exprt boolean_negate(const exprt &src)
negate a Boolean expression, possibly removing a not_exprt, and swapping false and true
exprt make_val_or_dummy_rec(goto_programt &dest, goto_programt::targett ref_instr, const symbolt &symbol, const typet &source_type)
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
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)
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
pointer_typet pointer_type(const typet &subtype)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
void build_new_symbol(const symbolt &symbol, const irep_idt &identifier, const typet &type)
const typet & build_abstraction_type(const typet &type)
const irep_idt & id() const
exprt::operandst argumentst
The Boolean constant false.
goto_programt::targett char_assign(goto_programt &dest, goto_programt::targett target, const exprt &new_lhs, const exprt &lhs, const exprt &rhs)
const parameterst & parameters() const
goto_programt::targett value_assignments_if(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const if_exprt &rhs)
goto_programt initialization
exprt pointer_offset(const exprt &pointer)
int main(int argc, char *argv[])
#define Forall_goto_functions(it, functions)
void clear()
Clear the goto program.
bool build_wrap(const exprt &object, exprt &dest, bool write)
void replace_string_macros(exprt &expr, bool lhs, const source_locationt &)
static bool is_ptr_argument(const typet &type)
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
A side_effect_exprt that returns a non-deterministically chosen value.
::goto_functiont goto_functiont
bool is_zero() const
Return whether the expression is a constant representing 0.
Extract member of struct or union.
instructionst instructions
The list of instructions in the goto program.
Deprecated expression utility functions.
A collection of goto functions.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
exprt value
Initial value of symbol.
goto_programt::targett abstract_pointer_assign(goto_programt &dest, goto_programt::targett it)
Structure type, corresponds to C style structs.
goto_functionst goto_functions
GOTO functions.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
const irep_idt & get(const irep_namet &name) const
source_locationt location
Source code location of definition of symbol.
unsigned temporary_counter
void set(const irep_namet &name, const irep_idt &value)
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
bool build_symbol_constant(const mp_integer &zero_length, const mp_integer &buf_size, exprt &dest)
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
const symbolst & symbols
Read-only field, used to look up symbols given their names.
A base class for relations, i.e., binary predicates whose two operands have the same type.
void make_decl_and_def(goto_programt &dest, goto_programt::targett ref_instr, const irep_idt &identifier, const irep_idt &source_sym)
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
A generic container class for the GOTO intermediate representation of one function.
bool build_array(const array_exprt &object, exprt &dest, bool write)
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
irep_idt get_component_name() const
void add_str_arguments(const irep_idt &name, goto_functionst::goto_functiont &fct)
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
Operator to return the address of an object.
source_locationt & add_source_location()
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
void move_lhs_arithmetic(exprt &lhs, exprt &rhs)
unsignedbv_typet size_type()
A codet representing an assignment in the program.
The Boolean constant true.
const std::string arg_suffix
irep_idt module
Name of module the symbol belongs to.
mstreamt & warning() const
bool is_constant(const typet &type)
This method tests, if the given typet is a constant.
bool build_if(const if_exprt &o_if, exprt &dest, bool write)
This class represents an instruction in the GOTO intermediate representation.
const source_locationt & source_location() const
void operator()(goto_programt &dest)
symbol_tablet symbol_table
Symbol table.
Array constructor from list of elements.
bool build_symbol(const symbol_exprt &sym, exprt &dest)
void add_argument(code_typet::parameterst &str_args, const symbolt &fct_symbol, const typet &type, const irep_idt &base_name, const irep_idt &identifier)
irep_idt name
The unique identifier.
void swap(goto_programt &program)
Swap the goto program.
instructionst::iterator targett
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
const struct_exprt & to_struct_expr(const exprt &expr)
Cast an exprt to a struct_exprt.
goto_programt::targett value_assignments_string_struct(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt &rhs)
const std::string integer2string(const mp_integer &n, unsigned base)