CBMC
recursive_initialization.cpp
Go to the documentation of this file.
1 /******************************************************************\
2 
3 Module: recursive_initialization
4 
5 Author: Diffblue Ltd.
6 
7 \******************************************************************/
8 
10 
12 
13 #include <util/arith_tools.h>
14 #include <util/c_types.h>
15 #include <util/fresh_symbol.h>
16 #include <util/irep.h>
17 #include <util/optional_utils.h>
18 #include <util/pointer_expr.h>
20 #include <util/rename.h>
21 #include <util/std_code.h>
22 #include <util/string2int.h>
23 #include <util/string_utils.h>
24 
25 #include <iterator>
26 
28 #include "goto_harness_generator.h"
29 
31  const std::string &option,
32  const std::list<std::string> &values)
33 {
35  {
36  auto const value =
38  auto const user_min_null_tree_depth =
39  string2optional<std::size_t>(value, 10);
40  if(user_min_null_tree_depth.has_value())
41  {
42  min_null_tree_depth = user_min_null_tree_depth.value();
43  }
44  else
45  {
47  "failed to convert '" + value + "' to integer",
49  }
50  return true;
51  }
53  {
54  auto const value =
56  auto const user_max_nondet_tree_depth =
57  string2optional<std::size_t>(value, 10);
58  if(user_max_nondet_tree_depth.has_value())
59  {
60  max_nondet_tree_depth = user_max_nondet_tree_depth.value();
61  }
62  else
63  {
65  "failed to convert '" + value + "' to integer",
67  }
68  return true;
69  }
71  {
74  return true;
75  }
77  {
80  return true;
81  }
83  {
85  values.begin(),
86  values.end(),
87  std::inserter(
90  [](const std::string &opt) -> irep_idt { return irep_idt{opt}; });
91  return true;
92  }
94  {
95  const auto list_of_members_string =
98  const auto list_of_members = split_string(list_of_members_string, ',');
99  for(const auto &member : list_of_members)
100  {
101  const auto selection_spec_strings = split_string(member, '.');
102 
103  selection_specs.push_back({});
104  auto &selection_spec = selection_specs.back();
106  selection_spec_strings.begin(),
107  selection_spec_strings.end(),
108  std::back_inserter(selection_spec),
109  [](const std::string &member_name_string) {
110  return irep_idt{member_name_string};
111  });
112  }
113  return true;
114  }
115  return false;
116 }
117 
119  recursive_initialization_configt initialization_config,
120  goto_modelt &goto_model)
121  : initialization_config(std::move(initialization_config)),
122  goto_model(goto_model),
123  max_depth_var_name(get_fresh_global_name(
124  "max_depth",
125  from_integer(
126  initialization_config.max_nondet_tree_depth,
127  signed_int_type()))),
128  min_depth_var_name(get_fresh_global_name(
129  "min_depth",
130  from_integer(
131  initialization_config.min_null_tree_depth,
132  signed_int_type())))
133 {
135  this->initialization_config.pointers_to_treat_equal.size());
136 }
137 
139  const exprt &lhs,
140  const exprt &depth,
141  code_blockt &body)
142 {
143  if(lhs.id() == ID_symbol && !initialization_config.selection_specs.empty())
144  {
145  auto lhs_id = to_symbol_expr(lhs).get_identifier();
146  for(const auto &selection_spec : initialization_config.selection_specs)
147  {
148  if(selection_spec.front() == lhs_id)
149  {
150  initialize_selected_member(lhs, depth, body, selection_spec);
151  return;
152  }
153  }
154  }
155  // special handling for the case that pointer arguments should be treated
156  // equal: if the equality is enforced (rather than the pointers may be equal),
157  // then we don't even build the constructor functions
158  if(lhs.id() == ID_symbol)
159  {
160  const auto maybe_cluster_index =
162  if(maybe_cluster_index.has_value())
163  {
164  if(common_arguments_origins[*maybe_cluster_index].has_value())
165  {
166  const auto set_equal_case =
167  code_assignt{lhs, *common_arguments_origins[*maybe_cluster_index]};
169  {
170  const irep_idt &fun_name = build_constructor(lhs);
171  const symbolt &fun_symbol =
173  const auto proper_init_case = code_function_callt{
174  fun_symbol.symbol_expr(), {depth, address_of_exprt{lhs}}};
175  const auto should_make_equal =
176  get_fresh_local_typed_symexpr("should_make_equal", bool_typet{});
177  body.add(code_declt{should_make_equal});
178  body.add(code_ifthenelset{
179  should_make_equal, set_equal_case, proper_init_case});
180  }
181  else
182  {
183  body.add(set_equal_case);
184  }
185  return;
186  }
187  else
188  {
189  common_arguments_origins[*maybe_cluster_index] = lhs;
190  }
191  }
192  }
193 
194  const irep_idt &fun_name = build_constructor(lhs);
195  const symbolt &fun_symbol = goto_model.symbol_table.lookup_ref(fun_name);
196 
197  if(lhs.id() == ID_symbol)
198  {
199  const irep_idt &lhs_name = to_symbol_expr(lhs).get_identifier();
200  if(should_be_treated_as_array(lhs_name))
201  {
202  auto size_var = get_associated_size_variable(lhs_name);
203  if(size_var.has_value())
204  {
205  const symbol_exprt &size_symbol =
206  goto_model.symbol_table.lookup_ref(size_var.value()).symbol_expr();
208  fun_symbol.symbol_expr(),
209  {depth, address_of_exprt{lhs}, address_of_exprt{size_symbol}}});
210  }
211  else
212  {
213  const auto &fun_type_params =
214  to_code_type(fun_symbol.type).parameters();
215  const pointer_typet *size_var_type =
216  type_try_dynamic_cast<pointer_typet>(fun_type_params.back().type());
217  INVARIANT(size_var_type, "Size parameter must have pointer type.");
219  fun_symbol.symbol_expr(),
220  {depth, address_of_exprt{lhs}, null_pointer_exprt{*size_var_type}}});
221  }
222  return;
223  }
224  for(const auto &irep_pair :
226  {
227  // skip initialisation of array-size variables
228  if(irep_pair.second == lhs_name)
229  return;
230  }
231  }
232  body.add(code_function_callt{fun_symbol.symbol_expr(),
233  {depth, address_of_exprt{lhs}}});
234 }
235 
237 {
238  const typet &type_to_construct =
240  const null_pointer_exprt nullptr_expr{to_pointer_type(type_to_construct)};
241  const code_assignt assign_null{dereference_exprt{result_symbol},
242  nullptr_expr};
243  return code_blockt{{assign_null, code_frontend_returnt{}}};
244 }
245 
247  const exprt &depth_symbol,
249  const optionalt<exprt> &size_symbol,
250  const optionalt<irep_idt> &lhs_name,
251  const bool is_nullable)
252 {
253  PRECONDITION(result_symbol.type().id() == ID_pointer);
254  const typet &type = to_pointer_type(result_symbol.type()).base_type();
255  if(type.id() == ID_struct_tag)
256  {
257  return build_struct_constructor(depth_symbol, result_symbol);
258  }
259  else if(type.id() == ID_pointer)
260  {
261  if(to_pointer_type(type).base_type().id() == ID_code)
262  {
264  }
265  if(to_pointer_type(type).base_type().id() == ID_empty)
266  {
267  // always initalize void* pointers as NULL
269  }
270  if(lhs_name.has_value())
271  {
272  if(should_be_treated_as_array(*lhs_name))
273  {
274  CHECK_RETURN(size_symbol.has_value());
276  depth_symbol, result_symbol, *size_symbol, lhs_name);
277  }
278  }
279  return build_pointer_constructor(depth_symbol, result_symbol);
280  }
281  else if(type.id() == ID_array)
282  {
283  return build_array_constructor(depth_symbol, result_symbol);
284  }
285  else
286  {
288  }
289 }
290 
292 {
293  // for `expr` of type T builds a declaration of a function:
294  //
295  // void type_constructor_T(int depth_T, T *result);
296  //
297  // or in case a `size` is associated with the `expr`
298  //
299  // void type_constructor_T(int depth_T, T *result_T, int *size);
300  optionalt<irep_idt> size_var;
301  optionalt<irep_idt> expr_name;
302  bool is_nullable = false;
303  bool has_size_param = false;
304  if(expr.id() == ID_symbol)
305  {
306  expr_name = to_symbol_expr(expr).get_identifier();
308  expr_name.value());
309  if(should_be_treated_as_array(*expr_name))
310  {
311  size_var = get_associated_size_variable(*expr_name);
312  has_size_param = true;
313  }
314  }
315  const typet &type = expr.type();
316  const constructor_keyt key{type, is_nullable, has_size_param};
317  if(type_constructor_names.find(key) != type_constructor_names.end())
318  return type_constructor_names[key];
319 
320  const std::string &pretty_type = type2id(type);
321  symbolt &depth_symbol =
322  get_fresh_param_symbol("depth_" + pretty_type, signed_int_type());
323  depth_symbol.value = from_integer(0, signed_int_type());
324 
325  code_typet::parameterst fun_params;
326  code_typet::parametert depth_parameter{signed_int_type()};
327  depth_parameter.set_identifier(depth_symbol.name);
328  fun_params.push_back(depth_parameter);
329 
330  const typet &result_type = pointer_type(type);
331  const symbolt &result_symbol =
332  get_fresh_param_symbol("result_" + pretty_type, result_type);
333  code_typet::parametert result_parameter{result_type};
334  result_parameter.set_identifier(result_symbol.name);
335  fun_params.push_back(result_parameter);
336 
337  auto &symbol_table = goto_model.symbol_table;
338  optionalt<exprt> size_symbol_expr;
339  if(expr_name.has_value() && should_be_treated_as_array(*expr_name))
340  {
341  typet size_var_type;
342  if(size_var.has_value())
343  {
344  const symbol_exprt &size_var_symbol_expr =
345  symbol_table.lookup_ref(*size_var).symbol_expr();
346  size_var_type = pointer_type(size_var_symbol_expr.type());
347  }
348  else
349  size_var_type = pointer_type(signed_int_type());
350 
351  const symbolt &size_symbol =
352  get_fresh_param_symbol("size_" + pretty_type, size_var_type);
353  fun_params.push_back(code_typet::parametert{size_var_type});
354  fun_params.back().set_identifier(size_symbol.name);
355  size_symbol_expr = size_symbol.symbol_expr();
356  }
357  const symbolt &function_symbol = get_fresh_fun_symbol(
358  "type_constructor_" + pretty_type, code_typet{fun_params, empty_typet{}});
359  type_constructor_names[key] = function_symbol.name;
360  symbolt *mutable_symbol = symbol_table.get_writeable(function_symbol.name);
361 
362  // the body is specific for each type of expression
363  mutable_symbol->value = build_constructor_body(
364  depth_symbol.symbol_expr(),
366  size_symbol_expr,
367  // the expression name may be needed to decide if expr should be treated as
368  // a string
369  expr_name,
370  is_nullable);
371 
372  return type_constructor_names.at(key);
373 }
374 
376 {
377  auto malloc_sym = goto_model.symbol_table.lookup("malloc");
378  if(malloc_sym == nullptr)
379  {
380  symbolt new_malloc_sym;
381  new_malloc_sym.type = code_typet{code_typet{
383  new_malloc_sym.name = new_malloc_sym.pretty_name =
384  new_malloc_sym.base_name = "malloc";
385  new_malloc_sym.mode = initialization_config.mode;
386  goto_model.symbol_table.insert(new_malloc_sym);
387  return new_malloc_sym.symbol_expr();
388  }
389  return malloc_sym->symbol_expr();
390 }
391 
393  const irep_idt &array_name) const
394 {
397 }
398 
401 {
402  for(equal_cluster_idt index = 0;
404  ++index)
405  {
406  if(initialization_config.pointers_to_treat_equal[index].count(name) != 0)
407  return index;
408  }
409  return {};
410 }
411 
413  const irep_idt &cmdline_arg) const
414 {
416  cmdline_arg) !=
418 }
419 
421  const irep_idt &array_name) const
422 {
423  return optional_lookup(
425  array_name);
426 }
427 
429  const irep_idt &pointer_name) const
430 {
432  pointer_name) != 0;
433 }
434 
436 {
437  std::ostringstream out{};
438  out << "recursive_initialization_config {"
439  << "\n min_null_tree_depth = " << min_null_tree_depth
440  << "\n max_nondet_tree_depth = " << max_nondet_tree_depth
441  << "\n mode = " << mode
442  << "\n max_dynamic_array_size = " << max_dynamic_array_size
443  << "\n min_dynamic_array_size = " << min_dynamic_array_size
444  << "\n pointers_to_treat_as_arrays = [";
445  for(auto const &pointer : pointers_to_treat_as_arrays)
446  {
447  out << "\n " << pointer;
448  }
449  out << "\n ]"
450  << "\n variables_that_hold_array_sizes = [";
451  for(auto const &array_size : variables_that_hold_array_sizes)
452  {
453  out << "\n " << array_size;
454  }
455  out << "\n ]";
456  out << "\n array_name_to_associated_size_variable = [";
457  for(auto const &associated_array_size :
459  {
460  out << "\n " << associated_array_size.first << " -> "
461  << associated_array_size.second;
462  }
463  out << "\n ]";
464  out << "\n pointers_to_treat_as_cstrings = [";
465  for(const auto &pointer_to_treat_as_string_name :
467  {
468  out << "\n " << pointer_to_treat_as_string_name << std::endl;
469  }
470  out << "\n ]";
471  out << "\n}";
472  return out.str();
473 }
474 
476  symbol_tablet &symbol_table,
477  const std::string &symbol_base_name,
478  typet symbol_type,
479  irep_idt mode)
480 {
481  source_locationt source_location{};
482  source_location.set_file(GOTO_HARNESS_PREFIX "harness.c");
483  symbolt &fresh_symbol = get_fresh_aux_symbol(
484  std::move(symbol_type),
486  symbol_base_name,
488  mode,
489  symbol_table);
490  fresh_symbol.base_name = fresh_symbol.pretty_name = symbol_base_name;
491  fresh_symbol.is_static_lifetime = true;
492  fresh_symbol.is_lvalue = true;
493  fresh_symbol.is_auxiliary = false;
494  fresh_symbol.is_file_local = false;
495  fresh_symbol.is_thread_local = false;
496  fresh_symbol.is_state_var = false;
497  fresh_symbol.module = GOTO_HARNESS_PREFIX "harness";
498  fresh_symbol.location = std::move(source_location);
499  return fresh_symbol;
500 }
501 
503  const std::string &symbol_name,
504  const exprt &initial_value) const
505 {
506  auto &fresh_symbol = get_fresh_global_symbol(
508  symbol_name,
509  signed_int_type(), // FIXME why always signed_int_type???
511  fresh_symbol.value = initial_value;
512  return fresh_symbol.name;
513 }
514 
516  const std::string &symbol_name) const
517 {
518  auto &fresh_symbol = get_fresh_global_symbol(
520  symbol_name,
521  signed_int_type(),
523  fresh_symbol.value = from_integer(0, signed_int_type());
524  return fresh_symbol.symbol_expr();
525 }
526 
528  const std::string &symbol_name) const
529 {
530  symbolt &fresh_symbol = get_fresh_aux_symbol(
531  signed_int_type(),
533  symbol_name,
537  fresh_symbol.is_lvalue = true;
538  fresh_symbol.value = from_integer(0, signed_int_type());
539  return fresh_symbol.symbol_expr();
540 }
541 
543  const std::string &symbol_name,
544  const typet &type) const
545 {
546  symbolt &fresh_symbol = get_fresh_aux_symbol(
547  type,
549  symbol_name,
553  fresh_symbol.is_lvalue = true;
554  fresh_symbol.mode = initialization_config.mode;
555  return fresh_symbol.symbol_expr();
556 }
557 
559  const std::string &fun_name,
560  const typet &fun_type)
561 {
562  irep_idt fresh_name =
564 
565  // create the function symbol
566  symbolt function_symbol{};
567  function_symbol.name = function_symbol.base_name =
568  function_symbol.pretty_name = fresh_name;
569 
570  function_symbol.is_lvalue = true;
571  function_symbol.mode = initialization_config.mode;
572  function_symbol.type = fun_type;
573 
574  auto r = goto_model.symbol_table.insert(function_symbol);
575  CHECK_RETURN(r.second);
576  return *goto_model.symbol_table.lookup(fresh_name);
577 }
578 
580  const std::string &symbol_name,
581  const typet &symbol_type)
582 {
583  symbolt &param_symbol = get_fresh_aux_symbol(
584  symbol_type,
586  symbol_name,
590  param_symbol.is_parameter = true;
591  param_symbol.is_lvalue = true;
592  param_symbol.mode = initialization_config.mode;
593 
594  return param_symbol;
595 }
596 
599 {
600  auto maybe_symbol = goto_model.symbol_table.lookup(symbol_name);
601  CHECK_RETURN(maybe_symbol != nullptr);
602  return maybe_symbol->symbol_expr();
603 }
604 
605 std::string recursive_initializationt::type2id(const typet &type) const
606 {
607  if(type.id() == ID_struct_tag)
608  {
609  auto st_tag = id2string(to_struct_tag_type(type).get_identifier());
610  std::replace(st_tag.begin(), st_tag.end(), '-', '_');
611  return st_tag;
612  }
613  else if(type.id() == ID_pointer)
614  return "ptr_" + type2id(to_pointer_type(type).base_type());
615  else if(type.id() == ID_array)
616  {
617  const auto array_size =
618  numeric_cast_v<std::size_t>(to_constant_expr(to_array_type(type).size()));
619  return "arr_" + type2id(to_array_type(type).element_type()) + "_" +
620  std::to_string(array_size);
621  }
622  else if(type == char_type())
623  return "char";
624  else if(type.id() == ID_signedbv)
625  return "int";
626  else if(type.id() == ID_unsignedbv)
627  return "uint";
628  else
629  return "";
630 }
631 
633 {
634  auto free_sym = goto_model.symbol_table.lookup("free");
635  if(free_sym == nullptr)
636  {
637  symbolt new_free_sym;
638  new_free_sym.type = code_typet{code_typet{
640  new_free_sym.name = new_free_sym.pretty_name = new_free_sym.base_name =
641  "free";
642  new_free_sym.mode = initialization_config.mode;
643  goto_model.symbol_table.insert(new_free_sym);
644  return new_free_sym.symbol_expr();
645  }
646  return free_sym->symbol_expr();
647 }
648 
650  const exprt &depth,
651  const symbol_exprt &result)
652 {
653  PRECONDITION(result.type().id() == ID_pointer);
654  const typet &type = to_pointer_type(result.type()).base_type();
655  PRECONDITION(type.id() == ID_pointer);
656  PRECONDITION(to_pointer_type(type).base_type().id() != ID_empty);
657 
658  code_blockt body{};
659  // build:
660  // void type_constructor_ptr_T(int depth, T** result)
661  // {
662  // if(has_seen && depth >= max_depth)
663  // *result=NULL;
664  // return
665  // if(nondet()) {
666  // size_t has_seen_prev;
667  // has_seen_prev = T_has_seen;
668  // T_has_seen = 1;
669  // *result = malloc(sizeof(T));
670  // type_constructor_T(depth+1, *result);
671  // T_has_seen=has_seen_prev;
672  // }
673  // else
674  // *result=NULL;
675  // }
676 
677  binary_predicate_exprt depth_gt_max_depth{
678  depth, ID_ge, get_symbol_expr(max_depth_var_name)};
679  exprt::operandst should_not_recurse{depth_gt_max_depth};
680 
681  optionalt<symbol_exprt> has_seen;
682  if(can_cast_type<struct_tag_typet>(to_pointer_type(type).base_type()))
683  has_seen = get_fresh_global_symexpr(
684  "has_seen_" + type2id(to_pointer_type(type).base_type()));
685 
686  if(has_seen.has_value())
687  {
688  equal_exprt has_seen_expr{*has_seen, from_integer(1, has_seen->type())};
689  should_not_recurse.push_back(has_seen_expr);
690  }
691 
692  null_pointer_exprt nullptr_expr{
693  pointer_type(to_pointer_type(type).base_type())};
694  const code_assignt assign_null{dereference_exprt{result}, nullptr_expr};
695  code_blockt null_and_return{{assign_null, code_frontend_returnt{}}};
696  body.add(code_ifthenelset{conjunction(should_not_recurse), null_and_return});
697 
698  const auto should_recurse_nondet =
699  get_fresh_local_typed_symexpr("should_recurse_nondet", bool_typet{});
700  body.add(code_declt{should_recurse_nondet});
701  exprt::operandst should_recurse_ops{
703  should_recurse_nondet};
704  code_blockt then_case{};
705 
706  code_assignt seen_assign_prev{};
707  if(has_seen.has_value())
708  {
709  const symbol_exprt &has_seen_prev = get_fresh_local_symexpr(
710  "has_seen_prev_" + type2id(to_pointer_type(type).base_type()));
711  then_case.add(code_declt{has_seen_prev});
712  then_case.add(code_assignt{has_seen_prev, *has_seen});
713  then_case.add(code_assignt{*has_seen, from_integer(1, has_seen->type())});
714  seen_assign_prev = code_assignt{*has_seen, has_seen_prev};
715  }
716 
717  // we want to initialize the pointee as non-const even for pointer to const
718  const pointer_typet non_const_pointer_type =
719  pointer_type(remove_const(to_pointer_type(type).base_type()));
720  const symbol_exprt &local_result =
721  get_fresh_local_typed_symexpr("local_result", non_const_pointer_type);
722 
723  then_case.add(code_declt{local_result});
725  then_case.add(code_function_callt{
726  local_result,
728  {*size_of_expr(non_const_pointer_type.base_type(), ns)}});
729  initialize(
730  dereference_exprt{local_result},
731  plus_exprt{depth, from_integer(1, depth.type())},
732  then_case);
733  then_case.add(code_assignt{dereference_exprt{result}, local_result});
734 
735  if(has_seen.has_value())
736  {
737  then_case.add(seen_assign_prev);
738  }
739 
740  body.add(
741  code_ifthenelset{disjunction(should_recurse_ops), then_case, assign_null});
742  return body;
743 }
744 
746  const exprt &depth,
747  const symbol_exprt &result)
748 {
749  PRECONDITION(result.type().id() == ID_pointer);
750  const typet &type = to_pointer_type(result.type()).base_type();
751  PRECONDITION(type.id() == ID_array);
752  const array_typet &array_type = to_array_type(type);
753  const auto array_size =
754  numeric_cast_v<std::size_t>(to_constant_expr(array_type.size()));
755  code_blockt body{};
756 
757  for(std::size_t index = 0; index < array_size; index++)
758  {
759  initialize(
761  depth,
762  body);
763  }
764  return body;
765 }
766 
768  const exprt &depth,
769  const symbol_exprt &result)
770 {
771  PRECONDITION(result.type().id() == ID_pointer);
772  const typet &struct_type = to_pointer_type(result.type()).base_type();
773  PRECONDITION(struct_type.id() == ID_struct_tag);
774  code_blockt body{};
776  for(const auto &component :
777  ns.follow_tag(to_struct_tag_type(struct_type)).components())
778  {
779  if(component.get_is_padding())
780  {
781  continue;
782  }
783  // if the struct component is const we need to cast away the const
784  // for initialisation purposes.
785  // As far as I'm aware that's the closest thing to a 'correct' way
786  // to initialize dynamically allocated structs with const components
787  exprt component_initialisation_lhs = [&result, &component]() -> exprt {
788  auto member_expr = member_exprt{dereference_exprt{result}, component};
789  if(component.type().get_bool(ID_C_constant))
790  {
791  return dereference_exprt{
792  typecast_exprt{address_of_exprt{std::move(member_expr)},
794  }
795  else
796  {
797  return std::move(member_expr);
798  }
799  }();
800  initialize(component_initialisation_lhs, depth, body);
801  }
802  return body;
803 }
804 
806  const symbol_exprt &result) const
807 {
808  PRECONDITION(result.type().id() == ID_pointer);
809  code_blockt body{};
810  auto const nondet_symbol = get_fresh_local_typed_symexpr(
811  "nondet", to_pointer_type(result.type()).base_type());
812  body.add(code_declt{nondet_symbol});
813  body.add(code_assignt{dereference_exprt{result}, nondet_symbol});
814  return body;
815 }
816 
818  const exprt &depth,
819  const symbol_exprt &result,
820  const exprt &size,
821  const optionalt<irep_idt> &lhs_name)
822 {
823  PRECONDITION(result.type().id() == ID_pointer);
824  const typet &dynamic_array_type = to_pointer_type(result.type()).base_type();
825  PRECONDITION(dynamic_array_type.id() == ID_pointer);
826  const typet &element_type = to_pointer_type(dynamic_array_type).base_type();
827  PRECONDITION(element_type.id() != ID_empty);
828 
829  // builds:
830  // void type_constructor_ptr_T(int depth, T** result, int* size)
831  // {
832  // int nondet_size;
833  // assume(nondet_size >= min_array_size && nondet_size <= max_array_size);
834  // T* local_result = malloc(nondet_size * sizeof(T));
835  // for (int i = 0; i < nondet_size; ++i)
836  // {
837  // type_construct_T(depth+1, local_result+i);
838  // }
839  // *result = local_result;
840  // if (size!=NULL)
841  // *size = nondet_size;
842  // }
843 
844  const auto min_array_size = initialization_config.min_dynamic_array_size;
845  const auto max_array_size = initialization_config.max_dynamic_array_size;
846  PRECONDITION(max_array_size >= min_array_size);
847 
848  code_blockt body{};
849  const symbol_exprt &nondet_size = get_fresh_local_symexpr("nondet_size");
850  body.add(code_declt{nondet_size});
851 
852  body.add(code_assumet{and_exprt{
854  nondet_size, ID_ge, from_integer(min_array_size, nondet_size.type())},
856  nondet_size, ID_le, from_integer(max_array_size, nondet_size.type())}}});
857 
858  // we want the local result to be mutable so we can initialise it
859  const typet mutable_dynamic_array_type =
860  pointer_type(remove_const(element_type));
861  const symbol_exprt &local_result =
862  get_fresh_local_typed_symexpr("local_result", mutable_dynamic_array_type);
863  body.add(code_declt{local_result});
865  for(auto array_size = min_array_size; array_size <= max_array_size;
866  ++array_size)
867  {
868  body.add(code_ifthenelset{
869  equal_exprt{nondet_size, from_integer(array_size, nondet_size.type())},
870  code_function_callt{local_result,
872  {mult_exprt{from_integer(array_size, size_type()),
873  *size_of_expr(element_type, ns)}}}});
874  }
875 
876  const symbol_exprt &index_iter = get_fresh_local_symexpr("index");
877  body.add(code_declt{index_iter});
878  code_assignt for_init{index_iter, from_integer(0, index_iter.type())};
879  binary_relation_exprt for_cond{index_iter, ID_lt, nondet_size};
880  side_effect_exprt for_iter{
881  ID_preincrement, {index_iter}, typet{}, source_locationt{}};
882  code_blockt for_body{};
883  if(lhs_name.has_value() && should_be_treated_as_cstring(*lhs_name))
884  {
885  code_blockt else_case{};
886  initialize(
887  dereference_exprt{plus_exprt{local_result, index_iter}},
888  plus_exprt{depth, from_integer(1, depth.type())},
889  else_case);
890  else_case.add(code_assumet{
891  notequal_exprt{dereference_exprt{plus_exprt{local_result, index_iter}},
892  from_integer(0, char_type())}});
893 
894  for_body.add(code_ifthenelset{
895  equal_exprt{
896  index_iter,
897  minus_exprt{nondet_size, from_integer(1, nondet_size.type())}},
898  code_assignt{dereference_exprt{plus_exprt{local_result, index_iter}},
899  from_integer(0, char_type())},
900  else_case});
901  }
902  else
903  {
904  initialize(
905  dereference_exprt{plus_exprt{local_result, index_iter}},
906  plus_exprt{depth, from_integer(1, depth.type())},
907  for_body);
908  }
909 
910  body.add(code_fort{for_init, for_cond, for_iter, for_body});
911  body.add(code_assignt{dereference_exprt{result}, local_result});
912 
913  CHECK_RETURN(size.type().id() == ID_pointer);
914  body.add(code_ifthenelset{
916  code_assignt{
917  dereference_exprt{size},
919  nondet_size, to_pointer_type(size.type()).base_type())}});
920 
921  return body;
922 }
923 
925 {
926  if(
927  expr.type().id() != ID_pointer ||
928  to_pointer_type(expr.type()).base_type().id() == ID_code)
929  return false;
930  for(auto const &common_arguments_origin : common_arguments_origins)
931  {
932  if(common_arguments_origin.has_value() && expr.id() == ID_symbol)
933  {
934  auto origin_name =
935  to_symbol_expr(*common_arguments_origin).get_identifier();
936  auto expr_name = to_symbol_expr(expr).get_identifier();
937  return origin_name == expr_name;
938  }
939  }
940  return true;
941 }
942 
944  const exprt &expr,
945  code_blockt &body)
946 {
947  PRECONDITION(expr.id() == ID_symbol);
948  const auto expr_id = to_symbol_expr(expr).get_identifier();
949  const auto maybe_cluster_index = find_equal_cluster(expr_id);
950  const auto call_free = code_function_callt{get_free_function(), {expr}};
951  if(!maybe_cluster_index.has_value())
952  {
953  // not in any equality cluster -> just free
954  body.add(call_free);
955  return;
956  }
957 
958  if(
959  to_symbol_expr(*common_arguments_origins[*maybe_cluster_index])
960  .get_identifier() != expr_id &&
962  {
963  // in equality cluster but not common origin -> free if not equal to origin
964  const auto condition =
965  notequal_exprt{expr, *common_arguments_origins[*maybe_cluster_index]};
966  body.add(code_ifthenelset{condition, call_free});
967  }
968  else
969  {
970  // expr is common origin, leave freeing until the rest of the cluster is
971  // freed
972  return;
973  }
974 }
975 
977 {
978  for(auto const &origin : common_arguments_origins)
979  {
980  body.add(code_function_callt{get_free_function(), {*origin}});
981  }
982 }
983 
985  const symbol_exprt &result,
986  bool is_nullable)
987 {
989  const auto &result_type = to_pointer_type(result.type());
990  PRECONDITION(can_cast_type<pointer_typet>(result_type.base_type()));
991  const auto &function_pointer_type = to_pointer_type(result_type.base_type());
992  PRECONDITION(can_cast_type<code_typet>(function_pointer_type.base_type()));
993  const auto &function_type = to_code_type(function_pointer_type.base_type());
994 
995  std::vector<exprt> targets;
996 
997  for(const auto &sym : goto_model.get_symbol_table())
998  {
999  if(sym.second.type == function_type)
1000  {
1001  targets.push_back(address_of_exprt{sym.second.symbol_expr()});
1002  }
1003  }
1004 
1005  if(is_nullable)
1006  targets.push_back(null_pointer_exprt{function_pointer_type});
1007 
1008  code_blockt body{};
1009 
1010  const auto function_pointer_selector =
1011  get_fresh_local_symexpr("function_pointer_selector");
1012  body.add(code_declt{function_pointer_selector});
1013  auto function_pointer_index = std::size_t{0};
1014 
1015  for(const auto &target : targets)
1016  {
1017  auto const assign = code_assignt{dereference_exprt{result}, target};
1018  auto const sym_to_lookup =
1019  target.id() == ID_address_of
1020  ?
1021  // This is either address of or pointer; in pointer case, we don't
1022  // need to do anything. In the address of case, the operand is
1023  // a symbol representing a target function.
1025  : "";
1026  // skip referencing globals because the corresponding symbols in the symbol
1027  // table are no longer marked as file local.
1028  if(has_prefix(id2string(sym_to_lookup), FILE_LOCAL_PREFIX))
1029  {
1030  continue;
1031  }
1032  else if(
1033  goto_model.get_symbol_table().lookup(sym_to_lookup) &&
1034  goto_model.get_symbol_table().lookup(sym_to_lookup)->is_file_local)
1035  {
1036  continue;
1037  }
1038 
1039  if(function_pointer_index != targets.size() - 1)
1040  {
1041  auto const condition = equal_exprt{
1042  function_pointer_selector,
1043  from_integer(function_pointer_index, function_pointer_selector.type())};
1044  auto const then = code_blockt{{assign, code_frontend_returnt{}}};
1045  body.add(code_ifthenelset{condition, then});
1046  }
1047  else
1048  {
1049  body.add(assign);
1050  }
1051  ++function_pointer_index;
1052  }
1053 
1054  return body;
1055 }
1056 
1058  const exprt &lhs,
1059  const exprt &depth,
1060  code_blockt &body,
1061  const std::vector<irep_idt> &selection_spec)
1062 {
1063  PRECONDITION(lhs.id() == ID_symbol);
1064  PRECONDITION(lhs.type().id() == ID_struct_tag);
1065  PRECONDITION(!selection_spec.empty());
1066 
1067  auto component_member = lhs;
1069 
1070  for(auto it = selection_spec.begin() + 1; it != selection_spec.end(); it++)
1071  {
1072  if(component_member.type().id() != ID_struct_tag)
1073  {
1075  "'" + id2string(*it) + "' is not a component name",
1077  }
1078  const auto &struct_tag_type = to_struct_tag_type(component_member.type());
1079  const auto &struct_type = to_struct_type(ns.follow_tag(struct_tag_type));
1080 
1081  bool found = false;
1082  for(auto const &component : struct_type.components())
1083  {
1084  const auto &component_type = component.type();
1085  const auto component_name = component.get_name();
1086 
1087  if(*it == component_name)
1088  {
1089  component_member =
1090  member_exprt{component_member, component_name, component_type};
1091  found = true;
1092  break;
1093  }
1094  }
1095  if(!found)
1096  {
1098  "'" + id2string(*it) + "' is not a component name",
1100  }
1101  }
1102  initialize(component_member, depth, body);
1103 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
pointer_offset_size.h
recursive_initialization_configt::pointers_to_treat_as_cstrings
std::set< irep_idt > pointers_to_treat_as_cstrings
Definition: recursive_initialization.h:41
array_name
std::string array_name(const namespacet &ns, const exprt &expr)
Definition: array_name.cpp:19
code_blockt
A codet representing sequential composition of program statements.
Definition: std_code.h:129
typecast_exprt::conditional_cast
static exprt conditional_cast(const exprt &expr, const typet &type)
Definition: std_expr.h:2025
COMMON_HARNESS_GENERATOR_FUNCTION_POINTER_CAN_BE_NULL_OPT
#define COMMON_HARNESS_GENERATOR_FUNCTION_POINTER_CAN_BE_NULL_OPT
Definition: common_harness_generator_options.h:17
symbolt::is_state_var
bool is_state_var
Definition: symbol.h:62
symbol_tablet
The symbol table.
Definition: symbol_table.h:13
recursive_initializationt::get_fresh_local_typed_symexpr
symbol_exprt get_fresh_local_typed_symexpr(const std::string &symbol_name, const typet &type) const
Construct a new local symbol of type type initialised to init_value.
Definition: recursive_initialization.cpp:542
symbol_table_baset::lookup_ref
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Definition: symbol_table_base.h:104
conjunction
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:62
recursive_initializationt::min_depth_var_name
irep_idt min_depth_var_name
Definition: recursive_initialization.h:124
arith_tools.h
recursive_initializationt::build_array_constructor
code_blockt build_array_constructor(const exprt &depth, const symbol_exprt &result)
Constructor for arrays: simply iterates over elements and initialise each one.
Definition: recursive_initialization.cpp:745
to_struct_type
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
Definition: std_types.h:308
recursive_initializationt::goto_model
goto_modelt & goto_model
Definition: recursive_initialization.h:122
recursive_initializationt::get_symbol_expr
symbol_exprt get_symbol_expr(const irep_idt &symbol_name) const
Recover the symbol expression from symbol table.
Definition: recursive_initialization.cpp:598
get_new_name
irep_idt get_new_name(const irep_idt &name, const namespacet &ns, char delimiter)
Build and identifier not yet present in the namespace ns based on name.
Definition: rename.cpp:16
code_fort
codet representation of a for statement.
Definition: std_code.h:733
CHECK_RETURN
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:495
string_utils.h
typet
The type of an expression, extends irept.
Definition: type.h:28
code_typet::parameterst
std::vector< parametert > parameterst
Definition: std_types.h:541
recursive_initialization.h
fresh_symbol.h
recursive_initializationt::build_constructor
irep_idt build_constructor(const exprt &expr)
Check if a constructor for the type of expr already exists and create it if not.
Definition: recursive_initialization.cpp:291
transform
static abstract_object_pointert transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns)
Definition: abstract_value_object.cpp:159
recursive_initializationt::initialize_selected_member
void initialize_selected_member(const exprt &lhs, const exprt &depth, code_blockt &body, const std::vector< irep_idt > &selection_spec)
Select the specified struct-member to be non-deterministically initialized.
Definition: recursive_initialization.cpp:1057
symbolt::type
typet type
Type of symbol.
Definition: symbol.h:31
recursive_initializationt::get_malloc_function
symbol_exprt get_malloc_function()
Get the malloc function as symbol exprt, and inserts it into the goto-model if it doesn't exist alrea...
Definition: recursive_initialization.cpp:375
dereference_exprt
Operator to dereference a pointer.
Definition: pointer_expr.h:659
recursive_initializationt::get_associated_size_variable
optionalt< irep_idt > get_associated_size_variable(const irep_idt &array_name) const
Definition: recursive_initialization.cpp:420
recursive_initializationt::get_fresh_local_symexpr
symbol_exprt get_fresh_local_symexpr(const std::string &symbol_name) const
Construct a new local symbol of type int initialised to 0.
Definition: recursive_initialization.cpp:527
COMMON_HARNESS_GENERATOR_HAVOC_MEMBER_OPT
#define COMMON_HARNESS_GENERATOR_HAVOC_MEMBER_OPT
Definition: common_harness_generator_options.h:19
replace
void replace(const union_find_replacet &replace_map, string_not_contains_constraintt &constraint)
Definition: string_constraint.cpp:70
code_declt
A goto_instruction_codet representing the declaration of a local variable.
Definition: goto_instruction_code.h:204
FILE_LOCAL_PREFIX
#define FILE_LOCAL_PREFIX
Definition: name_mangler.h:16
and_exprt
Boolean AND.
Definition: std_expr.h:2070
plus_exprt
The plus expression Associativity is not specified.
Definition: std_expr.h:946
recursive_initialization_configt::array_name_to_associated_array_size_variable
std::map< irep_idt, irep_idt > array_name_to_associated_array_size_variable
Definition: recursive_initialization.h:39
exprt
Base class for all expressions.
Definition: expr.h:55
goto_modelt
Definition: goto_model.h:25
goto_harness_generator.h
symbolt::base_name
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:46
recursive_initialization_configt::selection_specs
std::vector< std::vector< irep_idt > > selection_specs
Definition: recursive_initialization.h:46
component
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
Definition: std_expr.cpp:76
bool_typet
The Boolean type.
Definition: std_types.h:35
to_string
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Definition: string_constraint.cpp:58
harness_options_parser::require_exactly_one_value
std::string require_exactly_one_value(const std::string &option, const std::list< std::string > &values)
Returns the only value of a single element list, throws an exception if not passed a single element l...
Definition: goto_harness_generator.cpp:21
recursive_initialization_configt::mode
irep_idt mode
Definition: recursive_initialization.h:30
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:112
equal_exprt
Equality.
Definition: std_expr.h:1305
recursive_initializationt::free_cluster_origins
void free_cluster_origins(code_blockt &body)
Definition: recursive_initialization.cpp:976
recursive_initializationt::is_array_size_parameter
bool is_array_size_parameter(const irep_idt &cmdline_arg) const
Definition: recursive_initialization.cpp:412
recursive_initializationt::initialize
void initialize(const exprt &lhs, const exprt &depth, code_blockt &body)
Generate initialisation code for lhs into body.
Definition: recursive_initialization.cpp:138
can_cast_type< pointer_typet >
bool can_cast_type< pointer_typet >(const typet &type)
Check whether a reference to a typet is a pointer_typet.
Definition: pointer_expr.h:66
recursive_initializationt::find_equal_cluster
optionalt< equal_cluster_idt > find_equal_cluster(const irep_idt &name) const
Definition: recursive_initialization.cpp:400
code_ifthenelset
codet representation of an if-then-else statement.
Definition: std_code.h:459
notequal_exprt
Disequality.
Definition: std_expr.h:1364
recursive_initializationt::build_function_pointer_constructor
code_blockt build_function_pointer_constructor(const symbol_exprt &result, bool is_nullable)
Constructor for function pointers.
Definition: recursive_initialization.cpp:984
symbolt::pretty_name
irep_idt pretty_name
Language-specific display name.
Definition: symbol.h:52
recursive_initializationt::constructor_keyt
Definition: recursive_initialization.h:67
recursive_initialization_configt::pointers_to_treat_as_arrays
std::set< irep_idt > pointers_to_treat_as_arrays
Definition: recursive_initialization.h:37
recursive_initializationt::should_be_treated_as_array
bool should_be_treated_as_array(const irep_idt &pointer_name) const
Definition: recursive_initialization.cpp:392
array_typet::size
const exprt & size() const
Definition: std_types.h:800
remove_const
typet remove_const(typet type)
Remove const qualifier from type (if any).
Definition: type.cpp:32
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
recursive_initializationt::needs_freeing
bool needs_freeing(const exprt &expr) const
Definition: recursive_initialization.cpp:924
recursive_initialization_configt::max_nondet_tree_depth
std::size_t max_nondet_tree_depth
Definition: recursive_initialization.h:29
recursive_initializationt::get_fresh_param_symbol
symbolt & get_fresh_param_symbol(const std::string &param_name, const typet &param_type)
Construct a new parameter symbol of type param_type.
Definition: recursive_initialization.cpp:579
string2int.h
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:84
symbolt::is_thread_local
bool is_thread_local
Definition: symbol.h:65
build_null_pointer
code_blockt build_null_pointer(const symbol_exprt &result_symbol)
Definition: recursive_initialization.cpp:236
code_function_callt
goto_instruction_codet representation of a function call statement.
Definition: goto_instruction_code.h:271
split_string
void split_string(const std::string &s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)
Definition: string_utils.cpp:39
can_cast_type< code_typet >
bool can_cast_type< code_typet >(const typet &type)
Check whether a reference to a typet is a code_typet.
Definition: std_types.h:731
recursive_initialization_configt::max_dynamic_array_size
std::size_t max_dynamic_array_size
Definition: recursive_initialization.h:34
to_code_type
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition: std_types.h:744
disjunction
exprt disjunction(const exprt::operandst &op)
1) generates a disjunction for two or more operands 2) for one operand, returns the operand 3) return...
Definition: std_expr.cpp:50
result_symbol
static symbolt result_symbol(const irep_idt &identifier, const typet &type, const source_locationt &source_location, symbol_tablet &symbol_table)
Definition: c_typecheck_gcc_polymorphic_builtins.cpp:609
symbolt::mode
irep_idt mode
Language mode.
Definition: symbol.h:49
empty_typet
The empty type.
Definition: std_types.h:50
signed_int_type
signedbv_typet signed_int_type()
Definition: c_types.cpp:40
has_prefix
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
rename.h
recursive_initializationt::build_pointer_constructor
code_blockt build_pointer_constructor(const exprt &depth, const symbol_exprt &result)
Generic constructor for all pointers: only builds one pointee (not an array) but may recourse in case...
Definition: recursive_initialization.cpp:649
recursive_initialization_configt::arguments_may_be_equal
bool arguments_may_be_equal
Definition: recursive_initialization.h:44
null_pointer_exprt
The null pointer constant.
Definition: pointer_expr.h:734
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:47
recursive_initialization_configt::potential_null_function_pointers
std::unordered_set< irep_idt > potential_null_function_pointers
Definition: recursive_initialization.h:31
can_cast_type< struct_tag_typet >
bool can_cast_type< struct_tag_typet >(const typet &type)
Check whether a reference to a typet is a struct_tag_typet.
Definition: std_types.h:461
get_identifier
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)
Definition: smt2_incremental_decision_procedure.cpp:328
binary_predicate_exprt
A base class for expressions that are predicates, i.e., Boolean-typed, and that take exactly two argu...
Definition: std_expr.h:675
PRECONDITION
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
recursive_initializationt::get_fresh_global_symexpr
symbol_exprt get_fresh_global_symexpr(const std::string &symbol_name) const
Construct a new global symbol of type int initialised to 0.
Definition: recursive_initialization.cpp:515
recursive_initializationt::type_constructor_names
type_constructor_namest type_constructor_names
Definition: recursive_initialization.h:125
optional_utils.h
symbol_exprt::get_identifier
const irep_idt & get_identifier() const
Definition: std_expr.h:142
optional_lookup
auto optional_lookup(const map_like_collectiont &map, const keyt &key) -> optionalt< decltype(map.find(key) ->second)>
Lookup a key in a map, if found return the associated value, nullopt otherwise.
Definition: optional_utils.h:17
code_assumet
An assumption, which must hold in subsequent code.
Definition: std_code.h:216
source_locationt::set_file
void set_file(const irep_idt &file)
Definition: source_location.h:90
symbolt::symbol_expr
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Definition: symbol.cpp:121
pointer_expr.h
recursive_initializationt::build_dynamic_array_constructor
code_blockt build_dynamic_array_constructor(const exprt &depth, const symbol_exprt &result, const exprt &size, const optionalt< irep_idt > &lhs_name)
Constructor for dynamic arrays: allocate memory for n elements (n is random but bounded) and initiali...
Definition: recursive_initialization.cpp:817
mult_exprt
Binary multiplication Associativity is not specified.
Definition: std_expr.h:1051
to_pointer_type
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition: pointer_expr.h:79
symbol_tablet::insert
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
Definition: symbol_table.cpp:17
pointer_type
pointer_typet pointer_type(const typet &subtype)
Definition: c_types.cpp:253
to_symbol_expr
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition: std_expr.h:222
code_typet
Base type of functions.
Definition: std_types.h:538
symbolt::is_parameter
bool is_parameter
Definition: symbol.h:67
irept::id
const irep_idt & id() const
Definition: irep.h:396
COMMON_HARNESS_GENERATOR_MAX_NONDET_TREE_DEPTH_OPT
#define COMMON_HARNESS_GENERATOR_MAX_NONDET_TREE_DEPTH_OPT
Definition: common_harness_generator_options.h:13
to_struct_tag_type
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition: std_types.h:474
exprt::operandst
std::vector< exprt > operandst
Definition: expr.h:58
code_blockt::add
void add(const codet &code)
Definition: std_code.h:168
recursive_initializationt::recursive_initializationt
recursive_initializationt(recursive_initialization_configt initialization_config, goto_modelt &goto_model)
Definition: recursive_initialization.cpp:118
GOTO_HARNESS_PREFIX
#define GOTO_HARNESS_PREFIX
Definition: recursive_initialization.h:25
recursive_initializationt::get_fresh_fun_symbol
const symbolt & get_fresh_fun_symbol(const std::string &fun_name, const typet &fun_type)
Construct a new function symbol of type fun_type.
Definition: recursive_initialization.cpp:558
code_typet::parameters
const parameterst & parameters() const
Definition: std_types.h:655
recursive_initializationt::get_fresh_global_name
irep_idt get_fresh_global_name(const std::string &symbol_name, const exprt &initial_value) const
Construct a new global symbol of type int and set it's value to initial_value.
Definition: recursive_initialization.cpp:502
std_code.h
common_harness_generator_options.h
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
recursive_initializationt::common_arguments_origins
std::vector< optionalt< exprt > > common_arguments_origins
Definition: recursive_initialization.h:126
recursive_initialization_configt::handle_option
bool handle_option(const std::string &option, const std::list< std::string > &values)
Parse the options specific for recursive initialisation.
Definition: recursive_initialization.cpp:30
minus_exprt
Binary minus.
Definition: std_expr.h:1005
char_type
bitvector_typet char_type()
Definition: c_types.cpp:124
code_frontend_returnt
codet representation of a "return from a function" statement.
Definition: std_code.h:892
source_locationt
Definition: source_location.h:18
recursive_initializationt::build_constructor_body
code_blockt build_constructor_body(const exprt &depth_symbol, const symbol_exprt &result_symbol, const optionalt< exprt > &size_symbol, const optionalt< irep_idt > &lhs_name, const bool is_nullable)
Case analysis for which constructor should be used.
Definition: recursive_initialization.cpp:246
recursive_initializationt::free_if_possible
void free_if_possible(const exprt &expr, code_blockt &body)
Definition: recursive_initialization.cpp:943
recursive_initialization_configt::variables_that_hold_array_sizes
std::set< irep_idt > variables_that_hold_array_sizes
Definition: recursive_initialization.h:38
recursive_initializationt::should_be_treated_as_cstring
bool should_be_treated_as_cstring(const irep_idt &pointer_name) const
Definition: recursive_initialization.cpp:428
symbol_table_baset::add
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
Definition: symbol_table_base.cpp:18
member_exprt
Extract member of struct or union.
Definition: std_expr.h:2793
symbolt::value
exprt value
Initial value of symbol.
Definition: symbol.h:34
irept::add
irept & add(const irep_idt &name)
Definition: irep.cpp:116
array_typet
Arrays with given size.
Definition: std_types.h:762
recursive_initializationt::type2id
std::string type2id(const typet &type) const
Simple pretty-printer for typet.
Definition: recursive_initialization.cpp:605
symbolt::location
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:37
COMMON_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT
#define COMMON_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT
Definition: common_harness_generator_options.h:15
recursive_initialization_configt::min_dynamic_array_size
std::size_t min_dynamic_array_size
Definition: recursive_initialization.h:35
symbolt
Symbol table entry.
Definition: symbol.h:27
from_integer
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
Definition: arith_tools.cpp:100
recursive_initializationt::get_free_function
symbol_exprt get_free_function()
Get the free function as symbol expression, and inserts it into the goto-model if it doesn't exist al...
Definition: recursive_initialization.cpp:632
harness_options_parser::require_one_size_value
std::size_t require_one_size_value(const std::string &option, const std::list< std::string > &values)
Returns the only Nat value of a single element list, throws an exception if not passed a single eleme...
Definition: goto_harness_generator.cpp:41
goto_modelt::get_symbol_table
const symbol_tablet & get_symbol_table() const override
Accessor to get the symbol table.
Definition: goto_model.h:77
binary_relation_exprt
A base class for relations, i.e., binary predicates whose two operands have the same type.
Definition: std_expr.h:706
symbolt::is_auxiliary
bool is_auxiliary
Definition: symbol.h:67
pointer_typet::base_type
const typet & base_type() const
The type of the data what we point to.
Definition: pointer_expr.h:35
to_array_type
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
Definition: std_types.h:844
code_typet::parametert
Definition: std_types.h:555
recursive_initialization_configt
Definition: recursive_initialization.h:26
symbolt::is_static_lifetime
bool is_static_lifetime
Definition: symbol.h:65
recursive_initialization_configt::min_null_tree_depth
std::size_t min_null_tree_depth
Definition: recursive_initialization.h:28
recursive_initializationt::equal_cluster_idt
std::size_t equal_cluster_idt
Definition: recursive_initialization.h:66
symbol_table_baset::lookup
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Definition: symbol_table_base.h:95
size_of_expr
optionalt< exprt > size_of_expr(const typet &type, const namespacet &ns)
Definition: pointer_offset_size.cpp:280
recursive_initializationt::build_nondet_constructor
code_blockt build_nondet_constructor(const symbol_exprt &result) const
Default constructor: assigns non-deterministic value of the right type.
Definition: recursive_initialization.cpp:805
to_address_of_expr
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
Definition: pointer_expr.h:408
symbolt::is_file_local
bool is_file_local
Definition: symbol.h:66
r
static int8_t r
Definition: irep_hash.h:60
symbolt::is_lvalue
bool is_lvalue
Definition: symbol.h:66
COMMON_HARNESS_GENERATOR_MIN_NULL_TREE_DEPTH_OPT
#define COMMON_HARNESS_GENERATOR_MIN_NULL_TREE_DEPTH_OPT
Definition: common_harness_generator_options.h:12
get_fresh_global_symbol
static symbolt & get_fresh_global_symbol(symbol_tablet &symbol_table, const std::string &symbol_base_name, typet symbol_type, irep_idt mode)
Definition: recursive_initialization.cpp:475
index_exprt
Array index operator.
Definition: std_expr.h:1409
address_of_exprt
Operator to return the address of an object.
Definition: pointer_expr.h:370
typecast_exprt
Semantic type conversion.
Definition: std_expr.h:2016
pointer_typet
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
Definition: pointer_expr.h:23
size_type
unsignedbv_typet size_type()
Definition: c_types.cpp:68
COMMON_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT
#define COMMON_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT
Definition: common_harness_generator_options.h:16
code_assignt
A goto_instruction_codet representing an assignment in the program.
Definition: goto_instruction_code.h:22
recursive_initialization_configt::to_string
std::string to_string() const
Definition: recursive_initialization.cpp:435
symbolt::module
irep_idt module
Name of module the symbol belongs to.
Definition: symbol.h:43
recursive_initializationt::initialization_config
const recursive_initialization_configt initialization_config
Definition: recursive_initialization.h:121
invalid_command_line_argument_exceptiont
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
Definition: exception_utils.h:50
goto_modelt::symbol_table
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:30
c_types.h
get_fresh_aux_symbol
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 ...
Definition: fresh_symbol.cpp:32
symbolt::name
irep_idt name
The unique identifier.
Definition: symbol.h:40
name_mangler.h
Mangle names of file-local functions to make them unique.
recursive_initializationt::max_depth_var_name
irep_idt max_depth_var_name
Definition: recursive_initialization.h:123
side_effect_exprt
An expression containing a side effect.
Definition: std_code.h:1449
validation_modet::INVARIANT
@ INVARIANT
irep.h
recursive_initialization_configt::pointers_to_treat_equal
std::vector< std::set< irep_idt > > pointers_to_treat_equal
Definition: recursive_initialization.h:42
recursive_initializationt::build_struct_constructor
code_blockt build_struct_constructor(const exprt &depth, const symbol_exprt &result)
Constructor for structures: simply iterates over members and initialise each one.
Definition: recursive_initialization.cpp:767
to_constant_expr
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
Definition: std_expr.h:2992