48 !(dest.
type().
id() == ID_array && a_t.
id() == ID_pointer &&
53 log.warning() <<
"warning: inconsistent abstract type for "
63 return type.
id() == ID_pointer &&
69 return type.
id()==ID_pointer;
82 : sym_suffix(
"#str$fcn"),
83 goto_model(goto_model),
84 ns(goto_model.symbol_table),
86 message_handler(_message_handler)
92 s.components()[1].set_pretty_name(
"length");
93 s.components()[2].set_pretty_name(
"size");
142 if(type.
id() != ID_code)
147 goto_functionst::function_mapt::iterator fct_entry =
164 abstract(gf_entry.second.body);
168 goto_functionst::function_mapt::iterator
201 goto_functiont::parameter_identifierst::const_iterator param_id_it =
202 parameter_identifiers.begin();
203 for(
const auto ¶meter : fct_type.
parameters())
206 if(abstract_type.
is_nil())
209 str_args.push_back(
add_parameter(fct_symbol, abstract_type, *param_id_it));
213 for(
const auto &new_param : str_args)
214 parameter_identifiers.push_back(new_param.get_identifier());
216 fct_type.
parameters().end(), str_args.begin(), str_args.end());
232 :
ns.
lookup(identifier).base_name) +
242 str_parameter.set_base_name(param_symbol.
base_name);
243 str_parameter.set_identifier(param_symbol.
name);
245 if(!identifier.
empty())
248 return str_parameter;
256 it=
abstract(dest, it);
268 typedef std::unordered_map<irep_idt, goto_programt::targett> available_declst;
269 available_declst available_decls;
275 available_decls.insert(
276 std::make_pair(it->decl_symbol().get_identifier(), it));
279 for(
const auto &l :
locals)
284 available_declst::const_iterator entry=available_decls.find(l.first);
286 if(available_declst::const_iterator(available_decls.end())!=entry)
288 ref_instr=entry->second;
334 if(symbol.
type.
id() == ID_array || symbol.
type.
id() == ID_pointer)
347 if(symbol.
type.
id() == ID_array)
353 symbol.
type.
id() == ID_union_tag ||
362 struct_union_typet::componentst::const_iterator it2=components.begin();
363 for(struct_union_typet::componentst::const_iterator
364 it=s_components.begin();
365 it!=s_components.end() && it2!=components.end();
368 if(it->get_name()!=it2->get_name())
372 it2->type().id() == ID_pointer || it2->type().id() == ID_array ||
373 it2->type().id() == ID_struct_tag || it2->type().id() == ID_union_tag)
376 dest, ref_instr, symbol, it2->get_name(), it2->
type(), it->type());
390 components.size() == seen,
391 "some of the symbol's component names were not found in the source");
403 const typet &source_type)
405 std::string suffix=
"$strdummy";
406 if(!component_name.
empty())
407 suffix=
"#"+
id2string(component_name)+suffix;
412 new_symbol.
type=type;
414 new_symbol.
location = ref_instr->source_location();
415 new_symbol.
name=dummy_identifier;
432 source_type.
id() == ID_array &&
477 it->condition_nonconst(),
false, it->source_location());
517 exprt &lhs = target->assign_lhs_nonconst();
518 exprt &rhs = target->assign_rhs_nonconst();
530 const typet &type = target->assign_lhs().type();
532 if(type.
id() == ID_pointer || type.
id() == ID_array)
543 auto arguments =
as_const(*target).call_arguments();
546 for(
const auto &arg : arguments)
549 if(abstract_type.
is_nil())
552 str_args.push_back(
exprt());
558 if(str_args.back().type().id()==ID_array &&
559 abstract_type.
id()==ID_pointer)
564 "argument array type differs from formal parameter pointer type");
574 if(!str_args.empty())
576 arguments.insert(arguments.end(), str_args.begin(), str_args.end());
580 for(
const auto &arg : str_args)
583 target->call_arguments() = std::move(arguments);
589 if(expr.
id()==
"is_zero_string" ||
590 expr.
id()==
"zero_string_length" ||
591 expr.
id()==
"buffer_size")
594 for(
const auto &op : expr.
operands())
608 if(expr.
id()==
"is_zero_string")
615 else if(expr.
id()==
"zero_string_length")
622 else if(expr.
id()==
"buffer_size")
635 const exprt &pointer,
641 if(pointer.
id()==ID_typecast)
647 op.
type().
id() != ID_pointer ||
654 return build(op, what,
write, source_location);
679 abstraction_types_mapt::const_iterator map_entry =
682 return map_entry->second;
692 return map_entry->second;
698 abstraction_types_mapt::const_iterator known_entry = known.
find(type);
699 if(known_entry!=known.end())
700 return known_entry->second;
702 ::std::pair<abstraction_types_mapt::iterator, bool> map_entry(
704 if(!map_entry.second)
705 return map_entry.first->second;
707 if(type.
id() == ID_array || type.
id() == ID_pointer)
720 if(type.
id() == ID_array)
721 map_entry.first->second =
728 else if(type.
id() == ID_struct_tag || type.
id() == ID_union_tag)
737 for(
const auto &comp : struct_union_type.
components())
739 if(comp.get_anonymous())
747 new_comp.back().set_name(comp.get_name());
748 new_comp.back().set_pretty_name(comp.get_pretty_name());
749 new_comp.back().type()=subt;
751 if(!new_comp.empty())
756 const symbolt &existing_tag_symbol =
763 existing_tag_symbol.
mode,
766 abstracted_type_symbol.
is_type =
true;
767 abstracted_type_symbol.
is_lvalue =
false;
772 abstracted_type_symbol.
is_macro =
true;
774 if(type.
id() == ID_struct_tag)
781 return map_entry.first->second;
787 if(abstract_type.
is_nil())
790 if(
object.
id()==ID_typecast)
795 return dest.
type() != abstract_type ||
796 (dest.
type().
id() == ID_array && abstract_type.
id() == ID_pointer &&
801 if(
object.
id()==ID_string_constant)
803 const std::string &str_value =
807 const std::size_t str_len =
808 std::min(str_value.size(), str_value.find(
'\0'));
813 object.
id() == ID_array &&
821 if(
object.
id()==ID_symbol)
824 if(
object.
id()==ID_if)
827 if(
object.
id()==ID_member)
838 if(
object.
id()==ID_dereference)
848 if(
object.
id()==ID_index)
859 if(
object.type().
id()==ID_pointer)
873 if(op1_err && op2_err)
903 const auto size = numeric_cast<mp_integer>(a_size);
905 if(!size.has_value())
908 *size ==
object.operands().size(),
909 "wrong number of array object arguments");
911 exprt::operandst::const_iterator it=
object.operands().begin();
957 return exprt(ID_null_object, type);
979 return exprt(ID_null_object, type);
987 locals[identifier]=identifier;
990 new_symbol.
type=type;
992 new_symbol.
name=identifier;
995 new_symbol.
mode=ID_C;
1000 return ns.
lookup(identifier).symbol_expr();
1017 identifier = parameter_map_entry->second;
1050 new_symbol.
type=type;
1053 new_symbol.
name=identifier;
1093 new_symbol.
name=identifier;
1095 new_symbol.
mode=ID_C;
1123 while(lhs.
id() == ID_typecast)
1130 if(lhs.
id()==ID_minus)
1139 while(lhs.
id() == ID_typecast)
1151 const exprt &lhs = target->assign_lhs();
1152 const exprt rhs = target->assign_rhs();
1153 const exprt *rhsp = &(target->assign_rhs());
1155 while(rhsp->
id()==ID_typecast)
1159 if(abstract_type.
is_nil())
1162 exprt new_lhs, new_rhs;
1171 if(lhs.
type().
id()==ID_pointer && !unknown)
1178 return std::next(target);
1190 const exprt &lhs = target->assign_lhs();
1191 const exprt *rhsp = &(target->assign_rhs());
1193 while(rhsp->
id()==ID_typecast)
1201 if(lhs.
id()==ID_index)
1211 "failed to create length-component for the left-hand-side");
1219 return char_assign(dest, target, new_lhs, i2, min_expr);
1222 else if(lhs.
id()==ID_dereference)
1231 "failed to create length-component for the left-hand-side");
1250 const exprt &new_lhs,
1259 "failed to create is_zero-component for the left-hand-side");
1288 if(lhs.
type().
id()==ID_array)
1291 const auto size = numeric_cast<mp_integer>(a_size);
1293 if(!size.has_value())
1300 else if(lhs.
type().
id() == ID_pointer)
1305 else if(lhs.
type().
id()==ID_struct || lhs.
type().
id()==ID_union)
1310 for(
const auto &comp : struct_union_type.
components())
1313 !comp.get_name().empty(),
"struct/union components must have a name");
1341 goto_else->complete_goto(else_target);
1342 goto_out->complete_goto(out_target);
1368 target->source_location()));
1375 target->source_location()));
1382 target->source_location()));
1399 "either the expression is not a string or it is not a pointer to one");
1402 a.
type().
id()==ID_pointer?
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
pointer_typet pointer_type(const typet &subtype)
bitvector_typet c_index_type()
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
Operator to return the address of an object.
Array constructor from list of elements.
Array constructor from single element.
const typet & element_type() const
The type of the elements of the array.
const exprt & size() const
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
A base class for relations, i.e., binary predicates whose two operands have the same type.
A goto_instruction_codet representing an assignment in the program.
A goto_instruction_codet representing the declaration of a local variable.
exprt::operandst argumentst
std::vector< parametert > parameterst
const parameterst & parameters() const
Data structure for representing an arbitrary statement in a program.
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
source_locationt & add_source_location()
const source_locationt & source_location() const
bool is_zero() const
Return whether the expression is a constant representing 0.
typet & type()
Return the type of the expression.
A collection of goto functions.
function_mapt function_map
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
std::vector< irep_idt > parameter_identifierst
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
This class represents an instruction in the GOTO intermediate representation.
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
void clear()
Clear the goto program.
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
instructionst::iterator targett
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
void swap(goto_programt &program)
Swap the goto program.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
The trinary if-then-else operator.
const irept & find(const irep_idt &name) const
const irep_idt & id() const
Extract member of struct or union.
const exprt & struct_op() const
irep_idt get_component_name() const
Class that provides messages with a built-in verbosity 'level'.
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
The plus expression Associativity is not specified.
const typet & base_type() const
The type of the data what we point to.
A side_effect_exprt that returns a non-deterministically chosen value.
Replace all uses of char * by a struct that carries that string, and also the underlying allocation a...
goto_programt::targett abstract(goto_programt &dest, goto_programt::targett it)
goto_programt::targett value_assignments_if(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const if_exprt &rhs)
goto_programt::targett value_assignments_string_struct(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt &rhs)
void declare_define_locals(goto_programt &dest)
exprt make_val_or_dummy_rec(goto_programt &dest, goto_programt::targett ref_instr, const symbolt &symbol, const typet &source_type)
bool build_symbol_constant(const mp_integer &zero_length, const mp_integer &buf_size, exprt &dest)
goto_programt::targett abstract_assign(goto_programt &dest, goto_programt::targett it)
static typet build_type(whatt what)
goto_programt::targett abstract_pointer_assign(goto_programt &dest, goto_programt::targett it)
bool build_if(const if_exprt &o_if, exprt &dest, bool write)
const typet & build_abstraction_type_rec(const typet &type, const abstraction_types_mapt &known)
unsigned temporary_counter
void replace_string_macros(exprt &expr, bool lhs, const source_locationt &)
exprt build_unknown(whatt what, bool write)
string_abstractiont(goto_modelt &goto_model, message_handlert &_message_handler)
Apply string abstraction to goto_model.
void build_new_symbol(const symbolt &symbol, const irep_idt &identifier, const typet &type)
bool is_ptr_string_struct(const typet &type) const
message_handlert & message_handler
::std::map< typet, typet > abstraction_types_mapt
goto_programt initialization
goto_programt::targett value_assignments(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt &rhs)
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)
bool build_wrap(const exprt &object, exprt &dest, bool write)
goto_programt::targett abstract_char_assign(goto_programt &dest, goto_programt::targett it)
bool build_array(const array_exprt &object, exprt &dest, bool write)
bool build_symbol(const symbol_exprt &sym, exprt &dest)
void move_lhs_arithmetic(exprt &lhs, exprt &rhs)
abstraction_types_mapt abstraction_types_map
goto_programt::targett char_assign(goto_programt &dest, goto_programt::targett target, const exprt &new_lhs, const exprt &lhs, const exprt &rhs)
code_typet::parametert add_parameter(const symbolt &fct_symbol, const typet &type, const irep_idt &identifier)
bool build_pointer(const exprt &object, exprt &dest, bool write)
void abstract_function_call(goto_programt::targett it)
exprt member(const exprt &a, whatt what)
static bool has_string_macros(const exprt &expr)
exprt build(const exprt &pointer, whatt what, bool write, const source_locationt &)
void make_decl_and_def(goto_programt &dest, goto_programt::targett ref_instr, const irep_idt &identifier, const irep_idt &source_sym)
void add_str_parameters(symbolt &fct_symbol, goto_functiont::parameter_identifierst ¶meter_identifiers)
bool is_char_type(const typet &type) const
const typet & build_abstraction_type(const typet &type)
Struct constructor from list of elements.
A struct tag type, i.e., struct_typet with an identifier.
Structure type, corresponds to C style structs.
Base type for structs and unions.
const componentst & components() const
std::vector< componentt > componentst
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
std::vector< irep_idt > sorted_symbol_names() const
Build and return a lexicographically sorted vector of symbol names from all symbols stored in this sy...
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
irep_idt base_name
Base (non-scoped) name.
irep_idt module
Name of module the symbol belongs to.
source_locationt location
Source code location of definition of symbol.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
irep_idt pretty_name
Language-specific display name.
exprt value
Initial value of symbol.
irep_idt mode
Language mode.
The Boolean constant true.
const typet & subtype() const
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
source_locationt & add_source_location()
A union tag type, i.e., union_typet with an identifier.
#define Forall_operands(it, expr)
exprt boolean_negate(const exprt &src)
negate a Boolean expression, possibly removing a not_exprt, and swapping false and true
Deprecated expression utility functions.
int main(int argc, char *argv[])
symbolt & get_fresh_aux_symbol(const typet &type, const std::string &name_prefix, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &symbol_mode, const namespacet &ns, symbol_table_baset &symbol_table)
Installs a fresh-named symbol with respect to the given namespace ns with the requested name pattern ...
Fresh auxiliary symbol creation.
#define Forall_goto_program_instructions(it, program)
const std::string & id2string(const irep_idt &d)
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 address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
exprt pointer_offset(const exprt &pointer)
Various predicates over pointers in programs.
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define PRECONDITION(CONDITION)
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const array_exprt & to_array_expr(const exprt &expr)
Cast an exprt to an array_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const minus_exprt & to_minus_expr(const exprt &expr)
Cast an exprt to a minus_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_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.
bool is_constant(const typet &type)
This method tests, if the given typet is a constant.
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_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_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.
const tag_typet & to_tag_type(const typet &type)
Cast a typet to a tag_typet.
void string_abstraction(goto_modelt &goto_model, message_handlert &message_handler)
static bool is_ptr_argument(const typet &type)
const string_constantt & to_string_constant(const exprt &expr)
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)
ssize_t write(int fildes, const void *buf, size_t nbyte)