Go to the documentation of this file.
49 lhs.
type() == rhs.
type(),
"assignments must be type consistent");
53 mstream <<
"Assignment to " << format(lhs) <<
" ["
54 << pointer_offset_bits(lhs.type(), ns).value_or(0) <<
" bits]"
65 if(rhs.
id() == ID_side_effect)
71 statement == ID_cpp_new || statement == ID_cpp_new_array ||
72 statement == ID_java_new_array_data)
76 else if(statement == ID_allocate)
78 else if(statement == ID_va_start)
89 lhs.
id() == ID_symbol &&
101 if(state.
source.
pc->source_location().get_hide())
133 const auto &ibv_type =
136 const std::size_t n_bits = ibv_type.get_width();
139 static_assert(CHAR_BIT == 8,
"bitwidth of char assumed to be 8");
141 const std::size_t n_chars = n_bits / 8;
144 sizeof(std::size_t) >= n_chars,
145 "size_t shall be large enough to represent a character");
149 for(
const auto &c : char_array.
operands())
153 for(std::size_t i = 0; i < n_chars; i++)
155 const char c_chunk =
static_cast<char>((c_val >> (i * 8)) & 0xff);
156 result.push_back(c_chunk);
169 if(rhs.
id() == ID_function_application)
178 if(func_id == ID_cprover_string_concat_func)
182 else if(func_id == ID_cprover_string_empty_string_func)
189 else if(func_id == ID_cprover_string_substring_func)
194 func_id == ID_cprover_string_of_int_func ||
195 func_id == ID_cprover_string_of_long_func)
199 else if(func_id == ID_cprover_string_delete_char_at_func)
203 else if(func_id == ID_cprover_string_delete_func)
207 else if(func_id == ID_cprover_string_set_length_func)
211 else if(func_id == ID_cprover_string_char_set_func)
215 else if(func_id == ID_cprover_string_trim_func)
219 else if(func_id == ID_cprover_string_to_lower_case_func)
223 else if(func_id == ID_cprover_string_to_upper_case_func)
227 else if(func_id == ID_cprover_string_replace_func)
253 const std::string aux_symbol_name =
256 const bool string_constant_exists =
260 string_constant_exists
263 state,
symex_assign, aux_symbol_name, char_array, new_char_array);
266 aux_symbol.
value == new_char_array,
267 "symbol shall have value derived from char array content");
274 if(!string_constant_exists)
284 const std::string &aux_symbol_name,
289 new_char_array_type.
set(ID_C_constant,
true);
307 new_aux_symbol.
value = new_char_array;
314 return new_aux_symbol;
323 const symbolt &function_symbol =
324 ns.
lookup(ID_cprover_associate_array_to_pointer_func);
327 function_symbol.
symbol_expr(), {new_char_array, string_data}};
334 function_symbol.
mode,
347 const exprt &content)
349 if(content.
id() != ID_symbol)
354 const auto s_pointer_opt =
368 if(expr.
id() != ID_symbol)
373 const auto constant_expr_opt =
376 if(!constant_expr_opt || constant_expr_opt->get().id() != ID_constant)
391 const auto &length_type = f_type.
domain().at(0);
400 "empty string primitive requires two output arguments");
419 const auto &length_type = f_type.
domain().at(0);
438 const std::size_t new_size =
450 const array_exprt new_char_array(std::move(operands), new_char_array_type);
456 new_char_array_length,
468 const std::size_t num_operands = f_l1.
arguments().size();
474 const auto &length_type = f_type.
domain().at(0);
487 if(num_operands == 5)
489 const auto end_index_expr_opt =
492 if(!end_index_expr_opt)
500 if(end_index < 0 || end_index > s_data.
operands().size())
507 end_index = s_data.
operands().size();
510 const auto start_index_expr_opt =
513 if(!start_index_expr_opt)
521 if(start_index < 0 || start_index > end_index)
533 s_data.
operands().begin(), numeric_cast_v<std::size_t>(start_index)),
535 s_data.
operands().begin(), numeric_cast_v<std::size_t>(end_index)));
537 const array_exprt new_char_array(std::move(operands), new_char_array_type);
543 new_char_array_length,
560 const std::size_t num_operands = f_l1.
arguments().size();
566 const auto &length_type = f_type.
domain().at(0);
569 const auto &integer_opt =
577 const mp_integer integer = numeric_cast_v<mp_integer>(integer_opt->get());
581 if(num_operands == 4)
583 const auto &base_constant_opt =
586 if(!base_constant_opt)
591 const auto base_opt = numeric_cast<unsigned>(base_constant_opt->get());
613 std::back_inserter(operands),
614 [&
char_type](
const char c) { return from_integer(tolower(c), char_type); });
616 const array_exprt new_char_array(std::move(operands), new_char_array_type);
622 new_char_array_length,
642 const auto &length_type = f_type.
domain().at(0);
662 const mp_integer index = numeric_cast_v<mp_integer>(index_opt->get());
664 if(index < 0 || index >= s_data.
operands().size())
675 operands.reserve(s_data.
operands().size() - 1);
677 const std::size_t i = numeric_cast_v<std::size_t>(index);
682 std::next(s_data.
operands().begin(), i));
686 std::next(s_data.
operands().begin(), i + 1),
689 const array_exprt new_char_array(std::move(operands), new_char_array_type);
695 new_char_array_length,
716 const auto &length_type = f_type.
domain().at(0);
736 const mp_integer start = numeric_cast_v<mp_integer>(start_opt->get());
738 if(start < 0 || start > s_data.
operands().size())
750 const mp_integer end = numeric_cast_v<mp_integer>(end_opt->get());
757 const std::size_t start_index = numeric_cast_v<std::size_t>(start);
759 const std::size_t end_index =
760 std::min(numeric_cast_v<std::size_t>(end), s_data.
operands().size());
762 const std::size_t new_size =
763 s_data.
operands().size() - end_index + start_index;
771 operands.reserve(new_size);
776 std::next(s_data.
operands().begin(), start_index));
780 std::next(s_data.
operands().begin(), end_index),
783 const array_exprt new_char_array(std::move(operands), new_char_array_type);
789 new_char_array_length,
809 const auto &length_type = f_type.
domain().at(0);
812 const auto &new_length_opt =
821 numeric_cast_v<mp_integer>(new_length_opt->get());
828 const std::size_t new_size = numeric_cast_v<std::size_t>(new_length);
839 operands.reserve(new_size);
856 std::min(new_size, s_data.
operands().size())));
860 new_size - std::min(new_size, s_data.
operands().size()),
864 const array_exprt new_char_array(std::move(operands), new_char_array_type);
870 new_char_array_length,
891 const auto &length_type = f_type.
domain().at(0);
911 const mp_integer index = numeric_cast_v<mp_integer>(index_opt->get());
913 if(index < 0 || index >= s_data.
operands().size())
918 const auto &new_char_opt =
931 s_data.
operands()[numeric_cast_v<std::size_t>(index)] = new_char_opt->get();
934 std::move(s_data.
operands()), new_char_array_type);
940 new_char_array_length,
954 const auto &length_type = f_type.
domain().at(0);
965 auto &operands = string_data.
operands();
966 for(
auto &operand : operands)
969 auto character = numeric_cast_v<unsigned int>(constant_value);
975 if(isalpha(character))
979 if(islower(character))
981 from_integer(toupper(character), constant_value.type());
985 if(isupper(character))
987 from_integer(tolower(character), constant_value.type());
996 const array_exprt new_char_array(std::move(operands), new_char_array_type);
1002 new_char_array_length,
1015 const auto &length_type = f_type.
domain().at(0);
1024 auto &new_data = f_l1.
arguments().at(4);
1025 auto &old_data = f_l1.
arguments().at(3);
1031 bool is_single_character = new_data.type().id() == ID_unsignedbv &&
1032 old_data.type().id() == ID_unsignedbv;
1033 if(is_single_character)
1038 if(!new_char_pointer || !old_char_pointer)
1043 characters_to_find.emplace_back(old_char_pointer->get());
1044 characters_to_replace.emplace_back(new_char_pointer->get());
1051 const auto new_char_array_opt =
1054 const auto old_char_array_opt =
1057 if(!new_char_array_opt || !old_char_array_opt)
1062 characters_to_find = old_char_array_opt->get().operands();
1063 characters_to_replace = new_char_array_opt->get().operands();
1068 auto found_pattern = std::search(
1071 characters_to_find.begin(),
1072 characters_to_find.end());
1075 while(found_pattern != existing_data.
operands().end())
1078 auto match_end = found_pattern + characters_to_find.size();
1081 found_pattern = existing_data.
operands().erase(found_pattern, match_end);
1085 found_pattern = existing_data.
operands().insert(
1087 characters_to_replace.begin(),
1088 characters_to_replace.end()) +
1089 characters_to_replace.size();
1092 found_pattern = std::search(
1095 characters_to_find.begin(),
1096 characters_to_find.end());
1104 std::move(existing_data.
operands()), new_char_array_type);
1110 new_char_array_length,
1123 const auto &length_type = f_type.
domain().at(0);
1132 auto is_not_whitespace = [](
const exprt &expr) {
1134 return character >
' ';
1138 auto &operands = s_data_opt->get().operands();
1140 std::find_if(operands.rbegin(), operands.rend(), is_not_whitespace);
1142 std::find_if(operands.begin(), operands.end(), is_not_whitespace);
1148 if(start_iter != operands.end())
1156 std::move(new_operands), new_char_array_type);
1162 new_char_array_length,
#define UNREACHABLE
This should be used to mark dead code.
exprt clean_expr(exprt expr, statet &state, bool write)
Clean up an expression.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
static unsigned dynamic_counter
A monotonically increasing index for each created dynamic object.
optionalt< std::reference_wrapper< const array_exprt > > try_evaluate_constant_string(const statet &state, const exprt &content)
#define CHECK_RETURN(CONDITION)
std::string escape_non_alnum(const std::string &to_escape)
Replace non-alphanumeric characters with _xx escapes, where xx are hex digits.
refined_string_exprt & to_string_expr(exprt &expr)
exprt l2_rename_rvalues(exprt lvalue, const namespacet &ns)
goto_programt::const_targett pc
static abstract_object_pointert transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns)
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.
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.
symex_target_equationt & target
The equation that this execution is building up.
typet type
Type of symbol.
Central data structure: state.
const integer_bitvector_typet & to_integer_bitvector_type(const typet &type)
Cast a typet to an integer_bitvector_typet.
bool constant_propagate_trim(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate trim operations.
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.
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.
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...
const mathematical_function_typet & to_mathematical_function_type(const typet &type)
Cast a typet to a mathematical_function_typet.
Base class for all expressions.
symex_targett::sourcet source
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.
Functor for symex assignment.
side_effect_exprt & to_side_effect_expr(exprt &expr)
optionalt< 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.
exprt apply(const namespacet &ns, goto_symex_statet &state, exprt expr, bool write) const
Turn an expression expr into a field-sensitive SSA expression.
const exprt & get_original_expr() const
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.
const irep_idt & get(const irep_idt &name) const
sharing_mapt< irep_idt, exprt > propagation
messaget log
The messaget to write log messages to.
Expression providing an SSA-renamed symbol of expressions.
const mathematical_function_typet & function_type() const
This helper method provides the type of the expression returned by function.
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
const array_typet & type() const
std::vector< threadt > threads
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.
bool constant_propagate_string_concat(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant propagate string concatenation.
call_stackt & call_stack()
irep_idt mode
Language mode.
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.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
const ssa_exprt & to_ssa_expr(const exprt &expr)
Cast a generic exprt to an ssa_exprt.
const std::string & id2string(const irep_idt &d)
symbol_tablet symbol_table
contains symbols that are minted during symbolic execution, such as dynamically created objects etc.
static optionalt< smt_termt > get_identifier(const exprt &expr, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_handle_identifiers, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_identifiers)
void constant_propagate_empty_string(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Create an empty string constant.
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.
void set(const irep_idt &name, const irep_idt &value)
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.
#define PRECONDITION(CONDITION)
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.
typet & codomain()
Return the codomain, i.e., the set of values that the function maps to (the "target").
const irep_idt & get_identifier() const
virtual void symex_va_start(statet &, const exprt &lhs, const side_effect_exprt &)
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...
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
bool simplify(exprt &expr, const namespacet &ns)
Application of (mathematical) function.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
std::vector< exprt > operandst
nonstd::optional< T > optionalt
virtual void do_simplify(exprt &expr)
field_sensitivityt field_sensitivity
const irep_idt & get_statement() const
bitvector_typet char_type()
namespacet ns
Initialized just before symbolic execution begins, to point to both outer_symbol_table and the symbol...
exprt value
Initial value of symbol.
const exprt & content() const
virtual void symex_assume(statet &state, const exprt &cond)
Symbolically execute an ASSUME instruction or simulate such an execution for a synthetic assumption.
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...
const symex_configt symex_config
The configuration to use for this symbolic execution.
const typet & base_type() const
The type of the data what we point to.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
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)
static optionalt< std::reference_wrapper< const constant_exprt > > try_evaluate_constant(const statet &state, const exprt &expr)
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...
Operator to return the address of an object.
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
A constant literal expression.
bitvector_typet c_index_type()
bool constant_propagate_replace(statet &state, symex_assignt &symex_assign, const function_application_exprt &f_l1)
Attempt to constant proagate character replacement.
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.
Array constructor from list of elements.
const function_application_exprt & to_function_application_expr(const exprt &expr)
Cast an exprt to a function_application_exprt.
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 ...
An expression containing a side effect.
Expression in which some part is missing and can be substituted for another expression.
const typet & element_type() const
The type of the elements of the array.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const std::string integer2string(const mp_integer &n, unsigned base)