48 "assignments must be type consistent, got",
55 mstream <<
"Assignment to " << format(lhs) <<
" ["
56 << pointer_offset_bits(lhs.type(), ns).value_or(0) <<
" bits]"
67 if(rhs.
id() == ID_side_effect)
73 statement == ID_cpp_new || statement == ID_cpp_new_array ||
74 statement == ID_java_new_array_data)
78 else if(statement == ID_allocate)
80 else if(statement == ID_va_start)
91 lhs.
id() == ID_symbol &&
103 if(state.
source.
pc->source_location().get_hide())
124 const bool maybe_divisible =
125 lhs.
id() == ID_index ||
128 const bool need_atomic_section = maybe_divisible &&
132 if(need_atomic_section)
138 .assign_rec(lhs,
expr_skeletont{}, rhs, lhs_if_then_else_conditions);
140 if(need_atomic_section)
154 const auto &ibv_type =
157 const std::size_t n_bits = ibv_type.get_width();
160 static_assert(CHAR_BIT == 8,
"bitwidth of char assumed to be 8");
162 const std::size_t n_chars = n_bits / 8;
165 sizeof(std::size_t) >= n_chars,
166 "size_t shall be large enough to represent a character");
170 for(
const auto &c : char_array.
operands())
174 for(std::size_t i = 0; i < n_chars; i++)
176 const char c_chunk =
static_cast<char>((c_val >> (i * 8)) & 0xff);
177 result.push_back(c_chunk);
190 if(rhs.
id() == ID_function_application)
199 if(func_id == ID_cprover_string_concat_func)
203 else if(func_id == ID_cprover_string_empty_string_func)
210 else if(func_id == ID_cprover_string_substring_func)
215 func_id == ID_cprover_string_of_int_func ||
216 func_id == ID_cprover_string_of_long_func)
220 else if(func_id == ID_cprover_string_delete_char_at_func)
224 else if(func_id == ID_cprover_string_delete_func)
228 else if(func_id == ID_cprover_string_set_length_func)
232 else if(func_id == ID_cprover_string_char_set_func)
236 else if(func_id == ID_cprover_string_trim_func)
240 else if(func_id == ID_cprover_string_to_lower_case_func)
244 else if(func_id == ID_cprover_string_to_upper_case_func)
248 else if(func_id == ID_cprover_string_replace_func)
274 const std::string aux_symbol_name =
277 const bool string_constant_exists =
281 string_constant_exists
284 state,
symex_assign, aux_symbol_name, char_array, new_char_array);
287 aux_symbol.
value == new_char_array,
288 "symbol shall have value derived from char array content");
295 if(!string_constant_exists)
305 const std::string &aux_symbol_name,
310 new_char_array_type.
set(ID_C_constant,
true);
328 new_aux_symbol.
value = new_char_array;
335 return new_aux_symbol;
344 const symbolt &function_symbol =
345 ns.
lookup(ID_cprover_associate_array_to_pointer_func);
348 function_symbol.
symbol_expr(), {new_char_array, string_data}};
356 function_symbol.
mode,
361 const ssa_exprt ssa_expr(return_symbol_expr);
367 std::optional<std::reference_wrapper<const array_exprt>>
370 const exprt &content)
372 if(content.
id() != ID_symbol)
377 const auto s_pointer_opt =
388 std::optional<std::reference_wrapper<const constant_exprt>>
391 if(expr.
id() != ID_symbol)
396 const auto constant_expr_opt =
399 if(!constant_expr_opt || !constant_expr_opt->get().is_constant())
404 return std::optional<std::reference_wrapper<const constant_exprt>>(
414 const auto &length_type = f_type.
domain().at(0);
423 "empty string primitive requires two output arguments");
442 const auto &length_type = f_type.
domain().at(0);
461 const std::size_t new_size =
473 const array_exprt new_char_array(std::move(operands), new_char_array_type);
479 new_char_array_length,
491 const std::size_t num_operands = f_l1.
arguments().size();
497 const auto &length_type = f_type.
domain().at(0);
510 if(num_operands == 5)
512 const auto end_index_expr_opt =
515 if(!end_index_expr_opt)
523 if(end_index < 0 || end_index > s_data.
operands().size())
530 end_index = s_data.
operands().size();
533 const auto start_index_expr_opt =
536 if(!start_index_expr_opt)
544 if(start_index < 0 || start_index > end_index)
556 s_data.
operands().begin(), numeric_cast_v<std::size_t>(start_index)),
558 s_data.
operands().begin(), numeric_cast_v<std::size_t>(end_index)));
560 const array_exprt new_char_array(std::move(operands), new_char_array_type);
566 new_char_array_length,
583 const std::size_t num_operands = f_l1.
arguments().size();
589 const auto &length_type = f_type.
domain().at(0);
592 const auto &integer_opt =
600 const mp_integer integer = numeric_cast_v<mp_integer>(integer_opt->get());
604 if(num_operands == 4)
606 const auto &base_constant_opt =
609 if(!base_constant_opt)
614 const auto base_opt = numeric_cast<unsigned>(base_constant_opt->get());
636 std::back_inserter(operands),
637 [&
char_type](
const char c) { return from_integer(tolower(c), char_type); });
639 const array_exprt new_char_array(std::move(operands), new_char_array_type);
645 new_char_array_length,
665 const auto &length_type = f_type.
domain().at(0);
685 const mp_integer index = numeric_cast_v<mp_integer>(index_opt->get());
687 if(index < 0 || index >= s_data.
operands().size())
698 operands.reserve(s_data.
operands().size() - 1);
700 const std::size_t i = numeric_cast_v<std::size_t>(index);
705 std::next(s_data.
operands().begin(), i));
709 std::next(s_data.
operands().begin(), i + 1),
712 const array_exprt new_char_array(std::move(operands), new_char_array_type);
718 new_char_array_length,
739 const auto &length_type = f_type.
domain().at(0);
759 const mp_integer start = numeric_cast_v<mp_integer>(start_opt->get());
761 if(start < 0 || start > s_data.
operands().size())
773 const mp_integer end = numeric_cast_v<mp_integer>(end_opt->get());
780 const std::size_t start_index = numeric_cast_v<std::size_t>(start);
782 const std::size_t end_index =
783 std::min(numeric_cast_v<std::size_t>(end), s_data.
operands().size());
785 const std::size_t new_size =
786 s_data.
operands().size() - end_index + start_index;
794 operands.reserve(new_size);
799 std::next(s_data.
operands().begin(), start_index));
803 std::next(s_data.
operands().begin(), end_index),
806 const array_exprt new_char_array(std::move(operands), new_char_array_type);
812 new_char_array_length,
832 const auto &length_type = f_type.
domain().at(0);
835 const auto &new_length_opt =
844 numeric_cast_v<mp_integer>(new_length_opt->get());
851 const std::size_t new_size = numeric_cast_v<std::size_t>(new_length);
862 operands.reserve(new_size);
879 std::min(new_size, s_data.
operands().size())));
883 new_size - std::min(new_size, s_data.
operands().size()),
887 const array_exprt new_char_array(std::move(operands), new_char_array_type);
893 new_char_array_length,
914 const auto &length_type = f_type.
domain().at(0);
934 const mp_integer index = numeric_cast_v<mp_integer>(index_opt->get());
936 if(index < 0 || index >= s_data.
operands().size())
941 const auto &new_char_opt =
954 s_data.
operands()[numeric_cast_v<std::size_t>(index)] = new_char_opt->get();
957 std::move(s_data.
operands()), new_char_array_type);
963 new_char_array_length,
977 const auto &length_type = f_type.
domain().at(0);
988 auto &operands = string_data.
operands();
989 for(
auto &operand : operands)
992 auto character = numeric_cast_v<unsigned int>(constant_value);
1019 const array_exprt new_char_array(std::move(operands), new_char_array_type);
1025 new_char_array_length,
1038 const auto &length_type = f_type.
domain().at(0);
1047 auto &new_data = f_l1.
arguments().at(4);
1048 auto &old_data = f_l1.
arguments().at(3);
1054 bool is_single_character = new_data.type().id() == ID_unsignedbv &&
1055 old_data.type().id() == ID_unsignedbv;
1056 if(is_single_character)
1061 if(!new_char_pointer || !old_char_pointer)
1066 characters_to_find.emplace_back(old_char_pointer->get());
1067 characters_to_replace.emplace_back(new_char_pointer->get());
1074 const auto new_char_array_opt =
1077 const auto old_char_array_opt =
1080 if(!new_char_array_opt || !old_char_array_opt)
1085 characters_to_find = old_char_array_opt->get().operands();
1086 characters_to_replace = new_char_array_opt->get().operands();
1091 auto found_pattern = std::search(
1094 characters_to_find.begin(),
1095 characters_to_find.end());
1098 while(found_pattern != existing_data.
operands().end())
1101 auto match_end = found_pattern + characters_to_find.size();
1104 found_pattern = existing_data.
operands().erase(found_pattern, match_end);
1108 found_pattern = existing_data.
operands().insert(
1110 characters_to_replace.begin(),
1111 characters_to_replace.end()) +
1112 characters_to_replace.size();
1115 found_pattern = std::search(
1118 characters_to_find.begin(),
1119 characters_to_find.end());
1127 std::move(existing_data.
operands()), new_char_array_type);
1133 new_char_array_length,
1146 const auto &length_type = f_type.
domain().at(0);
1155 auto is_not_whitespace = [](
const exprt &expr) {
1157 return character >
' ';
1161 auto &operands = s_data_opt->get().operands();
1163 std::find_if(operands.rbegin(), operands.rend(), is_not_whitespace);
1165 std::find_if(operands.begin(), operands.end(), is_not_whitespace);
1171 if(start_iter != operands.end())
1179 std::move(new_operands), new_char_array_type);
1185 new_char_array_length,
static abstract_object_pointert transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns)
const integer_bitvector_typet & to_integer_bitvector_type(const typet &type)
Cast a typet to an integer_bitvector_typet.
bitvector_typet char_type()
bitvector_typet c_index_type()
Operator to return the address of an object.
Array constructor from list of elements.
const array_typet & type() const
const typet & element_type() const
The type of the elements of the array.
A constant literal expression.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Expression in which some part is missing and can be substituted for another expression.
Base class for all expressions.
std::vector< exprt > operandst
typet & type()
Return the type of the expression.
exprt apply(const namespacet &ns, goto_symex_statet &state, exprt expr, bool write) const
Turn an expression expr into a field-sensitive SSA expression.
bool is_divisible(const ssa_exprt &expr, bool disjoined_fields_only) const
Determine whether expr would translate to an atomic SSA expression (returns false) or a composite obj...
Application of (mathematical) function.
const mathematical_function_typet & function_type() const
This helper method provides the type of the expression returned by function.
unsigned atomic_section_id
Threads.
sharing_mapt< irep_idt, exprt > propagation
Central data structure: state.
exprt l2_rename_rvalues(exprt lvalue, const namespacet &ns)
call_stackt & call_stack()
renamedt< exprt, level > rename(exprt expr, const namespacet &ns)
Rewrites symbol expressions in exprt, applying a suffix to each symbol reflecting its most recent ver...
symbol_tablet symbol_table
contains symbols that are minted during symbolic execution, such as dynamically created objects etc.
field_sensitivityt field_sensitivity
symex_targett::sourcet source
std::vector< threadt > threads
virtual void symex_assume(statet &state, const exprt &cond)
Symbolically execute an ASSUME instruction or simulate such an execution for a synthetic assumption.
virtual void symex_atomic_begin(statet &state)
Symbolically execute an ATOMIC_BEGIN instruction.
bool constant_propagate_delete_char_at(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate deleting a character from a string.
bool constant_propagate_set_char_at(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate setting the char at the given index.
bool constant_propagate_assignment_with_side_effects(statet &state, symex_assignt &symex_assign, const exprt &lhs, const exprt &rhs)
Attempt to constant propagate side effects of the assignment (if any)
bool constant_propagate_delete(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate deleting a substring from a string.
static std::optional< std::reference_wrapper< const constant_exprt > > try_evaluate_constant(const statet &state, const exprt &expr)
void constant_propagate_empty_string(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Create an empty string constant.
symex_target_equationt & target
The equation that this execution is building up.
bool constant_propagate_case_change(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1, bool to_upper)
Attempt to constant propagate case changes, both upper and lower.
virtual void symex_allocate(statet &state, const exprt &lhs, const side_effect_exprt &code)
Symbolically execute an assignment instruction that has an allocate on the right hand side.
bool constant_propagate_integer_to_string(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate converting an integer to a string.
exprt clean_expr(exprt expr, statet &state, bool write)
Clean up an expression.
bool constant_propagate_trim(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate trim operations.
shadow_memoryt shadow_memory
Shadow memory instrumentation API.
virtual void symex_va_start(statet &, const exprt &lhs, const side_effect_exprt &)
namespacet ns
Initialized just before symbolic execution begins, to point to both outer_symbol_table and the symbol...
void symex_assign(statet &state, const exprt &lhs, const exprt &rhs)
Symbolically execute an ASSIGN instruction or simulate such an execution for a synthetic assignment.
const symbolt & get_new_string_data_symbol(statet &state, symex_assignt &symex_assign, const std::string &aux_symbol_name, const ssa_exprt &char_array, const array_exprt &new_char_array)
Installs a new symbol in the symbol table to represent the given character array, and assigns the cha...
void associate_array_to_pointer(statet &state, symex_assignt &symex_assign, const array_exprt &new_char_array, const address_of_exprt &string_data)
Generate array to pointer association primitive.
virtual void do_simplify(exprt &expr)
virtual void symex_cpp_new(statet &state, const exprt &lhs, const side_effect_exprt &code)
Handles side effects of type 'new' for C++ and 'new array' for C++ and Java language modes.
bool constant_propagate_set_length(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate setting the length of a string.
messaget log
The messaget to write log messages to.
const symex_configt symex_config
The configuration to use for this symbolic execution.
bool constant_propagate_string_substring(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate getting a substring of a string.
bool constant_propagate_replace(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant proagate character replacement.
bool constant_propagate_string_concat(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate string concatenation.
virtual void symex_atomic_end(statet &state)
Symbolically execute an ATOMIC_END instruction.
void assign_string_constant(statet &state, symex_assignt &symex_assign, const ssa_exprt &length, const constant_exprt &new_length, const ssa_exprt &char_array, const array_exprt &new_char_array)
Assign constant string length and string data given by a char array to given ssa variables.
std::optional< std::reference_wrapper< const array_exprt > > try_evaluate_constant_string(const statet &state, const exprt &content)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const irep_idt & get(const irep_idt &name) const
void set(const irep_idt &name, const irep_idt &value)
const irep_idt & id() const
typet & codomain()
Return the codomain, i.e., the set of values that the function maps to (the "target").
void conditional_output(mstreamt &mstream, const std::function< void(mstreamt &)> &output_generator) const
Generate output to message_stream using output_generator if the configured verbosity is at least as h...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
const typet & base_type() const
The type of the data what we point to.
const exprt & content() const
An expression containing a side effect.
const irep_idt & get_statement() const
Expression providing an SSA-renamed symbol of expressions.
const exprt & get_original_expr() const
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
exprt value
Initial value of symbol.
irep_idt mode
Language mode.
Functor for symex assignment.
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.
static std::string get_alnum_string(const array_exprt &char_array)
Maps the given array expression containing constant characters to a string containing only alphanumer...
const std::string & id2string(const irep_idt &d)
API to expression classes for 'mathematical' expressions.
const function_application_exprt & to_function_application_expr(const exprt &expr)
Cast an exprt to a function_application_exprt.
const mathematical_function_typet & to_mathematical_function_type(const typet &type)
Cast a typet to a mathematical_function_typet.
const std::string integer2string(const mp_integer &n, unsigned base)
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
bool simplify(exprt &expr, const namespacet &ns)
std::optional< std::reference_wrapper< const array_exprt > > try_get_string_data_array(const exprt &content, const namespacet &ns)
Get char sequence from content field of a refined string expression.
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
#define DATA_INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
const ssa_exprt & to_ssa_expr(const exprt &expr)
Cast a generic exprt to an ssa_exprt.
bool is_ssa_expr(const exprt &expr)
side_effect_exprt & to_side_effect_expr(exprt &expr)
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
String expressions for the string solver.
refined_string_exprt & to_string_expr(exprt &expr)
std::string escape_non_alnum(const std::string &to_escape)
Replace non-alphanumeric characters with _xx escapes, where xx are hex digits.
goto_programt::const_targett pc
Symbolic Execution of assignments.