CBMC
string_refinement.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: String support via creating string constraints and progressively
4  instantiating the universal constraints as needed.
5  The procedure is described in the PASS paper at HVC'13:
6  "PASS: String Solving with Parameterized Array and Interval Automaton"
7  by Guodong Li and Indradeep Ghosh.
8 
9 Author: Alberto Griggio, alberto.griggio@gmail.com
10 
11 \*******************************************************************/
12 
19 
20 #include "string_refinement.h"
21 
22 #include <solvers/sat/satcheck.h>
23 #include <stack>
24 #include <unordered_set>
25 
26 #include <util/expr_iterator.h>
27 #include <util/expr_util.h>
28 #include <util/format_type.h>
29 #include <util/magic.h>
30 #include <util/range.h>
31 #include <util/simplify_expr.h>
32 
35 #include "string_dependencies.h"
37 
39  messaget::mstreamt &stream,
40  const namespacet &ns,
41  const string_constraintt &constraint);
42 
43 static std::optional<exprt> find_counter_example(
44  const namespacet &ns,
45  const exprt &axiom,
46  const symbol_exprt &var,
47  message_handlert &message_handler);
48 
65 static std::pair<bool, std::vector<exprt>> check_axioms(
66  const string_axiomst &axioms,
68  const std::function<exprt(const exprt &)> &get,
69  messaget::mstreamt &stream,
70  const namespacet &ns,
71  bool use_counter_example,
72  const union_find_replacet &symbol_resolve,
73  const std::unordered_map<string_not_contains_constraintt, symbol_exprt>
74  &not_contain_witnesses);
75 
76 static void initial_index_set(
77  index_set_pairt &index_set,
78  const namespacet &ns,
79  const string_constraintt &axiom);
80 
81 static void initial_index_set(
82  index_set_pairt &index_set,
83  const namespacet &ns,
84  const string_not_contains_constraintt &axiom);
85 
86 static void initial_index_set(
87  index_set_pairt &index_set,
88  const namespacet &ns,
89  const string_axiomst &axioms);
90 
91 exprt simplify_sum(const exprt &f);
92 
93 static void update_index_set(
94  index_set_pairt &index_set,
95  const namespacet &ns,
96  const std::vector<exprt> &current_constraints);
97 
98 static void update_index_set(
99  index_set_pairt &index_set,
100  const namespacet &ns,
101  const exprt &formula);
102 
103 static std::vector<exprt> instantiate(
104  const string_not_contains_constraintt &axiom,
105  const index_set_pairt &index_set,
106  const std::unordered_map<string_not_contains_constraintt, symbol_exprt>
107  &witnesses);
108 
109 static std::optional<exprt> get_array(
110  const std::function<exprt(const exprt &)> &super_get,
111  const namespacet &ns,
112  messaget::mstreamt &stream,
113  const array_string_exprt &arr,
114  const array_poolt &array_pool);
115 
116 static std::optional<exprt> substitute_array_access(
117  const index_exprt &index_expr,
118  symbol_generatort &symbol_generator,
119  const bool left_propagate);
120 
128 template <typename T>
129 static std::vector<T>
130 fill_in_map_as_vector(const std::map<std::size_t, T> &index_value)
131 {
132  std::vector<T> result;
133  if(!index_value.empty())
134  {
135  result.resize(index_value.rbegin()->first + 1);
136  for(auto it = index_value.rbegin(); it != index_value.rend(); ++it)
137  {
138  const std::size_t index = it->first;
139  const T &value = it->second;
140  const auto next = std::next(it);
141  const std::size_t leftmost_index_to_pad =
142  next != index_value.rend() ? next->first + 1 : 0;
143  for(std::size_t j = leftmost_index_to_pad; j <= index; j++)
144  result[j] = value;
145  }
146  }
147  return result;
148 }
149 
150 static bool validate(const string_refinementt::infot &info)
151 {
152  PRECONDITION(info.ns);
153  PRECONDITION(info.prop);
154  return true;
155 }
156 
158  : supert(info),
159  config_(info),
160  loop_bound_(info.refinement_bound),
161  generator(*info.ns, *info.message_handler)
162 {
163 }
164 
166  : string_refinementt(info, validate(info))
167 {
168 }
169 
171 static void
173 {
174  std::size_t count = 0;
175  std::size_t count_current = 0;
176  for(const auto &i : index_set.cumulative)
177  {
178  const exprt &s = i.first;
179  stream << "IS(" << format(s) << ")=={" << messaget::eom;
180 
181  for(const auto &j : i.second)
182  {
183  const auto it = index_set.current.find(i.first);
184  if(
185  it != index_set.current.end() && it->second.find(j) != it->second.end())
186  {
187  count_current++;
188  stream << "**";
189  }
190  stream << " " << format(j) << ";" << messaget::eom;
191  count++;
192  }
193  stream << "}" << messaget::eom;
194  }
195  stream << count << " elements in index set (" << count_current
196  << " newly added)" << messaget::eom;
197 }
198 
220 static std::vector<exprt> generate_instantiations(
221  const index_set_pairt &index_set,
222  const string_axiomst &axioms,
223  const std::unordered_map<string_not_contains_constraintt, symbol_exprt>
224  &not_contain_witnesses)
225 {
226  std::vector<exprt> lemmas;
227  for(const auto &i : index_set.current)
228  {
229  for(const auto &univ_axiom : axioms.universal)
230  {
231  for(const auto &j : i.second)
232  lemmas.push_back(instantiate(univ_axiom, i.first, j));
233  }
234  }
235  for(const auto &nc_axiom : axioms.not_contains)
236  {
237  for(const auto &instance :
238  instantiate(nc_axiom, index_set, not_contain_witnesses))
239  lemmas.push_back(instance);
240  }
241  return lemmas;
242 }
243 
248  string_constraint_generatort &generator,
249  exprt &expr)
250 {
251  if(const auto equal_expr = expr_try_dynamic_cast<equal_exprt>(expr))
252  {
253  if(
254  const auto fun_app = expr_try_dynamic_cast<function_application_exprt>(
255  as_const(equal_expr->rhs())))
256  {
257  const auto new_equation =
258  generator.make_array_pointer_association(equal_expr->lhs(), *fun_app);
259  if(new_equation)
260  {
261  expr =
262  equal_exprt{from_integer(true, new_equation->type()), *new_equation};
263  }
264  }
265  }
266 }
267 
272 static exprt
273 replace_expr_copy(const union_find_replacet &symbol_resolve, exprt expr)
274 {
275  symbol_resolve.replace_expr(expr);
276  return expr;
277 }
278 
283 void string_refinementt::set_to(const exprt &expr, bool value)
284 {
285  PRECONDITION(expr.is_boolean());
287  if(!value)
288  equations.push_back(not_exprt{expr});
289  else
290  equations.push_back(expr);
291 }
292 
301  union_find_replacet &symbol_solver,
302  const std::vector<exprt> &equations,
303  const namespacet &ns,
304  messaget::mstreamt &stream)
305 {
306  const std::string log_message =
307  "WARNING string_refinement.cpp generate_symbol_resolution_from_equations:";
308  auto equalities = make_range(equations).filter(
309  [&](const exprt &e) { return can_cast_expr<equal_exprt>(e); });
310  for(const exprt &e : equalities)
311  {
312  const equal_exprt &eq = to_equal_expr(e);
313  const exprt &lhs = to_equal_expr(eq).lhs();
314  const exprt &rhs = to_equal_expr(eq).rhs();
315  if(lhs.id() != ID_symbol)
316  {
317  stream << log_message << "non symbol lhs: " << format(lhs)
318  << " with rhs: " << format(rhs) << messaget::eom;
319  continue;
320  }
321 
322  if(lhs.type() != rhs.type())
323  {
324  stream << log_message << "non equal types lhs: " << format(lhs)
325  << "\n####################### rhs: " << format(rhs)
326  << messaget::eom;
327  continue;
328  }
329 
330  if(is_char_pointer_type(rhs.type()))
331  {
332  symbol_solver.make_union(lhs, simplify_expr(rhs, ns));
333  }
334  else if(rhs.id() == ID_function_application)
335  {
336  // function applications can be ignored because they will be replaced
337  // in the convert_function_application step of dec_solve
338  }
339  else if(
340  lhs.type().id() != ID_pointer && has_char_pointer_subtype(lhs.type(), ns))
341  {
342  if(rhs.type().id() == ID_struct || rhs.type().id() == ID_struct_tag)
343  {
344  const struct_typet &struct_type = to_struct_type(ns.follow(rhs.type()));
345  for(const auto &comp : struct_type.components())
346  {
347  if(is_char_pointer_type(comp.type()))
348  {
349  const member_exprt lhs_data(lhs, comp.get_name(), comp.type());
350  const exprt rhs_data = simplify_expr(
351  member_exprt(rhs, comp.get_name(), comp.type()), ns);
352  symbol_solver.make_union(lhs_data, rhs_data);
353  }
354  }
355  }
356  else
357  {
358  stream << log_message << "non struct with char pointer subexpr "
359  << format(rhs) << "\n * of type " << format(rhs.type())
360  << messaget::eom;
361  }
362  }
363  }
364 }
365 
372 static std::vector<exprt>
374 {
375  std::vector<exprt> result;
376  if(lhs.type() == string_typet())
377  result.push_back(lhs);
378  else if(lhs.type().id() == ID_struct || lhs.type().id() == ID_struct_tag)
379  {
380  const struct_typet &struct_type = to_struct_type(ns.follow(lhs.type()));
381  for(const auto &comp : struct_type.components())
382  {
383  const std::vector<exprt> strings_in_comp = extract_strings_from_lhs(
384  member_exprt(lhs, comp.get_name(), comp.type()), ns);
385  result.insert(
386  result.end(), strings_in_comp.begin(), strings_in_comp.end());
387  }
388  }
389  return result;
390 }
391 
397 static std::vector<exprt>
398 extract_strings(const exprt &expr, const namespacet &ns)
399 {
400  std::vector<exprt> result;
401  for(auto it = expr.depth_begin(); it != expr.depth_end();)
402  {
403  if(it->type() == string_typet() && it->id() != ID_if)
404  {
405  result.push_back(*it);
406  it.next_sibling_or_parent();
407  }
408  else if(it->id() == ID_symbol)
409  {
410  for(const exprt &e : extract_strings_from_lhs(*it, ns))
411  result.push_back(e);
412  it.next_sibling_or_parent();
413  }
414  else
415  ++it;
416  }
417  return result;
418 }
419 
427  const equal_exprt &eq,
428  union_find_replacet &symbol_resolve,
429  const namespacet &ns)
430 {
431  if(eq.rhs().type() == string_typet())
432  {
433  symbol_resolve.make_union(eq.lhs(), simplify_expr(eq.rhs(), ns));
434  }
435  else if(has_subtype(eq.lhs().type(), ID_string, ns))
436  {
437  if(
438  eq.rhs().type().id() == ID_struct ||
439  eq.rhs().type().id() == ID_struct_tag)
440  {
441  const struct_typet &struct_type =
442  to_struct_type(ns.follow(eq.rhs().type()));
443  for(const auto &comp : struct_type.components())
444  {
445  const member_exprt lhs_data(eq.lhs(), comp.get_name(), comp.type());
446  const exprt rhs_data = simplify_expr(
447  member_exprt(eq.rhs(), comp.get_name(), comp.type()), ns);
449  equal_exprt(lhs_data, rhs_data), symbol_resolve, ns);
450  }
451  }
452  }
453 }
454 
463  const std::vector<equal_exprt> &equations,
464  const namespacet &ns,
465  messaget::mstreamt &stream)
466 {
467  const std::string log_message =
468  "WARNING string_refinement.cpp "
469  "string_identifiers_resolution_from_equations:";
470 
471  equation_symbol_mappingt equation_map;
472 
473  // Indexes of equations that need to be added to the result
474  std::unordered_set<size_t> required_equations;
475  std::stack<size_t> equations_to_treat;
476 
477  for(std::size_t i = 0; i < equations.size(); ++i)
478  {
479  const equal_exprt &eq = equations[i];
480  if(eq.rhs().id() == ID_function_application)
481  {
482  if(required_equations.insert(i).second)
483  equations_to_treat.push(i);
484 
485  std::vector<exprt> rhs_strings = extract_strings(eq.rhs(), ns);
486  for(const auto &expr : rhs_strings)
487  equation_map.add(i, expr);
488  }
489  else if(
490  eq.lhs().type().id() != ID_pointer &&
491  has_subtype(eq.lhs().type(), ID_string, ns))
492  {
493  std::vector<exprt> lhs_strings = extract_strings_from_lhs(eq.lhs(), ns);
494 
495  for(const auto &expr : lhs_strings)
496  equation_map.add(i, expr);
497 
498  if(lhs_strings.empty())
499  {
500  stream << log_message << "non struct with string subtype "
501  << format(eq.lhs()) << "\n * of type "
502  << format(eq.lhs().type()) << messaget::eom;
503  }
504 
505  for(const exprt &expr : extract_strings(eq.rhs(), ns))
506  equation_map.add(i, expr);
507  }
508  }
509 
510  // transitively add all equations which depend on the equations to treat
511  while(!equations_to_treat.empty())
512  {
513  const std::size_t i = equations_to_treat.top();
514  equations_to_treat.pop();
515  for(const exprt &string : equation_map.find_expressions(i))
516  {
517  for(const std::size_t j : equation_map.find_equations(string))
518  {
519  if(required_equations.insert(j).second)
520  equations_to_treat.push(j);
521  }
522  }
523  }
524 
525  union_find_replacet result;
526  for(const std::size_t i : required_equations)
527  add_string_equation_to_symbol_resolution(equations[i], result, ns);
528 
529  return result;
530 }
531 
532 #ifdef DEBUG
534 static void
535 output_equations(std::ostream &output, const std::vector<exprt> &equations)
536 {
537  for(std::size_t i = 0; i < equations.size(); ++i)
538  output << " [" << i << "] " << format(equations[i]) << std::endl;
539 }
540 #endif
541 
552 // NOLINTNEXTLINE
555 // NOLINTNEXTLINE
560 // NOLINTNEXTLINE
608 {
609 #ifdef DEBUG
610  log.debug() << "dec_solve: Initial set of equations" << messaget::eom;
611  output_equations(log.debug(), equations);
612 #endif
613 
614  log.debug() << "dec_solve: Build symbol solver from equations"
615  << messaget::eom;
616  // symbol_resolve is used by get and is kept between calls to dec_solve,
617  // that's why we use a class member here
620 #ifdef DEBUG
621  log.debug() << "symbol resolve:" << messaget::eom;
622  for(const auto &pair : symbol_resolve.to_vector())
623  log.debug() << format(pair.first) << " --> " << format(pair.second)
624  << messaget::eom;
625 #endif
626 
627  const union_find_replacet string_id_symbol_resolve =
629  [&] {
630  std::vector<equal_exprt> equalities;
631  for(const auto &eq : equations)
632  {
633  if(auto equal_expr = expr_try_dynamic_cast<equal_exprt>(eq))
634  equalities.push_back(*equal_expr);
635  }
636  return equalities;
637  }(),
638  ns,
639  log.debug());
640 #ifdef DEBUG
641  log.debug() << "symbol resolve string:" << messaget::eom;
642  for(const auto &pair : string_id_symbol_resolve.to_vector())
643  {
644  log.debug() << format(pair.first) << " --> " << format(pair.second)
645  << messaget::eom;
646  }
647 #endif
648 
649  log.debug() << "dec_solve: Replacing string ids and simplifying arguments"
650  " in function applications"
651  << messaget::eom;
652  for(exprt &expr : equations)
653  {
654  auto it = expr.depth_begin();
655  while(it != expr.depth_end())
656  {
658  {
659  // Simplification is required because the array pool may not realize
660  // that an expression like
661  // `(unsignedbv[16]*)((signedbv[8]*)&constarray[0] + 0)` is the
662  // same pointer as `&constarray[0]
663  simplify(it.mutate(), ns);
664  string_id_symbol_resolve.replace_expr(it.mutate());
665  it.next_sibling_or_parent();
666  }
667  else
668  ++it;
669  }
670  }
671 
672  // Constraints start clear at each `dec_solve` call.
673  string_constraintst constraints;
674  for(auto &expr : equations)
676 
677 #ifdef DEBUG
678  output_equations(log.debug(), equations);
679 #endif
680 
681  log.debug() << "dec_solve: compute dependency graph and remove function "
682  << "applications captured by the dependencies:" << messaget::eom;
683  std::vector<exprt> local_equations;
684  for(const exprt &eq : equations)
685  {
686  // Ensures that arrays that are equal, are associated to the same nodes
687  // in the graph.
688  const exprt eq_with_char_array_replaced_with_representative_elements =
690  const std::optional<exprt> new_equation = add_node(
691  dependencies,
692  eq_with_char_array_replaced_with_representative_elements,
695  if(new_equation)
696  local_equations.push_back(*new_equation);
697  else
698  local_equations.push_back(eq);
699  }
700  equations.clear();
701 
702 #ifdef DEBUG
704 #endif
705 
706  log.debug() << "dec_solve: add constraints" << messaget::eom;
707  merge(
708  constraints,
710 
711 #ifdef DEBUG
712  output_equations(log.debug(), equations);
713 #endif
714 
715 #ifdef DEBUG
716  log.debug() << "dec_solve: arrays_of_pointers:" << messaget::eom;
717  for(auto pair : generator.array_pool.get_arrays_of_pointers())
718  {
719  log.debug() << " * " << format(pair.first) << "\t--> "
720  << format(pair.second) << " : " << format(pair.second.type())
721  << messaget::eom;
722  }
723 #endif
724 
725  for(const auto &eq : local_equations)
726  {
727 #ifdef DEBUG
728  log.debug() << "dec_solve: set_to " << format(eq) << messaget::eom;
729 #endif
730  supert::set_to(eq, true);
731  }
732 
734  constraints.universal.begin(),
735  constraints.universal.end(),
736  std::back_inserter(axioms.universal),
737  [&](string_constraintt constraint) {
738  constraint.replace_expr(symbol_resolve);
739  DATA_INVARIANT(
740  is_valid_string_constraint(log.error(), ns, constraint),
741  string_refinement_invariantt(
742  "string constraints satisfy their invariant"));
743  return constraint;
744  });
745 
747  constraints.not_contains.begin(),
748  constraints.not_contains.end(),
749  std::back_inserter(axioms.not_contains),
751  replace(symbol_resolve, axiom);
752  return axiom;
753  });
754 
755  // Used to store information about witnesses for not_contains constraints
756  std::unordered_map<string_not_contains_constraintt, symbol_exprt>
757  not_contain_witnesses;
758  for(const auto &nc_axiom : axioms.not_contains)
759  {
760  const auto &witness_type = [&] {
761  const auto &rtype = to_array_type(nc_axiom.s0.type());
762  const typet &index_type = rtype.size().type();
763  return array_typet(index_type, infinity_exprt(index_type));
764  }();
765  not_contain_witnesses.emplace(
766  nc_axiom, generator.fresh_symbol("not_contains_witness", witness_type));
767  }
768 
769  for(const exprt &lemma : constraints.existential)
770  {
772  }
773 
774  // All generated strings should have non-negative length
775  for(const auto &pair : generator.array_pool.created_strings())
776  {
777  exprt length = generator.array_pool.get_or_create_length(pair.first);
778  add_lemma(
779  binary_relation_exprt{length, ID_ge, from_integer(0, length.type())});
780  }
781 
782  // Initial try without index set
783  const auto get = [this](const exprt &expr) { return this->get(expr); };
785  const decision_proceduret::resultt initial_result =
787  if(initial_result == resultt::D_SATISFIABLE)
788  {
789  bool satisfied;
790  std::vector<exprt> counter_examples;
791  std::tie(satisfied, counter_examples) = check_axioms(
792  axioms,
793  generator,
794  get,
795  log.debug(),
796  ns,
799  not_contain_witnesses);
800  if(satisfied)
801  {
802  log.debug() << "check_SAT: the model is correct" << messaget::eom;
803  return resultt::D_SATISFIABLE;
804  }
805  log.debug() << "check_SAT: got SAT but the model is not correct"
806  << messaget::eom;
807  }
808  else
809  {
810  log.debug() << "check_SAT: got UNSAT or ERROR" << messaget::eom;
811  return initial_result;
812  }
813 
816  current_constraints.clear();
817  const auto initial_instances =
818  generate_instantiations(index_sets, axioms, not_contain_witnesses);
819  for(const auto &instance : initial_instances)
820  {
822  }
823 
824  while((loop_bound_--) > 0)
825  {
827  const decision_proceduret::resultt refined_result =
829 
830  if(refined_result == resultt::D_SATISFIABLE)
831  {
832  bool satisfied;
833  std::vector<exprt> counter_examples;
834  std::tie(satisfied, counter_examples) = check_axioms(
835  axioms,
836  generator,
837  get,
838  log.debug(),
839  ns,
842  not_contain_witnesses);
843  if(satisfied)
844  {
845  log.debug() << "check_SAT: the model is correct" << messaget::eom;
846  return resultt::D_SATISFIABLE;
847  }
848 
849  log.debug()
850  << "check_SAT: got SAT but the model is not correct, refining..."
851  << messaget::eom;
852 
853  // Since the model is not correct although we got SAT, we need to refine
854  // the property we are checking by adding more indices to the index set,
855  // and instantiating universal formulas with this indices.
856  // We will then relaunch the solver with these added lemmas.
857  index_sets.current.clear();
859 
861 
862  if(index_sets.current.empty())
863  {
864  if(axioms.not_contains.empty())
865  {
866  log.error() << "dec_solve: current index set is empty, "
867  << "this should not happen" << messaget::eom;
868  return resultt::D_ERROR;
869  }
870  else
871  {
872  log.debug() << "dec_solve: current index set is empty, "
873  << "adding counter examples" << messaget::eom;
874  for(const auto &counter : counter_examples)
875  add_lemma(counter);
876  }
877  }
878  current_constraints.clear();
879  const auto instances =
880  generate_instantiations(index_sets, axioms, not_contain_witnesses);
881  for(const auto &instance : instances)
882  add_lemma(
884  }
885  else
886  {
887  log.debug() << "check_SAT: default return "
888  << static_cast<int>(refined_result) << messaget::eom;
889  return refined_result;
890  }
891  }
892  log.debug() << "string_refinementt::dec_solve reached the maximum number"
893  << "of steps allowed" << messaget::eom;
894  return resultt::D_ERROR;
895 }
901  const exprt &lemma,
902  const bool simplify_lemma)
903 {
904  if(!seen_instances.insert(lemma).second)
905  return;
906 
907  current_constraints.push_back(lemma);
908 
909  exprt simple_lemma = lemma;
910  if(simplify_lemma)
911  {
912  simplify(simple_lemma, ns);
913  }
914 
915  if(simple_lemma.is_true())
916  {
917 #if 0
918  log.debug() << "string_refinementt::add_lemma : tautology" << messaget::eom;
919 #endif
920  return;
921  }
922 
923  symbol_resolve.replace_expr(simple_lemma);
924 
925  // Replace empty arrays with array_of expression because the solver cannot
926  // handle empty arrays.
927  for(auto it = simple_lemma.depth_begin(); it != simple_lemma.depth_end();)
928  {
929  if(it->id() == ID_array && it->operands().empty())
930  {
931  it.mutate() = array_of_exprt(
932  from_integer(
934  to_array_type(it->type()));
935  it.next_sibling_or_parent();
936  }
937  else
938  ++it;
939  }
940 
941  log.debug() << "adding lemma " << format(simple_lemma) << messaget::eom;
942 
943  prop.l_set_to_true(convert(simple_lemma));
944 }
945 
960 static std::optional<exprt> get_valid_array_size(
961  const std::function<exprt(const exprt &)> &super_get,
962  const namespacet &ns,
963  messaget::mstreamt &stream,
964  const array_string_exprt &arr,
965  const array_poolt &array_pool)
966 {
967  const auto &size_from_pool = array_pool.get_length_if_exists(arr);
968  exprt size_val;
969  if(size_from_pool.has_value())
970  {
971  const exprt size = size_from_pool.value();
972  size_val = simplify_expr(super_get(size), ns);
973  if(!size_val.is_constant())
974  {
975  stream << "(sr::get_valid_array_size) string of unknown size: "
976  << format(size_val) << messaget::eom;
977  return {};
978  }
979  }
980  else if(to_array_type(arr.type()).size().is_constant())
981  size_val = simplify_expr(to_array_type(arr.type()).size(), ns);
982  else
983  return {};
984 
985  auto n_opt = numeric_cast<std::size_t>(size_val);
986  if(!n_opt)
987  {
988  stream << "(sr::get_valid_array_size) size is not valid" << messaget::eom;
989  return {};
990  }
991 
992  return size_val;
993 }
994 
1004 static std::optional<exprt> get_array(
1005  const std::function<exprt(const exprt &)> &super_get,
1006  const namespacet &ns,
1007  messaget::mstreamt &stream,
1008  const array_string_exprt &arr,
1009  const array_poolt &array_pool)
1010 {
1011  const auto size =
1012  get_valid_array_size(super_get, ns, stream, arr, array_pool);
1013  if(!size.has_value())
1014  {
1015  return {};
1016  }
1017 
1018  const size_t n = numeric_cast<std::size_t>(size.value()).value();
1019 
1020  if(n > MAX_CONCRETE_STRING_SIZE)
1021  {
1022  stream << "(sr::get_valid_array_size) long string (size "
1023  << " = " << n << ") " << format(arr) << messaget::eom;
1024  stream << "(sr::get_valid_array_size) consider reducing "
1025  "max-nondet-string-length so "
1026  "that no string exceeds "
1028  << " in length and "
1029  "make sure all functions returning strings are loaded"
1030  << messaget::eom;
1031  stream << "(sr::get_valid_array_size) this can also happen on invalid "
1032  "object access"
1033  << messaget::eom;
1034  return nil_exprt();
1035  }
1036 
1037  const exprt arr_val = simplify_expr(super_get(arr), ns);
1038  const typet char_type = to_array_type(arr.type()).element_type();
1039  const typet &index_type = size.value().type();
1040 
1041  if(
1042  const auto &array = interval_sparse_arrayt::of_expr(
1044  return array->concretize(n, index_type);
1045  return {};
1046 }
1047 
1052 static std::string string_of_array(const array_exprt &arr)
1053 {
1054  if(arr.type().id() != ID_array)
1055  return std::string("");
1056 
1057  exprt size_expr = to_array_type(arr.type()).size();
1058  auto n = numeric_cast_v<std::size_t>(to_constant_expr(size_expr));
1059  return utf16_constant_array_to_java(arr, n);
1060 }
1061 
1071  const std::function<exprt(const exprt &)> &super_get,
1072  const namespacet &ns,
1073  messaget::mstreamt &stream,
1074  const array_string_exprt &arr,
1075  array_poolt &array_pool)
1076 {
1077  stream << "- " << format(arr) << ":\n";
1078  stream << std::string(4, ' ') << "- type: " << format(arr.type())
1079  << messaget::eom;
1080  const auto arr_model_opt = get_array(super_get, ns, stream, arr, array_pool);
1081  if(arr_model_opt)
1082  {
1083  stream << std::string(4, ' ') << "- char_array: " << format(*arr_model_opt)
1084  << '\n';
1085  stream << std::string(4, ' ')
1086  << "- type : " << format(arr_model_opt->type()) << messaget::eom;
1087  const exprt simple = simplify_expr(*arr_model_opt, ns);
1088  stream << std::string(4, ' ')
1089  << "- simplified_char_array: " << format(simple) << messaget::eom;
1090  if(
1091  const auto concretized_array = get_array(
1092  super_get, ns, stream, to_array_string_expr(simple), array_pool))
1093  {
1094  stream << std::string(4, ' ')
1095  << "- concretized_char_array: " << format(*concretized_array)
1096  << messaget::eom;
1097 
1098  if(
1099  const auto array_expr =
1100  expr_try_dynamic_cast<array_exprt>(*concretized_array))
1101  {
1102  stream << std::string(4, ' ') << "- as_string: \""
1103  << string_of_array(*array_expr) << "\"\n";
1104  }
1105  else
1106  stream << std::string(2, ' ') << "- warning: not an array"
1107  << messaget::eom;
1108  return *concretized_array;
1109  }
1110  return simple;
1111  }
1112  stream << std::string(4, ' ') << "- incomplete model" << messaget::eom;
1113  return arr;
1114 }
1115 
1119  const string_constraint_generatort &generator,
1120  messaget::mstreamt &stream,
1121  const namespacet &ns,
1122  const std::function<exprt(const exprt &)> &super_get,
1123  const std::vector<symbol_exprt> &symbols,
1124  array_poolt &array_pool)
1125 {
1126  stream << "debug_model:" << '\n';
1127  for(const auto &pointer_array : generator.array_pool.get_arrays_of_pointers())
1128  {
1129  const auto arr = pointer_array.second;
1130  const exprt model =
1131  get_char_array_and_concretize(super_get, ns, stream, arr, array_pool);
1132 
1133  stream << "- " << format(arr) << ":\n"
1134  << " - pointer: " << format(pointer_array.first) << "\n"
1135  << " - model: " << format(model) << messaget::eom;
1136  }
1137 
1138  for(const auto &symbol : symbols)
1139  {
1140  stream << " - " << symbol.get_identifier() << ": "
1141  << format(super_get(symbol)) << '\n';
1142  }
1143  stream << messaget::eom;
1144 }
1145 
1159  const with_exprt &expr,
1160  const exprt &index,
1161  const bool left_propagate)
1162 {
1163  return left_propagate ? interval_sparse_arrayt(expr).to_if_expression(index)
1164  : sparse_arrayt::to_if_expression(expr, index);
1165 }
1166 
1174  const array_exprt &array_expr,
1175  const exprt &index,
1176  symbol_generatort &symbol_generator)
1177 {
1178  const typet &char_type = array_expr.type().element_type();
1179  const exprt default_val = symbol_generator("out_of_bound_access", char_type);
1180  const interval_sparse_arrayt sparse_array(array_expr, default_val);
1181  return sparse_array.to_if_expression(index);
1182 }
1183 
1185  const if_exprt &if_expr,
1186  const exprt &index,
1187  symbol_generatort &symbol_generator,
1188  const bool left_propagate)
1189 {
1190  exprt true_index = index_exprt(if_expr.true_case(), index);
1191  exprt false_index = index_exprt(if_expr.false_case(), index);
1192 
1193  // Substitute recursively in branches of conditional expressions
1194  std::optional<exprt> substituted_true_case =
1195  substitute_array_access(true_index, symbol_generator, left_propagate);
1196  std::optional<exprt> substituted_false_case =
1197  substitute_array_access(false_index, symbol_generator, left_propagate);
1198 
1199  return if_exprt(
1200  if_expr.cond(),
1201  substituted_true_case ? *substituted_true_case : true_index,
1202  substituted_false_case ? *substituted_false_case : false_index);
1203 }
1204 
1205 static std::optional<exprt> substitute_array_access(
1206  const index_exprt &index_expr,
1207  symbol_generatort &symbol_generator,
1208  const bool left_propagate)
1209 {
1210  const exprt &array = index_expr.array();
1211  if(auto array_of = expr_try_dynamic_cast<array_of_exprt>(array))
1212  return array_of->op();
1213  if(auto array_with = expr_try_dynamic_cast<with_exprt>(array))
1214  return substitute_array_access(
1215  *array_with, index_expr.index(), left_propagate);
1216  if(auto array_expr = expr_try_dynamic_cast<array_exprt>(array))
1217  return substitute_array_access(
1218  *array_expr, index_expr.index(), symbol_generator);
1219  if(auto if_expr = expr_try_dynamic_cast<if_exprt>(array))
1220  return substitute_array_access(
1221  *if_expr, index_expr.index(), symbol_generator, left_propagate);
1222 
1223  INVARIANT(
1224  array.is_nil() || array.id() == ID_symbol || array.id() == ID_nondet_symbol,
1225  std::string(
1226  "in case the array is unknown, it should be a symbol or nil, id: ") +
1227  id2string(array.id()));
1228  return {};
1229 }
1230 
1235  exprt &expr,
1236  symbol_generatort &symbol_generator,
1237  const bool left_propagate)
1238 {
1239  // Recurse down structure and modify on the way.
1240  for(auto it = expr.depth_begin(), itend = expr.depth_end(); it != itend; ++it)
1241  {
1242  if(const auto index_expr = expr_try_dynamic_cast<index_exprt>(*it))
1243  {
1244  std::optional<exprt> result =
1245  substitute_array_access(*index_expr, symbol_generator, left_propagate);
1246 
1247  // Only perform a write when we have something changed.
1248  if(result)
1249  it.mutate() = *result;
1250  }
1251  }
1252 }
1253 
1274  exprt expr,
1275  symbol_generatort &symbol_generator,
1276  const bool left_propagate)
1277 {
1278  substitute_array_access_in_place(expr, symbol_generator, left_propagate);
1279  return expr;
1280 }
1281 
1293  const string_not_contains_constraintt &constraint,
1294  const symbol_exprt &univ_var,
1295  const std::function<exprt(const exprt &)> &get)
1296 {
1297  // If the for all is vacuously true, the negation is false.
1298  const auto lbe = numeric_cast_v<mp_integer>(
1299  to_constant_expr(get(constraint.exists_lower_bound)));
1300  const auto ube = numeric_cast_v<mp_integer>(
1301  to_constant_expr(get(constraint.exists_upper_bound)));
1302  const auto univ_bounds = and_exprt(
1303  binary_relation_exprt(get(constraint.univ_lower_bound), ID_le, univ_var),
1304  binary_relation_exprt(get(constraint.univ_upper_bound), ID_gt, univ_var));
1305 
1306  // The negated existential becomes an universal, and this is the unrolling of
1307  // that universal quantifier.
1308  // Ff the upper bound is smaller than the lower bound (specifically, it might
1309  // actually be negative as it is initially unconstrained) then there is
1310  // nothing to do (and the reserve call would fail).
1311  if(ube < lbe)
1312  return and_exprt(univ_bounds, get(constraint.premise));
1313 
1314  std::vector<exprt> conjuncts;
1315  conjuncts.reserve(numeric_cast_v<std::size_t>(ube - lbe));
1316  for(mp_integer i = lbe; i < ube; ++i)
1317  {
1318  const constant_exprt i_expr = from_integer(i, univ_var.type());
1319  const exprt s0_char =
1320  get(index_exprt(constraint.s0, plus_exprt(univ_var, i_expr)));
1321  const exprt s1_char = get(index_exprt(constraint.s1, i_expr));
1322  conjuncts.push_back(equal_exprt(s0_char, s1_char));
1323  }
1324  const exprt equal_strings = conjunction(conjuncts);
1325  return and_exprt(univ_bounds, get(constraint.premise), equal_strings);
1326 }
1327 
1332 template <typename T>
1334  messaget::mstreamt &stream,
1335  const T &axiom,
1336  const T &axiom_in_model,
1337  const exprt &negaxiom,
1338  const exprt &with_concretized_arrays)
1339 {
1340  stream << std::string(4, ' ') << "- axiom:\n" << std::string(6, ' ');
1341  stream << to_string(axiom);
1342  stream << '\n'
1343  << std::string(4, ' ') << "- axiom_in_model:\n"
1344  << std::string(6, ' ');
1345  stream << to_string(axiom_in_model) << '\n'
1346  << std::string(4, ' ') << "- negated_axiom:\n"
1347  << std::string(6, ' ') << format(negaxiom) << '\n';
1348  stream << std::string(4, ' ') << "- negated_axiom_with_concretized_arrays:\n"
1349  << std::string(6, ' ') << format(with_concretized_arrays) << '\n';
1350 }
1351 
1353 static std::pair<bool, std::vector<exprt>> check_axioms(
1354  const string_axiomst &axioms,
1355  string_constraint_generatort &generator,
1356  const std::function<exprt(const exprt &)> &get,
1357  messaget::mstreamt &stream,
1358  const namespacet &ns,
1359  bool use_counter_example,
1360  const union_find_replacet &symbol_resolve,
1361  const std::unordered_map<string_not_contains_constraintt, symbol_exprt>
1362  &not_contain_witnesses)
1363 {
1364  stream << "string_refinementt::check_axioms:" << messaget::eom;
1365 
1366  stream << "symbol_resolve:" << messaget::eom;
1367  auto pairs = symbol_resolve.to_vector();
1368  for(const auto &pair : pairs)
1369  stream << " - " << format(pair.first) << " --> " << format(pair.second)
1370  << messaget::eom;
1371 
1372 #ifdef DEBUG
1373  debug_model(
1374  generator,
1375  stream,
1376  ns,
1377  get,
1378  generator.fresh_symbol.created_symbols,
1379  generator.array_pool);
1380 #endif
1381 
1382  // Maps from indexes of violated universal axiom to a witness of violation
1383  std::map<size_t, exprt> violated;
1384 
1385  stream << "string_refinement::check_axioms: " << axioms.universal.size()
1386  << " universal axioms:" << messaget::eom;
1387  for(size_t i = 0; i < axioms.universal.size(); i++)
1388  {
1389  const string_constraintt &axiom = axioms.universal[i];
1390  const string_constraintt axiom_in_model(
1391  axiom.univ_var,
1392  get(axiom.lower_bound),
1393  get(axiom.upper_bound),
1394  get(axiom.body),
1395  stream.message.get_message_handler());
1396 
1397  exprt negaxiom = axiom_in_model.negation();
1398  negaxiom = simplify_expr(negaxiom, ns);
1399 
1400  stream << std::string(2, ' ') << i << ".\n";
1401  const exprt with_concretized_arrays =
1402  substitute_array_access(negaxiom, generator.fresh_symbol, true);
1404  stream, axiom, axiom_in_model, negaxiom, with_concretized_arrays);
1405 
1406  if(
1407  const auto &witness = find_counter_example(
1408  ns,
1409  with_concretized_arrays,
1410  axiom.univ_var,
1411  stream.message.get_message_handler()))
1412  {
1413  stream << std::string(4, ' ')
1414  << "- violated_for: " << format(axiom.univ_var) << "="
1415  << format(*witness) << messaget::eom;
1416  violated[i] = *witness;
1417  }
1418  else
1419  stream << std::string(4, ' ') << "- correct" << messaget::eom;
1420  }
1421 
1422  // Maps from indexes of violated not_contains axiom to a witness of violation
1423  std::map<std::size_t, exprt> violated_not_contains;
1424 
1425  stream << "there are " << axioms.not_contains.size() << " not_contains axioms"
1426  << messaget::eom;
1427  for(std::size_t i = 0; i < axioms.not_contains.size(); i++)
1428  {
1429  const string_not_contains_constraintt &nc_axiom = axioms.not_contains[i];
1430  const symbol_exprt univ_var = generator.fresh_symbol(
1431  "not_contains_univ_var", nc_axiom.s0.length_type());
1432  const exprt negated_axiom = negation_of_not_contains_constraint(
1433  nc_axiom, univ_var, [&](const exprt &expr) {
1434  return simplify_expr(get(expr), ns);
1435  });
1436 
1437  stream << std::string(2, ' ') << i << ".\n";
1439  stream, nc_axiom, nc_axiom, negated_axiom, negated_axiom);
1440 
1441  if(
1442  const auto witness = find_counter_example(
1443  ns, negated_axiom, univ_var, stream.message.get_message_handler()))
1444  {
1445  stream << std::string(4, ' ')
1446  << "- violated_for: " << univ_var.get_identifier() << "="
1447  << format(*witness) << messaget::eom;
1448  violated_not_contains[i] = *witness;
1449  }
1450  }
1451 
1452  if(violated.empty() && violated_not_contains.empty())
1453  {
1454  stream << "no violated property" << messaget::eom;
1455  return {true, std::vector<exprt>()};
1456  }
1457  else
1458  {
1459  stream << violated.size() << " universal string axioms can be violated"
1460  << messaget::eom;
1461  stream << violated_not_contains.size()
1462  << " not_contains string axioms can be violated" << messaget::eom;
1463 
1464  if(use_counter_example)
1465  {
1466  std::vector<exprt> lemmas;
1467 
1468  for(const auto &v : violated)
1469  {
1470  const exprt &val = v.second;
1471  const string_constraintt &axiom = axioms.universal[v.first];
1472 
1473  exprt instance(axiom.body);
1474  replace_expr(axiom.univ_var, val, instance);
1475  // We are not sure the index set contains only positive numbers
1476  and_exprt bounds(
1477  axiom.univ_within_bounds(),
1478  binary_relation_exprt(from_integer(0, val.type()), ID_le, val));
1479  replace_expr(axiom.univ_var, val, bounds);
1480  const implies_exprt counter(bounds, instance);
1481  lemmas.push_back(counter);
1482  }
1483 
1484  for(const auto &v : violated_not_contains)
1485  {
1486  const exprt &val = v.second;
1487  const string_not_contains_constraintt &axiom =
1488  axioms.not_contains[v.first];
1489 
1490  const exprt func_val =
1491  index_exprt(not_contain_witnesses.at(axiom), val);
1492  const exprt comp_val = simplify_sum(plus_exprt(val, func_val));
1493 
1494  std::set<std::pair<exprt, exprt>> indices;
1495  indices.insert(std::pair<exprt, exprt>(comp_val, func_val));
1496  const exprt counter =
1497  ::instantiate_not_contains(axiom, indices, not_contain_witnesses)[0];
1498  lemmas.push_back(counter);
1499  }
1500  return {false, lemmas};
1501  }
1502  }
1503  return {false, std::vector<exprt>()};
1504 }
1505 
1509 {
1510  return linear_functiont{f}.to_expr();
1511 }
1512 
1518 static void initial_index_set(
1519  index_set_pairt &index_set,
1520  const namespacet &ns,
1521  const string_axiomst &axioms)
1522 {
1523  for(const auto &axiom : axioms.universal)
1524  initial_index_set(index_set, ns, axiom);
1525  for(const auto &axiom : axioms.not_contains)
1526  initial_index_set(index_set, ns, axiom);
1527 }
1528 
1533 static void update_index_set(
1534  index_set_pairt &index_set,
1535  const namespacet &ns,
1536  const std::vector<exprt> &current_constraints)
1537 {
1538  for(const auto &axiom : current_constraints)
1539  update_index_set(index_set, ns, axiom);
1540 }
1541 
1548 static void get_sub_arrays(const exprt &array_expr, std::vector<exprt> &accu)
1549 {
1550  if(array_expr.id() == ID_if)
1551  {
1552  get_sub_arrays(to_if_expr(array_expr).true_case(), accu);
1553  get_sub_arrays(to_if_expr(array_expr).false_case(), accu);
1554  }
1555  else
1556  {
1557  if(array_expr.type().id() == ID_array)
1558  {
1559  // TODO: check_that it does not contain any sub_array
1560  accu.push_back(array_expr);
1561  }
1562  else
1563  {
1564  for(const auto &operand : array_expr.operands())
1565  get_sub_arrays(operand, accu);
1566  }
1567  }
1568 }
1569 
1575 static void add_to_index_set(
1576  index_set_pairt &index_set,
1577  const namespacet &ns,
1578  const exprt &s,
1579  exprt i)
1580 {
1581  simplify(i, ns);
1582  const bool is_size_t = numeric_cast<std::size_t>(i).has_value();
1583  if(!i.is_constant() || is_size_t)
1584  {
1585  std::vector<exprt> sub_arrays;
1586  get_sub_arrays(s, sub_arrays);
1587  for(const auto &sub : sub_arrays)
1588  if(index_set.cumulative[sub].insert(i).second)
1589  index_set.current[sub].insert(i);
1590  }
1591 }
1592 
1608 static void initial_index_set(
1609  index_set_pairt &index_set,
1610  const namespacet &ns,
1611  const exprt &qvar,
1612  const exprt &upper_bound,
1613  const exprt &s,
1614  const exprt &i)
1615 {
1616  PRECONDITION(
1617  s.id() == ID_symbol || s.id() == ID_nondet_symbol || s.id() == ID_array ||
1618  s.id() == ID_if);
1619  if(s.id() == ID_array)
1620  {
1621  for(std::size_t j = 0; j < s.operands().size(); ++j)
1622  add_to_index_set(index_set, ns, s, from_integer(j, i.type()));
1623  return;
1624  }
1625  if(auto ite = expr_try_dynamic_cast<if_exprt>(s))
1626  {
1627  initial_index_set(index_set, ns, qvar, upper_bound, ite->true_case(), i);
1628  initial_index_set(index_set, ns, qvar, upper_bound, ite->false_case(), i);
1629  return;
1630  }
1631  const minus_exprt u_minus_1(upper_bound, from_integer(1, upper_bound.type()));
1632  exprt i_copy = i;
1633  replace_expr(qvar, u_minus_1, i_copy);
1634  add_to_index_set(index_set, ns, s, i_copy);
1635 }
1636 
1637 static void initial_index_set(
1638  index_set_pairt &index_set,
1639  const namespacet &ns,
1640  const string_constraintt &axiom)
1641 {
1642  const symbol_exprt &qvar = axiom.univ_var;
1643  const auto &bound = axiom.upper_bound;
1644  auto it = axiom.body.depth_begin();
1645  const auto end = axiom.body.depth_end();
1646  while(it != end)
1647  {
1648  if(it->id() == ID_index && is_char_type(it->type()))
1649  {
1650  const auto &index_expr = to_index_expr(*it);
1651  const auto &s = index_expr.array();
1652  initial_index_set(index_set, ns, qvar, bound, s, index_expr.index());
1653  it.next_sibling_or_parent();
1654  }
1655  else
1656  ++it;
1657  }
1658 }
1659 
1660 static void initial_index_set(
1661  index_set_pairt &index_set,
1662  const namespacet &ns,
1663  const string_not_contains_constraintt &axiom)
1664 {
1665  auto it = axiom.premise.depth_begin();
1666  const auto end = axiom.premise.depth_end();
1667  while(it != end)
1668  {
1669  if(it->id() == ID_index && is_char_type(it->type()))
1670  {
1671  const exprt &s = to_index_expr(*it).array();
1672  const exprt &i = to_index_expr(*it).index();
1673 
1674  // cur is of the form s[i] and no quantified variable appears in i
1675  add_to_index_set(index_set, ns, s, i);
1676 
1677  it.next_sibling_or_parent();
1678  }
1679  else
1680  ++it;
1681  }
1682 
1683  const minus_exprt kminus1(
1685  add_to_index_set(index_set, ns, axiom.s1.content(), kminus1);
1686 }
1687 
1692 static void update_index_set(
1693  index_set_pairt &index_set,
1694  const namespacet &ns,
1695  const exprt &formula)
1696 {
1697  std::list<exprt> to_process;
1698  to_process.push_back(formula);
1699 
1700  while(!to_process.empty())
1701  {
1702  exprt cur = to_process.back();
1703  to_process.pop_back();
1704  if(cur.id() == ID_index && is_char_type(cur.type()))
1705  {
1706  const exprt &s = to_index_expr(cur).array();
1707  const exprt &i = to_index_expr(cur).index();
1709  s.type().id() == ID_array,
1710  string_refinement_invariantt("index expressions must index on arrays"));
1711  exprt simplified = simplify_sum(i);
1712  if(s.id() != ID_array) // do not update index set of constant arrays
1713  add_to_index_set(index_set, ns, s, simplified);
1714  }
1715  else
1716  {
1717  for(const auto &op : as_const(cur).operands())
1718  to_process.push_back(op);
1719  }
1720  }
1721 }
1722 
1741 static std::vector<exprt> instantiate(
1742  const string_not_contains_constraintt &axiom,
1743  const index_set_pairt &index_set,
1744  const std::unordered_map<string_not_contains_constraintt, symbol_exprt>
1745  &witnesses)
1746 {
1747  const array_string_exprt &s0 = axiom.s0;
1748  const array_string_exprt &s1 = axiom.s1;
1749 
1750  const auto &index_set0 = index_set.cumulative.find(s0.content());
1751  const auto &index_set1 = index_set.cumulative.find(s1.content());
1752  const auto &current_index_set0 = index_set.current.find(s0.content());
1753  const auto &current_index_set1 = index_set.current.find(s1.content());
1754 
1755  if(
1756  index_set0 != index_set.cumulative.end() &&
1757  index_set1 != index_set.cumulative.end() &&
1758  current_index_set0 != index_set.current.end() &&
1759  current_index_set1 != index_set.current.end())
1760  {
1761  typedef std::pair<exprt, exprt> expr_pairt;
1762  std::set<expr_pairt> index_pairs;
1763 
1764  for(const auto &ic0 : current_index_set0->second)
1765  for(const auto &i1 : index_set1->second)
1766  index_pairs.insert(expr_pairt(ic0, i1));
1767  for(const auto &ic1 : current_index_set1->second)
1768  for(const auto &i0 : index_set0->second)
1769  index_pairs.insert(expr_pairt(i0, ic1));
1770 
1771  return ::instantiate_not_contains(axiom, index_pairs, witnesses);
1772  }
1773  return {};
1774 }
1775 
1783 exprt substitute_array_lists(exprt expr, size_t string_max_length)
1784 {
1785  for(auto &operand : expr.operands())
1786  operand = substitute_array_lists(operand, string_max_length);
1787 
1788  if(expr.id() == ID_array_list)
1789  {
1791  expr.operands().size() >= 2,
1792  string_refinement_invariantt("array-lists must have at least two "
1793  "operands"));
1794  const typet &char_type = expr.operands()[1].type();
1796  exprt ret_expr = array_of_exprt(from_integer(0, char_type), arr_type);
1797 
1798  for(size_t i = 0; i < expr.operands().size(); i += 2)
1799  {
1800  const exprt &index = expr.operands()[i];
1801  const exprt &value = expr.operands()[i + 1];
1802  const auto index_value = numeric_cast<std::size_t>(index);
1803  if(
1804  !index.is_constant() ||
1805  (index_value && *index_value < string_max_length))
1806  ret_expr = with_exprt(ret_expr, index, value);
1807  }
1808  return ret_expr;
1809  }
1810 
1811  return expr;
1812 }
1813 
1822 {
1823  const auto super_get = [this](const exprt &expr) {
1824  return supert::get(expr);
1825  };
1826  exprt ecopy(expr);
1827  (void)symbol_resolve.replace_expr(ecopy);
1828 
1829  // Special treatment for index expressions
1830  const auto &index_expr = expr_try_dynamic_cast<index_exprt>(ecopy);
1831  if(index_expr && is_char_type(index_expr->type()))
1832  {
1833  std::reference_wrapper<const exprt> current(index_expr->array());
1834  while(current.get().id() == ID_if)
1835  {
1836  const auto &if_expr = expr_dynamic_cast<if_exprt>(current.get());
1837  const exprt cond = get(if_expr.cond());
1838  if(cond.is_true())
1839  current = std::cref(if_expr.true_case());
1840  else if(cond.is_false())
1841  current = std::cref(if_expr.false_case());
1842  else
1843  UNREACHABLE;
1844  }
1845  const auto array = supert::get(current.get());
1846  const auto index = get(index_expr->index());
1847 
1848  // If the underlying solver does not know about the existence of an array,
1849  // it can return nil, which cannot be used in the expression returned here.
1850  if(array.is_nil())
1851  return index_exprt(current, index);
1852 
1853  const exprt unknown =
1854  from_integer(CHARACTER_FOR_UNKNOWN, index_expr->type());
1855  if(
1856  const auto sparse_array = interval_sparse_arrayt::of_expr(array, unknown))
1857  {
1858  if(const auto index_value = numeric_cast<std::size_t>(index))
1859  return sparse_array->at(*index_value);
1860  return sparse_array->to_if_expression(index);
1861  }
1862 
1863  INVARIANT(array.id() == ID_symbol || array.id() == ID_nondet_symbol,
1864  "Apart from symbols, array valuations can be interpreted as "
1865  "sparse arrays. Array model : " + array.pretty());
1866  return index_exprt(array, index);
1867  }
1868 
1869  if(is_char_array_type(ecopy.type(), ns))
1870  {
1872 
1873  if(
1874  const auto from_dependencies =
1875  dependencies.eval(arr, [&](const exprt &expr) { return get(expr); }))
1876  return *from_dependencies;
1877 
1878  if(
1879  const auto arr_model_opt =
1880  get_array(super_get, ns, log.debug(), arr, generator.array_pool))
1881  return *arr_model_opt;
1882 
1883  if(
1884  const auto &length_from_pool =
1886  {
1887  const exprt length = super_get(length_from_pool.value());
1888 
1889  if(const auto n = numeric_cast<std::size_t>(length))
1890  {
1891  const interval_sparse_arrayt sparse_array(from_integer(
1893  return sparse_array.concretize(*n, length.type());
1894  }
1895  }
1896  return arr;
1897  }
1898  return supert::get(ecopy);
1899 }
1900 
1910 static std::optional<exprt> find_counter_example(
1911  const namespacet &ns,
1912  const exprt &axiom,
1913  const symbol_exprt &var,
1914  message_handlert &message_handler)
1915 {
1916  satcheck_no_simplifiert sat_check(message_handler);
1917  bv_pointerst solver(ns, sat_check, message_handler);
1918  solver << axiom;
1919 
1921  return solver.get(var);
1922  else
1923  return {};
1924 }
1925 
1927 typedef std::map<exprt, std::vector<exprt>> array_index_mapt;
1928 
1931 {
1932  array_index_mapt indices;
1933  // clang-format off
1934  std::for_each(
1935  expr.depth_begin(),
1936  expr.depth_end(),
1937  [&](const exprt &expr)
1938  {
1939  const auto index_expr = expr_try_dynamic_cast<const index_exprt>(expr);
1940  if(index_expr)
1941  indices[index_expr->array()].push_back(index_expr->index());
1942  });
1943  // clang-format on
1944  return indices;
1945 }
1946 
1952 static bool
1954 {
1955  for(auto it = expr.depth_begin(); it != expr.depth_end();)
1956  {
1957  if(
1958  it->id() != ID_plus && it->id() != ID_minus &&
1959  it->id() != ID_unary_minus && *it != var)
1960  {
1961  if(std::find(it->depth_begin(), it->depth_end(), var) != it->depth_end())
1962  return false;
1963  else
1964  it.next_sibling_or_parent();
1965  }
1966  else
1967  ++it;
1968  }
1969  return true;
1970 }
1971 
1980 {
1981  for(auto it = constr.body.depth_begin(); it != constr.body.depth_end();)
1982  {
1983  if(*it == constr.univ_var)
1984  return false;
1985  if(it->id() == ID_index)
1986  it.next_sibling_or_parent();
1987  else
1988  ++it;
1989  }
1990  return true;
1991 }
1992 
2000  messaget::mstreamt &stream,
2001  const namespacet &ns,
2002  const string_constraintt &constraint)
2003 {
2004  const array_index_mapt body_indices = gather_indices(constraint.body);
2005  // Must validate for each string. Note that we have an invariant that the
2006  // second value in the pair is non-empty.
2007  for(const auto &pair : body_indices)
2008  {
2009  // Condition 1: All indices of the same string must be the of the same form
2010  const exprt rep = pair.second.back();
2011  for(size_t j = 0; j < pair.second.size() - 1; j++)
2012  {
2013  const exprt i = pair.second[j];
2014  const equal_exprt equals(rep, i);
2015  const exprt result = simplify_expr(equals, ns);
2016  if(result.is_false())
2017  {
2018  stream << "Indices not equal: " << to_string(constraint)
2019  << ", str: " << format(pair.first) << messaget::eom;
2020  return false;
2021  }
2022  }
2023 
2024  // Condition 2: f must be linear in the quantified variable
2025  if(!is_linear_arithmetic_expr(rep, constraint.univ_var))
2026  {
2027  stream << "f is not linear: " << to_string(constraint)
2028  << ", str: " << format(pair.first) << messaget::eom;
2029  return false;
2030  }
2031 
2032  // Condition 3: the quantified variable can only occur in indices in the
2033  // body
2034  if(!universal_only_in_index(constraint))
2035  {
2036  stream << "Universal variable outside of index:" << to_string(constraint)
2037  << messaget::eom;
2038  return false;
2039  }
2040  }
2041 
2042  return true;
2043 }
static abstract_object_pointert transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns)
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
Definition: as_const.h:14
int8_t s1
Definition: bytecode_info.h:59
bitvector_typet char_type()
Definition: c_types.cpp:106
Boolean AND.
Definition: std_expr.h:2120
Array constructor from list of elements.
Definition: std_expr.h:1616
const array_typet & type() const
Definition: std_expr.h:1623
Array constructor from single element.
Definition: std_expr.h:1553
Correspondance between arrays and pointers string representations.
Definition: array_pool.h:42
const std::unordered_map< exprt, array_string_exprt, irep_hash > & get_arrays_of_pointers() const
Definition: array_pool.h:50
std::optional< exprt > get_length_if_exists(const array_string_exprt &s) const
As opposed to get_length(), do not create a new symbol if the length of the array_string_exprt does n...
Definition: array_pool.cpp:48
exprt get_or_create_length(const array_string_exprt &s)
Get the length of an array_string_exprt from the array_pool.
Definition: array_pool.cpp:26
const std::unordered_map< array_string_exprt, exprt, irep_hash > & created_strings() const
Return a map mapping all array_string_exprt of the array_pool to their length.
Definition: array_pool.cpp:179
const typet & length_type() const
Definition: string_expr.h:70
exprt & content()
Definition: string_expr.h:75
Arrays with given size.
Definition: std_types.h:807
const typet & element_type() const
The type of the elements of the array.
Definition: std_types.h:827
const exprt & size() const
Definition: std_types.h:840
const namespacet & ns
Definition: arrays.h:56
messaget log
Definition: arrays.h:57
exprt & lhs()
Definition: std_expr.h:668
exprt & rhs()
Definition: std_expr.h:678
A base class for relations, i.e., binary predicates whose two operands have the same type.
Definition: std_expr.h:762
void set_to(const exprt &expr, bool value) override
For a Boolean expression expr, add the constraint 'expr' if value is true, otherwise add 'not expr'.
Definition: boolbv.cpp:508
exprt get(const exprt &expr) const override
Return expr with variables replaced by values from satisfying assignment if available.
Definition: boolbv_get.cpp:21
decision_proceduret::resultt dec_solve(const exprt &) override
Implementation of the decision procedure.
A constant literal expression.
Definition: std_expr.h:2987
resultt
Result of running the decision procedure.
Equality.
Definition: std_expr.h:1361
Maps equation to expressions contained in them and conversely expressions to equations that contain t...
void add(const std::size_t i, const exprt &expr)
Record the fact that equation i contains expression expr
std::vector< std::size_t > find_equations(const exprt &expr)
std::vector< exprt > find_expressions(const std::size_t i)
Base class for all expressions.
Definition: expr.h:56
bool is_true() const
Return whether the expression is a constant representing true.
Definition: expr.cpp:27
depth_iteratort depth_end()
Definition: expr.cpp:249
bool is_boolean() const
Return whether the expression represents a Boolean.
Definition: expr.h:224
depth_iteratort depth_begin()
Definition: expr.cpp:247
bool is_false() const
Return whether the expression is a constant representing false.
Definition: expr.cpp:34
typet & type()
Return the type of the expression.
Definition: expr.h:84
bool is_constant() const
Return whether the expression is a constant.
Definition: expr.h:212
operandst & operands()
Definition: expr.h:94
The trinary if-then-else operator.
Definition: std_expr.h:2370
exprt & true_case()
Definition: std_expr.h:2397
exprt & false_case()
Definition: std_expr.h:2407
exprt & cond()
Definition: std_expr.h:2387
Boolean implication.
Definition: std_expr.h:2183
Array index operator.
Definition: std_expr.h:1465
exprt & array()
Definition: std_expr.h:1495
exprt & index()
Definition: std_expr.h:1505
An expression denoting infinity.
Definition: std_expr.h:3089
Represents arrays by the indexes up to which the value remains the same.
exprt to_if_expression(const exprt &index) const
static std::optional< interval_sparse_arrayt > of_expr(const exprt &expr, const exprt &extra_value)
If the expression is an array_exprt or a with_exprt uses the appropriate constructor,...
array_exprt concretize(std::size_t size, const typet &index_type) const
Convert to an array representation, ignores elements at index >= size.
const irep_idt & id() const
Definition: irep.h:384
bool is_nil() const
Definition: irep.h:364
Canonical representation of linear function, for instance, expression $x + x - y + 5 - 3$ would given...
Extract member of struct or union.
Definition: std_expr.h:2841
messaget & message
Definition: message.h:246
mstreamt & error() const
Definition: message.h:399
mstreamt & debug() const
Definition: message.h:429
message_handlert & get_message_handler()
Definition: message.h:184
static eomt eom
Definition: message.h:297
Binary minus.
Definition: std_expr.h:1061
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
Definition: namespace.cpp:49
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
The NIL expression.
Definition: std_expr.h:3073
Boolean negation.
Definition: std_expr.h:2327
The plus expression Associativity is not specified.
Definition: std_expr.h:1002
literalt convert(const exprt &expr) override
Convert a Boolean expression and return the corresponding literal.
void l_set_to_true(literalt a)
Definition: prop.h:52
static exprt to_if_expression(const with_exprt &expr, const exprt &index)
Creates an if_expr corresponding to the result of accessing the array at the given index.
std::optional< exprt > make_array_pointer_association(const exprt &return_code, const function_application_exprt &expr)
Associate array to pointer, and array to length.
static bool is_valid_string_constraint(messaget::mstreamt &stream, const namespacet &ns, const string_constraintt &constraint)
Checks the data invariant for string_constraintt.
exprt univ_within_bounds() const
static array_index_mapt gather_indices(const exprt &expr)
exprt negation() const
static bool universal_only_in_index(const string_constraintt &constr)
The universally quantified variable is only allowed to occur in index expressions in the body of a st...
static bool is_linear_arithmetic_expr(const exprt &expr, const symbol_exprt &var)
std::map< exprt, std::vector< exprt > > array_index_mapt
void output_dot(std::ostream &stream) const
void clean_cache()
Clean the cache used by eval
std::optional< exprt > eval(const array_string_exprt &s, const std::function< exprt(const exprt &)> &get_value) const
Attempt to evaluate the given string from the dependencies and valuation of strings on which it depen...
string_constraintst add_constraints(string_constraint_generatort &generatort, message_handlert &message_handler)
For all builtin call on which a test (or an unsupported buitin) result depends, add the corresponding...
string_constraint_generatort generator
union_find_replacet symbol_resolve
std::vector< exprt > equations
string_axiomst axioms
decision_proceduret::resultt dec_solve(const exprt &) override
Main decision procedure of the solver.
string_refinementt(const infot &)
const configt config_
std::set< exprt > seen_instances
void set_to(const exprt &expr, bool value) override
Record the constraints to ensure that the expression is true when the boolean is true and false other...
string_dependenciest dependencies
index_set_pairt index_sets
exprt get(const exprt &expr) const override
Evaluates the given expression in the valuation found by string_refinementt::dec_solve.
std::vector< exprt > instantiate_not_contains(const string_not_contains_constraintt &axiom, const std::set< std::pair< exprt, exprt >> &index_pairs, const std::unordered_map< string_not_contains_constraintt, symbol_exprt > &witnesses)
Instantiates a quantified formula representing not_contains by substituting the quantifiers and gener...
std::vector< exprt > current_constraints
void add_lemma(const exprt &lemma, bool simplify_lemma=true)
Add the given lemma to the solver.
String type.
Definition: std_types.h:957
Structure type, corresponds to C style structs.
Definition: std_types.h:231
const componentst & components() const
Definition: std_types.h:147
Expression to hold a symbol (variable)
Definition: std_expr.h:131
const irep_idt & get_identifier() const
Definition: std_expr.h:160
Generation of fresh symbols of a given type.
Definition: array_pool.h:22
The type of an expression, extends irept.
Definition: type.h:29
Similar interface to union-find for expressions, with a function for replacing sub-expressions by the...
std::vector< std::pair< exprt, exprt > > to_vector() const
exprt make_union(const exprt &a, const exprt &b)
Merge the set containing a and the set containing b.
bool replace_expr(exprt &expr) const
Replace subexpressions of expr by the representative element of the set they belong to.
Operator to update elements in structs and arrays.
Definition: std_expr.h:2471
Forward depth-first search iterators These iterators' copy operations are expensive,...
bool has_subtype(const typet &type, const std::function< bool(const typet &)> &pred, const namespacet &ns)
returns true if any of the contained types satisfies pred
Definition: expr_util.cpp:155
Deprecated expression utility functions.
static format_containert< T > format(const T &o)
Definition: format.h:37
const std::string & id2string(const irep_idt &d)
Definition: irep.h:40
Magic numbers used throughout the codebase.
const std::size_t MAX_CONCRETE_STRING_SIZE
Definition: magic.h:14
bool can_cast_expr< function_application_exprt >(const exprt &base)
Ranges: pair of begin and end iterators, which can be initialized from containers,...
ranget< iteratort > make_range(iteratort begin, iteratort end)
Definition: range.h:522
bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
bool simplify(exprt &expr, const namespacet &ns)
exprt simplify_expr(exprt src, const namespacet &ns)
BigInt mp_integer
Definition: smt_terms.h:17
void solver(std::vector< framet > &frames, const std::unordered_set< symbol_exprt, irep_hash > &address_taken, const solver_optionst &solver_options, const namespacet &ns, std::vector< propertyt > &properties, std::size_t property_index)
Definition: solver.cpp:44
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:525
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition: invariant.h:534
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:423
exprt conjunction(const exprt::operandst &op)
1) generates a conjunction for two or more operands 2) for one operand, returns the operand 3) return...
Definition: std_expr.cpp:66
bool can_cast_expr< equal_exprt >(const exprt &base)
Definition: std_expr.h:1386
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
Definition: std_expr.h:2450
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
Definition: std_expr.h:3037
const equal_exprt & to_equal_expr(const exprt &expr)
Cast an exprt to an equal_exprt.
Definition: std_expr.h:1402
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
Definition: std_expr.h:1533
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
Definition: std_types.h:308
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
Definition: std_types.h:888
#define CHARACTER_FOR_UNKNOWN
Module: String solver Author: Diffblue Ltd.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
void merge(string_constraintst &result, string_constraintst other)
Merge two sets of constraints by appending to the first one.
Defines related function for string constraints.
std::vector< exprt > instantiate_not_contains(const string_not_contains_constraintt &axiom, const std::set< std::pair< exprt, exprt >> &index_pairs, const std::unordered_map< string_not_contains_constraintt, symbol_exprt > &witnesses)
std::optional< exprt > add_node(string_dependenciest &dependencies, const exprt &expr, array_poolt &array_pool, symbol_generatort &fresh_symbol)
When a sub-expression of expr is a builtin_function, add a "string_builtin_function" node to the grap...
Keeps track of dependencies between strings.
array_string_exprt & to_array_string_expr(exprt &expr)
Definition: string_expr.h:96
static void initial_index_set(index_set_pairt &index_set, const namespacet &ns, const string_constraintt &axiom)
static std::vector< exprt > extract_strings_from_lhs(const exprt &lhs, const namespacet &ns)
This is meant to be used on the lhs of an equation with string subtype.
static std::string string_of_array(const array_exprt &arr)
convert the content of a string to a more readable representation.
static void update_index_set(index_set_pairt &index_set, const namespacet &ns, const std::vector< exprt > &current_constraints)
Add to the index set all the indices that appear in the formulas.
static std::vector< exprt > extract_strings(const exprt &expr, const namespacet &ns)
exprt substitute_array_lists(exprt expr, size_t string_max_length)
Replace array-lists by 'with' expressions.
static std::optional< exprt > substitute_array_access(const index_exprt &index_expr, symbol_generatort &symbol_generator, const bool left_propagate)
static std::vector< T > fill_in_map_as_vector(const std::map< std::size_t, T > &index_value)
Convert index-value map to a vector of values.
static std::vector< exprt > generate_instantiations(const index_set_pairt &index_set, const string_axiomst &axioms, const std::unordered_map< string_not_contains_constraintt, symbol_exprt > &not_contain_witnesses)
Instantiation of all constraints.
static std::pair< bool, std::vector< exprt > > check_axioms(const string_axiomst &axioms, string_constraint_generatort &generator, const std::function< exprt(const exprt &)> &get, messaget::mstreamt &stream, const namespacet &ns, bool use_counter_example, const union_find_replacet &symbol_resolve, const std::unordered_map< string_not_contains_constraintt, symbol_exprt > &not_contain_witnesses)
Check axioms takes the model given by the underlying solver and answers whether it satisfies the stri...
static void add_equations_for_symbol_resolution(union_find_replacet &symbol_solver, const std::vector< exprt > &equations, const namespacet &ns, messaget::mstreamt &stream)
Add association for each char pointer in the equation.
static void make_char_array_pointer_associations(string_constraint_generatort &generator, exprt &expr)
If expr is an equation whose right-hand-side is a associate_array_to_pointer call,...
static std::optional< exprt > get_valid_array_size(const std::function< exprt(const exprt &)> &super_get, const namespacet &ns, messaget::mstreamt &stream, const array_string_exprt &arr, const array_poolt &array_pool)
Get a model of the size of the input string.
static void add_string_equation_to_symbol_resolution(const equal_exprt &eq, union_find_replacet &symbol_resolve, const namespacet &ns)
Given an equation on strings, mark these strings as belonging to the same set in the symbol_resolve s...
static bool validate(const string_refinementt::infot &info)
static void add_to_index_set(index_set_pairt &index_set, const namespacet &ns, const exprt &s, exprt i)
Add i to the index set all the indices that appear in the formula.
exprt simplify_sum(const exprt &f)
static std::optional< exprt > get_array(const std::function< exprt(const exprt &)> &super_get, const namespacet &ns, messaget::mstreamt &stream, const array_string_exprt &arr, const array_poolt &array_pool)
Get a model of an array and put it in a certain form.
union_find_replacet string_identifiers_resolution_from_equations(const std::vector< equal_exprt > &equations, const namespacet &ns, messaget::mstreamt &stream)
Symbol resolution for expressions of type string typet.
static void display_index_set(messaget::mstreamt &stream, const index_set_pairt &index_set)
Write index set to the given stream, use for debugging.
static exprt negation_of_not_contains_constraint(const string_not_contains_constraintt &constraint, const symbol_exprt &univ_var, const std::function< exprt(const exprt &)> &get)
Negates the constraint to be fed to a solver.
static exprt replace_expr_copy(const union_find_replacet &symbol_resolve, exprt expr)
Substitute sub-expressions in equation by representative elements of symbol_resolve whenever possible...
static void substitute_array_access_in_place(exprt &expr, symbol_generatort &symbol_generator, const bool left_propagate)
Auxiliary function for substitute_array_access Performs the same operation but modifies the argument ...
static void get_sub_arrays(const exprt &array_expr, std::vector< exprt > &accu)
An expression representing an array of characters can be in the form of an if expression for instance...
void debug_model(const string_constraint_generatort &generator, messaget::mstreamt &stream, const namespacet &ns, const std::function< exprt(const exprt &)> &super_get, const std::vector< symbol_exprt > &symbols, array_poolt &array_pool)
Display part of the current model by mapping the variables created by the solver to constant expressi...
static std::vector< exprt > instantiate(const string_not_contains_constraintt &axiom, const index_set_pairt &index_set, const std::unordered_map< string_not_contains_constraintt, symbol_exprt > &witnesses)
Instantiates a quantified formula representing not_contains by substituting the quantifiers and gener...
static std::optional< exprt > find_counter_example(const namespacet &ns, const exprt &axiom, const symbol_exprt &var, message_handlert &message_handler)
Creates a solver with axiom as the only formula added and runs it.
static void debug_check_axioms_step(messaget::mstreamt &stream, const T &axiom, const T &axiom_in_model, const exprt &negaxiom, const exprt &with_concretized_arrays)
Debugging function which outputs the different steps an axiom goes through to be checked in check axi...
static exprt get_char_array_and_concretize(const std::function< exprt(const exprt &)> &super_get, const namespacet &ns, messaget::mstreamt &stream, const array_string_exprt &arr, array_poolt &array_pool)
Debugging function which finds the valuation of the given array in super_get and concretize unknown c...
String support via creating string constraints and progressively instantiating the universal constrai...
#define string_refinement_invariantt(reason)
std::string utf16_constant_array_to_java(const array_exprt &arr, std::size_t length)
Construct a string from a constant array.
bool is_char_type(const typet &type)
For now, any unsigned bitvector type of width smaller or equal to 16 is considered a character.
bool has_char_pointer_subtype(const typet &type, const namespacet &ns)
bool is_char_array_type(const typet &type, const namespacet &ns)
Distinguish char array from other types.
bool is_char_pointer_type(const typet &type)
For now, any unsigned bitvector type is considered a character.
const namespacet * ns
Definition: bv_refinement.h:35
std::map< exprt, std::set< exprt > > current
std::map< exprt, std::set< exprt > > cumulative
std::vector< string_constraintt > universal
std::vector< string_not_contains_constraintt > not_contains
Collection of constraints of different types: existential formulas, universal formulas,...
std::vector< string_not_contains_constraintt > not_contains
std::vector< exprt > existential
std::vector< string_constraintt > universal
Constraints to encode non containement of strings.
string_refinementt constructor arguments