CBMC
jbmc_parse_options.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: JBMC Command Line Option Processing
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "jbmc_parse_options.h"
13 
14 #include <util/config.h>
15 #include <util/exit_codes.h>
16 #include <util/help_formatter.h>
17 #include <util/invariant.h>
18 #include <util/version.h>
19 #include <util/xml.h>
20 
24 #include <goto-programs/loop_ids.h>
33 
34 #include <ansi-c/ansi_c_language.h>
57 #include <langapi/language.h>
58 #include <langapi/mode.h>
61 
62 #include <cstdlib> // exit()
63 #include <iostream>
64 #include <memory>
65 
66 jbmc_parse_optionst::jbmc_parse_optionst(int argc, const char **argv)
69  argc,
70  argv,
71  std::string("JBMC ") + CBMC_VERSION)
72 {
75 }
76 
78  int argc,
79  const char **argv,
80  const std::string &extra_options)
82  JBMC_OPTIONS + extra_options,
83  argc,
84  argv,
85  std::string("JBMC ") + CBMC_VERSION)
86 {
89 }
90 
92 {
93  // Default true
94  options.set_option("assertions", true);
95  options.set_option("assumptions", true);
96  options.set_option("built-in-assertions", true);
97  options.set_option("propagation", true);
98  options.set_option("refine-strings", true);
99  options.set_option("simple-slice", true);
100  options.set_option("simplify", true);
101  options.set_option("show-goto-symex-steps", false);
102 
103  // Other default
104  options.set_option("arrays-uf", "auto");
105  options.set_option("depth", UINT32_MAX);
106 }
107 
109 {
110  if(config.set(cmdline))
111  {
112  usage_error();
113  exit(1); // should contemplate EX_USAGE from sysexits.h
114  }
115 
117 
118  if(cmdline.isset("function"))
119  options.set_option("function", cmdline.get_value("function"));
120 
123 
124  if(cmdline.isset("max-field-sensitivity-array-size"))
125  {
126  options.set_option(
127  "max-field-sensitivity-array-size",
128  cmdline.get_value("max-field-sensitivity-array-size"));
129  }
130 
131  if(cmdline.isset("no-array-field-sensitivity"))
132  {
133  if(cmdline.isset("max-field-sensitivity-array-size"))
134  {
135  log.error()
136  << "--no-array-field-sensitivity and --max-field-sensitivity-array-size"
137  << " must not be given together" << messaget::eom;
139  }
140  options.set_option("no-array-field-sensitivity", true);
141  }
142 
143  if(cmdline.isset("show-symex-strategies"))
144  {
147  }
148 
150 
151  if(cmdline.isset("program-only"))
152  options.set_option("program-only", true);
153 
154  if(cmdline.isset("show-vcc"))
155  options.set_option("show-vcc", true);
156 
157  if(cmdline.isset("nondet-static"))
158  options.set_option("nondet-static", true);
159 
160  if(cmdline.isset("no-simplify"))
161  options.set_option("simplify", false);
162 
163  if(cmdline.isset("stop-on-fail") ||
164  cmdline.isset("dimacs") ||
165  cmdline.isset("outfile"))
166  options.set_option("stop-on-fail", true);
167 
168  if(
169  cmdline.isset("trace") || cmdline.isset("compact-trace") ||
170  cmdline.isset("stack-trace") || cmdline.isset("stop-on-fail") ||
172  !cmdline.isset("cover")))
173  {
174  options.set_option("trace", true);
175  }
176 
177  if(cmdline.isset("validate-trace"))
178  {
179  options.set_option("validate-trace", true);
180  options.set_option("trace", true);
181  }
182 
183  if(cmdline.isset("localize-faults"))
184  options.set_option("localize-faults", true);
185 
186  if(cmdline.isset("symex-complexity-limit"))
187  {
188  options.set_option(
189  "symex-complexity-limit", cmdline.get_value("symex-complexity-limit"));
190  log.warning() << "**** WARNING: Complexity-limited analysis may yield "
191  "unsound verification results"
192  << messaget::eom;
193  }
194 
195  if(cmdline.isset("symex-complexity-failed-child-loops-limit"))
196  {
197  options.set_option(
198  "symex-complexity-failed-child-loops-limit",
199  cmdline.get_value("symex-complexity-failed-child-loops-limit"));
200  if(!cmdline.isset("symex-complexity-limit"))
201  {
202  log.warning() << "**** WARNING: Complexity-limited analysis may yield "
203  "unsound verification results"
204  << messaget::eom;
205  }
206  }
207 
208  // generate unwinding assertions
209  options.set_option(
210  "unwinding-assertions",
211  cmdline.isset("unwinding-assertions") ||
212  !cmdline.isset("no-unwinding-assertions"));
213 
214  if(cmdline.isset("unwind"))
215  {
216  options.set_option("unwind", cmdline.get_value("unwind"));
217  if(!options.get_bool_option("unwinding-assertions"))
218  {
219  log.warning() << "**** WARNING: Use --unwinding-assertions to obtain "
220  "sound verification results"
221  << messaget::eom;
222  }
223  }
224 
225  if(cmdline.isset("depth"))
226  {
227  options.set_option("depth", cmdline.get_value("depth"));
228  log.warning()
229  << "**** WARNING: Depth-bounded analysis may yield unsound verification "
230  "results"
231  << messaget::eom;
232  }
233 
234  if(cmdline.isset("unwindset"))
235  {
236  options.set_option(
237  "unwindset", cmdline.get_comma_separated_values("unwindset"));
238  if(!options.get_bool_option("unwinding-assertions"))
239  {
240  log.warning() << "**** WARNING: Use --unwinding-assertions to obtain "
241  "sound verification results"
242  << messaget::eom;
243  }
244  }
245 
246  // constant propagation
247  if(cmdline.isset("no-propagation"))
248  options.set_option("propagation", false);
249 
250  // transform self loops to assumptions
251  options.set_option(
252  "self-loops-to-assumptions",
253  !cmdline.isset("no-self-loops-to-assumptions"));
254 
255  // unwind loops in java enum static initialization
256  if(cmdline.isset("java-unwind-enum-static"))
257  options.set_option("java-unwind-enum-static", true);
258 
259  // check assertions
260  if(cmdline.isset("no-assertions"))
261  options.set_option("assertions", false);
262 
263  // use assumptions
264  if(cmdline.isset("no-assumptions"))
265  options.set_option("assumptions", false);
266 
267  // generate unwinding assumptions otherwise
268  if(cmdline.isset("partial-loops"))
269  {
270  options.set_option("partial-loops", true);
271  log.warning()
272  << "**** WARNING: --partial-loops may yield unsound verification results"
273  << messaget::eom;
274  }
275 
276  // remove unused equations
277  options.set_option(
278  "slice-formula",
279  cmdline.isset("slice-formula"));
280 
281  if(cmdline.isset("arrays-uf-always"))
282  options.set_option("arrays-uf", "always");
283  else if(cmdline.isset("arrays-uf-never"))
284  options.set_option("arrays-uf", "never");
285 
286  if(cmdline.isset("no-refine-strings"))
287  options.set_option("refine-strings", false);
288 
289  if(cmdline.isset("string-printable") && cmdline.isset("no-refine-strings"))
290  {
292  "cannot use --string-printable with --no-refine-strings",
293  "--string-printable");
294  }
295 
296  if(cmdline.isset("string-input-value") && cmdline.isset("no-refine-strings"))
297  {
299  "cannot use --string-input-value with --no-refine-strings",
300  "--string-input-value");
301  }
302 
303  if(
304  cmdline.isset("no-refine-strings") &&
305  cmdline.isset("max-nondet-string-length"))
306  {
308  "cannot use --max-nondet-string-length with --no-refine-strings",
309  "--max-nondet-string-length");
310  }
311 
312  if(cmdline.isset("graphml-witness"))
313  {
314  options.set_option("graphml-witness", cmdline.get_value("graphml-witness"));
315  options.set_option("stop-on-fail", true);
316  options.set_option("trace", true);
317  }
318 
319  if(cmdline.isset("symex-coverage-report"))
320  options.set_option(
321  "symex-coverage-report",
322  cmdline.get_value("symex-coverage-report"));
323 
324  if(cmdline.isset("validate-ssa-equation"))
325  {
326  options.set_option("validate-ssa-equation", true);
327  }
328 
329  if(cmdline.isset("validate-goto-model"))
330  {
331  options.set_option("validate-goto-model", true);
332  }
333 
334  options.set_option(
335  "symex-cache-dereferences", cmdline.isset("symex-cache-dereferences"));
336 
338 
339  if(cmdline.isset("symex-driven-lazy-loading"))
340  {
341  options.set_option("symex-driven-lazy-loading", true);
342  for(const char *opt :
343  { "nondet-static",
344  "full-slice",
345  "reachability-slice",
346  "reachability-slice-fb" })
347  {
348  if(cmdline.isset(opt))
349  {
350  throw std::string("Option ") + opt +
351  " can't be used with --symex-driven-lazy-loading";
352  }
353  }
354  }
355 
356  // The 'allow-pointer-unsoundness' option prevents symex from throwing an
357  // exception when it encounters pointers that are shared across threads.
358  // This is unsound but given that pointers are ubiquitous in java this check
359  // must be disabled in order to support the analysis of multithreaded java
360  // code.
361  if(cmdline.isset("java-threading"))
362  options.set_option("allow-pointer-unsoundness", true);
363 
364  if(cmdline.isset("show-goto-symex-steps"))
365  options.set_option("show-goto-symex-steps", true);
366 
367  if(cmdline.isset("smt1"))
368  {
369  log.error() << "--smt1 is no longer supported" << messaget::eom;
371  }
372 
373  parse_solver_options(cmdline, options);
374 }
375 
378 {
379  if(cmdline.isset("version"))
380  {
381  std::cout << CBMC_VERSION << '\n';
382  return CPROVER_EXIT_SUCCESS;
383  }
384 
387 
388  //
389  // command line options
390  //
391 
392  optionst options;
393  get_command_line_options(options);
394 
396 
397  // output the options
398  switch(ui_message_handler.get_ui())
399  {
402  log.debug(), [&options](messaget::mstreamt &debug_stream) {
403  debug_stream << "\nOptions: \n";
404  options.output(debug_stream);
405  debug_stream << messaget::eom;
406  });
407  break;
409  {
410  json_objectt json_options{{"options", options.to_json()}};
411  log.debug() << json_options;
412  break;
413  }
415  log.debug() << options.to_xml();
416  break;
417  }
418 
421 
422  if(!((cmdline.isset("jar") && cmdline.args.empty()) ||
423  (cmdline.isset("gb") && cmdline.args.empty()) ||
424  (!cmdline.isset("jar") && !cmdline.isset("gb") &&
425  (cmdline.args.size() == 1))))
426  {
427  log.error() << "Please give exactly one class name, "
428  << "and/or use -jar jarfile or --gb goto-binary"
429  << messaget::eom;
431  }
432 
433  if((cmdline.args.size() == 1) && !cmdline.isset("show-parse-tree"))
434  {
435  std::string main_class = cmdline.args[0];
436  // `java` accepts slashes and dots as package separators
437  std::replace(main_class.begin(), main_class.end(), '/', '.');
438  config.java.main_class = main_class;
439  cmdline.args.pop_back();
440  }
441 
442  if(cmdline.isset("jar"))
443  {
444  cmdline.args.push_back(cmdline.get_value("jar"));
445  }
446 
447  if(cmdline.isset("gb"))
448  {
449  cmdline.args.push_back(cmdline.get_value("gb"));
450  }
451 
452  // Shows the parse tree of the main class
453  if(cmdline.isset("show-parse-tree"))
454  {
455  std::unique_ptr<languaget> language = get_language_from_mode(ID_java);
456  CHECK_RETURN(language != nullptr);
457  language->set_language_options(options, ui_message_handler);
458 
459  log.status() << "Parsing ..." << messaget::eom;
460 
461  std::istringstream unused;
462  if(language.get()->parse(unused, "", ui_message_handler))
463  {
464  log.error() << "PARSING ERROR" << messaget::eom;
466  }
467 
468  language->show_parse(std::cout, ui_message_handler);
469  return CPROVER_EXIT_SUCCESS;
470  }
471 
472  object_factory_params.set(options);
473 
475  options.get_bool_option("java-assume-inputs-non-null");
476 
477  std::unique_ptr<abstract_goto_modelt> goto_model_ptr;
478  int get_goto_program_ret = get_goto_program(goto_model_ptr, options);
479  if(get_goto_program_ret != -1)
480  return get_goto_program_ret;
481 
482  if(
483  options.get_bool_option("program-only") ||
484  options.get_bool_option("show-vcc") ||
485  (options.get_bool_option("symex-driven-lazy-loading") &&
486  (cmdline.isset("show-symbol-table") || cmdline.isset("list-symbols") ||
487  cmdline.isset("show-goto-functions") ||
488  cmdline.isset("list-goto-functions") ||
489  cmdline.isset("show-properties") || cmdline.isset("show-loops"))))
490  {
491  if(options.get_bool_option("paths"))
492  {
494  options, ui_message_handler, *goto_model_ptr);
495  (void)verifier();
496  }
497  else
498  {
500  options, ui_message_handler, *goto_model_ptr);
501  (void)verifier();
502  }
503 
504  if(options.get_bool_option("symex-driven-lazy-loading"))
505  {
506  // We can only output these after goto-symex has run.
507  (void)show_loaded_symbols(*goto_model_ptr);
508  (void)show_loaded_functions(*goto_model_ptr);
509  }
510 
511  return CPROVER_EXIT_SUCCESS;
512  }
513 
514  if(
515  options.get_bool_option("dimacs") || !options.get_option("outfile").empty())
516  {
517  if(options.get_bool_option("paths"))
518  {
520  options, ui_message_handler, *goto_model_ptr);
521  (void)verifier();
522  }
523  else
524  {
526  options, ui_message_handler, *goto_model_ptr);
527  (void)verifier();
528  }
529 
530  return CPROVER_EXIT_SUCCESS;
531  }
532 
533  std::unique_ptr<goto_verifiert> verifier = nullptr;
534 
535  if(
536  options.get_bool_option("stop-on-fail") && options.get_bool_option("paths"))
537  {
538  verifier =
539  std::make_unique<stop_on_fail_verifiert<java_single_path_symex_checkert>>(
540  options, ui_message_handler, *goto_model_ptr);
541  }
542  else if(
543  options.get_bool_option("stop-on-fail") &&
544  !options.get_bool_option("paths"))
545  {
546  if(options.get_bool_option("localize-faults"))
547  {
548  verifier =
551  options, ui_message_handler, *goto_model_ptr);
552  }
553  else
554  {
555  verifier = std::make_unique<
557  options, ui_message_handler, *goto_model_ptr);
558  }
559  }
560  else if(
561  !options.get_bool_option("stop-on-fail") &&
562  options.get_bool_option("paths"))
563  {
564  verifier = std::make_unique<all_properties_verifier_with_trace_storaget<
566  options, ui_message_handler, *goto_model_ptr);
567  }
568  else if(
569  !options.get_bool_option("stop-on-fail") &&
570  !options.get_bool_option("paths"))
571  {
572  if(options.get_bool_option("localize-faults"))
573  {
574  verifier =
577  options, ui_message_handler, *goto_model_ptr);
578  }
579  else
580  {
581  verifier = std::make_unique<all_properties_verifier_with_trace_storaget<
583  options, ui_message_handler, *goto_model_ptr);
584  }
585  }
586  else
587  {
588  UNREACHABLE;
589  }
590 
591  const resultt result = (*verifier)();
592  verifier->report();
593  return result_to_exit_code(result);
594 }
595 
597  std::unique_ptr<abstract_goto_modelt> &goto_model_ptr,
598  const optionst &options)
599 {
600  if(options.is_set("context-include") || options.is_set("context-exclude"))
601  method_context = get_context(options);
602  lazy_goto_modelt lazy_goto_model =
604  lazy_goto_model.initialize(cmdline.args, options);
605 
607  std::make_unique<class_hierarchyt>(lazy_goto_model.symbol_table);
608 
609  // Show the class hierarchy
610  if(cmdline.isset("show-class-hierarchy"))
611  {
613  return CPROVER_EXIT_SUCCESS;
614  }
615 
616  // Add failed symbols for any symbol created prior to loading any
617  // particular function:
618  add_failed_symbols(lazy_goto_model.symbol_table);
619 
620  if(!options.get_bool_option("symex-driven-lazy-loading"))
621  {
622  log.status() << "Generating GOTO Program" << messaget::eom;
623  lazy_goto_model.load_all_functions();
624 
625  // show symbol table or list symbols
626  if(show_loaded_symbols(lazy_goto_model))
627  return CPROVER_EXIT_SUCCESS;
628 
629  // Move the model out of the local lazy_goto_model
630  // and into the caller's goto_model
631  auto final_goto_model_ptr =
633  std::move(lazy_goto_model));
634  if(final_goto_model_ptr == nullptr)
636 
637  goto_modelt &goto_model = *final_goto_model_ptr;
638  goto_model_ptr =
639  std::unique_ptr<abstract_goto_modelt>(final_goto_model_ptr.get());
640  final_goto_model_ptr.release();
641 
642  if(cmdline.isset("validate-goto-model"))
643  {
644  goto_model.validate();
645  }
646 
647  if(show_loaded_functions(goto_model))
648  return CPROVER_EXIT_SUCCESS;
649 
650  if(cmdline.isset("property"))
651  ::set_properties(goto_model, cmdline.get_values("property"));
652  }
653  else
654  {
655  // The precise wording of this error matches goto-symex's complaint when no
656  // __CPROVER_start exists (if we just go ahead and run it anyway it will
657  // trip an invariant when it tries to load it)
659  {
660  log.error() << "the program has no entry point" << messaget::eom;
662  }
663 
664  if(cmdline.isset("validate-goto-model"))
665  {
666  lazy_goto_model.validate();
667  }
668 
669  goto_model_ptr =
670  std::make_unique<lazy_goto_modelt>(std::move(lazy_goto_model));
671  }
672 
674 
675  return -1; // no error, continue
676 }
677 
679  goto_model_functiont &function,
680  const abstract_goto_modelt &model,
681  const optionst &options)
682 {
683  journalling_symbol_tablet &symbol_table = function.get_symbol_table();
684  namespacet ns(symbol_table);
685  goto_functionst::goto_functiont &goto_function = function.get_goto_function();
686 
687  bool using_symex_driven_loading =
688  options.get_bool_option("symex-driven-lazy-loading");
689 
690  // Removal of RTTI inspection:
692  function.get_function_id(),
693  goto_function,
694  symbol_table,
697  // Java virtual functions -> explicit dispatch tables:
699 
700  auto function_is_stub = [&symbol_table, &model](const irep_idt &id) {
701  return symbol_table.lookup_ref(id).value.is_nil() &&
702  !model.can_produce_function(id);
703  };
704 
705  remove_returns(function, function_is_stub);
706 
707  replace_java_nondet(function);
708 
709  // Similar removal of java nondet statements:
711 
712  if(using_symex_driven_loading)
713  {
714  // remove exceptions
715  // If using symex-driven function loading we need to do this now so that
716  // symex doesn't have to cope with exception-handling constructs; however
717  // the results are slightly worse than running it in whole-program mode
718  // (e.g. dead catch sites will be retained)
720  function.get_function_id(),
721  goto_function.body,
722  symbol_table,
723  *class_hierarchy.get(),
725  }
726 
727  transform_assertions_assumptions(options, function.get_goto_function().body);
728 
729  // Replace Java new side effects
731  function.get_function_id(),
732  goto_function,
733  symbol_table,
735 
736  // checks don't know about adjusted float expressions
737  adjust_float_expressions(goto_function, ns);
738 
739  // add failed symbols for anything created relating to this particular
740  // function (note this means subsequent passes mustn't create more!):
742  symbol_table.get_inserted();
743  for(const irep_idt &new_symbol_name : new_symbols)
744  {
746  symbol_table.lookup_ref(new_symbol_name), symbol_table);
747  }
748 
749  // If using symex-driven function loading we must label the assertions
750  // now so symex sees its targets; otherwise we leave this until
751  // process_goto_functions, as we haven't run remove_exceptions yet, and that
752  // pass alters the CFG.
753  if(using_symex_driven_loading)
754  {
755  // label the assertions
756  label_properties(function.get_function_id(), goto_function.body);
757 
758  goto_function.body.update();
759  function.compute_location_numbers();
760  goto_function.body.compute_loop_numbers();
761  }
762 }
763 
765  const abstract_goto_modelt &goto_model)
766 {
767  if(cmdline.isset("show-symbol-table"))
768  {
770  return true;
771  }
772  else if(cmdline.isset("list-symbols"))
773  {
775  return true;
776  }
777 
778  return false;
779 }
780 
782  const abstract_goto_modelt &goto_model)
783 {
784  if(cmdline.isset("show-loops"))
785  {
787  return true;
788  }
789 
790  if(
791  cmdline.isset("show-goto-functions") ||
792  cmdline.isset("list-goto-functions"))
793  {
794  namespacet ns(goto_model.get_symbol_table());
796  ns,
798  goto_model.get_goto_functions(),
799  cmdline.isset("list-goto-functions"));
800  return true;
801  }
802 
803  if(cmdline.isset("show-properties"))
804  {
805  namespacet ns(goto_model.get_symbol_table());
807  return true;
808  }
809 
810  return false;
811 }
812 
814  goto_modelt &goto_model,
815  const optionst &options)
816 {
817  log.status() << "Running GOTO functions transformation passes"
818  << messaget::eom;
819 
820  bool using_symex_driven_loading =
821  options.get_bool_option("symex-driven-lazy-loading");
822 
823  // When using symex-driven lazy loading, *all* relevant processing is done
824  // during process_goto_function, so we have nothing to do here.
825  if(using_symex_driven_loading)
826  return false;
827 
828  // remove catch and throw
830 
831  // instrument library preconditions
832  instrument_preconditions(goto_model);
833 
834  // ignore default/user-specified initialization
835  // of variables with static lifetime
836  if(cmdline.isset("nondet-static"))
837  {
838  log.status() << "Adding nondeterministic initialization "
839  "of static/global variables"
840  << messaget::eom;
841  nondet_static(goto_model);
842  }
843 
844  // recalculate numbers, etc.
845  goto_model.goto_functions.update();
846 
847  if(cmdline.isset("drop-unused-functions"))
848  {
849  // Entry point will have been set before and function pointers removed
850  log.status() << "Removing unused functions" << messaget::eom;
852  }
853 
854  // remove skips such that trivial GOTOs are deleted
855  remove_skip(goto_model);
856 
857  // label the assertions
858  // This must be done after adding assertions and
859  // before using the argument of the "property" option.
860  // Do not re-label after using the property slicer because
861  // this would cause the property identifiers to change.
862  label_properties(goto_model);
863 
864  // reachability slice?
865  if(cmdline.isset("reachability-slice-fb"))
866  {
867  if(cmdline.isset("reachability-slice"))
868  {
869  log.error() << "--reachability-slice and --reachability-slice-fb "
870  << "must not be given together" << messaget::eom;
871  return true;
872  }
873 
874  log.status() << "Performing a forwards-backwards reachability slice"
875  << messaget::eom;
876  if(cmdline.isset("property"))
877  {
879  goto_model, cmdline.get_values("property"), true, ui_message_handler);
880  }
881  else
882  reachability_slicer(goto_model, true, ui_message_handler);
883  }
884 
885  if(cmdline.isset("reachability-slice"))
886  {
887  log.status() << "Performing a reachability slice" << messaget::eom;
888  if(cmdline.isset("property"))
889  {
891  goto_model, cmdline.get_values("property"), ui_message_handler);
892  }
893  else
895  }
896 
897  // full slice?
898  if(cmdline.isset("full-slice"))
899  {
900  log.warning() << "**** WARNING: Experimental option --full-slice, "
901  << "analysis results may be unsound. See "
902  << "https://github.com/diffblue/cbmc/issues/260"
903  << messaget::eom;
904  log.status() << "Performing a full slice" << messaget::eom;
905  if(cmdline.isset("property"))
907  goto_model, cmdline.get_values("property"), ui_message_handler);
908  else
909  full_slicer(goto_model, ui_message_handler);
910  }
911 
912  // remove any skips introduced
913  remove_skip(goto_model);
914 
915  return false;
916 }
917 
919 {
920  static const irep_idt initialize_id = INITIALIZE_FUNCTION;
921 
922  return name != goto_functionst::entry_point() && name != initialize_id;
923 }
924 
926  const irep_idt &function_name,
927  symbol_table_baset &symbol_table,
928  goto_functiont &function,
929  bool body_available)
930 {
931  // Provide a simple stub implementation for any function we don't have a
932  // bytecode implementation for:
933 
934  if(
935  body_available &&
936  (!method_context || (*method_context)(id2string(function_name))))
937  return false;
938 
939  if(!can_generate_function_body(function_name))
940  return false;
941 
942  if(symbol_table.lookup_ref(function_name).mode == ID_java)
943  {
945  function_name,
946  symbol_table,
950 
951  goto_convert_functionst converter(symbol_table, ui_message_handler);
952  converter.convert_function(function_name, function);
953 
954  return true;
955  }
956  else
957  {
958  return false;
959  }
960 }
961 
964 {
965  // clang-format off
966  std::cout << '\n' << banner_string("JBMC", CBMC_VERSION) << '\n'
967  << align_center_with_border("Copyright (C) 2001-2018") << '\n'
968  << align_center_with_border("Daniel Kroening, Edmund Clarke") << '\n' // NOLINT(*)
969  << align_center_with_border("Carnegie Mellon University, Computer Science Department") << '\n' // NOLINT(*)
970  << align_center_with_border("kroening@kroening.com") << '\n';
971 
972  std::cout << help_formatter(
973  "\n"
974  "Usage: \tPurpose:\n"
975  "\n"
976  " {bjbmc} [{y-?}] [{y-h}] [{y--help}] \t show this help\n"
977  " {bjbmc}\n"
979  " {bjbmc}\n"
981  " {bjbmc}\n"
983  " {bjbmc}\n"
985  "\n"
988  "\n"
989  "Analysis options:\n"
991  " {y--symex-coverage-report} {uf} \t generate a Cobertura XML coverage"
992  " report in {uf}\n"
993  " {y--property} {uid} \t only check one specific property\n"
994  " {y--trace} \t give a counterexample trace for failed properties\n"
995  " {y--stop-on-fail} \t stop analysis once a failed property is detected"
996  " (implies {y--trace})\n"
997  " {y--localize-faults} \t localize faults (experimental)\n"
999  "\n"
1000  "Platform options:\n"
1002  "\n"
1003  "Program representations:\n"
1004  " {y--show-parse-tree} \t show parse tree\n"
1005  " {y--show-symbol-table} \t show loaded symbol table\n"
1006  " {y--list-symbols} \t list symbols with type information\n"
1008  " {y--drop-unused-functions} \t drop functions trivially unreachable"
1009  " from main function\n"
1011  "\n"
1012  "Program instrumentation options:\n"
1013  " {y--no-assertions} \t ignore user assertions\n"
1014  " {y--no-assumptions} \t ignore user assumptions\n"
1015  " {y--mm} {uMM} \t memory consistency model for concurrent programs\n"
1017  " {y--full-slice} \t run full slicer (experimental)\n"
1018  "\n"
1019  "Java Bytecode frontend options:\n"
1021  // This one is handled by jbmc_parse_options not by the Java frontend,
1022  // hence its presence here:
1023  " {y--java-threading} \t enable java multi-threading support"
1024  " (experimental)\n"
1025  " {y--java-unwind-enum-static} \t unwind loops in static initialization of"
1026  " enums\n"
1027  " {y--symex-driven-lazy-loading} \t only load functions when first entered"
1028  " by symbolic execution. Note that {y--show-symbol-table},"
1029  " {y--show-goto-functions}, {y--show-properties} output will be restricted"
1030  " to loaded methods in this case, and only output after the symex phase.\n"
1031  "\n"
1032  "Semantic transformations:\n"
1033  " {y--nondet-static} \t add nondeterministic initialization of variables"
1034  " with static lifetime\n"
1035  "\n"
1036  "BMC options:\n"
1037  HELP_BMC
1038  "\n"
1039  "Backend options:\n"
1041  HELP_SOLVER
1043  " {y--arrays-uf-never} \t never turn arrays into uninterpreted functions\n"
1044  " {y--arrays-uf-always} \t always turn arrays into uninterpreted"
1045  " functions\n"
1046  "\n"
1047  "Other options:\n"
1048  " {y--version} \t show version and exit\n"
1053  HELP_FLUSH
1054  " {y--verbosity} {u#} \t verbosity level\n"
1056  "\n");
1057  // clang-format on
1058 }
void add_failed_symbol_if_needed(const symbolt &symbol, symbol_table_baset &symbol_table)
Create a failed-dereference symbol for the given base symbol if it is pointer-typed,...
void add_failed_symbols(symbol_table_baset &symbol_table)
Create a failed-dereference symbol for all symbols in the given table that need one (i....
Pointer Dereferencing.
void adjust_float_expressions(exprt &expr, const exprt &rounding_mode)
Replaces arithmetic operations and typecasts involving floating point numbers with their equivalent f...
Symbolic Execution.
Goto Verifier for Verifying all Properties.
Goto verifier for verifying all properties that stores traces and localizes faults.
Goto verifier for verifying all properties that stores traces.
std::unique_ptr< languaget > new_ansi_c_language()
configt config
Definition: config.cpp:25
#define HELP_BMC
Definition: bmc_util.h:197
unsigned char opt
Definition: cegis.c:20
void show_class_hierarchy(const class_hierarchyt &hierarchy, ui_message_handlert &message_handler, bool children_only)
Output the class hierarchy.
#define HELP_SHOW_CLASS_HIERARCHY
Abstract interface to eager or lazy GOTO models.
virtual bool can_produce_function(const irep_idt &id) const =0
Determines if this model can produce a body for the given function.
virtual const symbol_tablet & get_symbol_table() const =0
Accessor to get the symbol table.
virtual const goto_functionst & get_goto_functions() const =0
Accessor to get a raw goto_functionst.
Requires an incremental goto checker that is a goto_trace_providert and fault_localization_providert.
std::string get_value(char option) const
Definition: cmdline.cpp:48
virtual bool isset(char option) const
Definition: cmdline.cpp:30
std::list< std::string > get_comma_separated_values(const char *option) const
Collect all occurrences of option option and split their values on each comma, merging them into a si...
Definition: cmdline.cpp:121
argst args
Definition: cmdline.h:151
const std::list< std::string > & get_values(const std::string &option) const
Definition: cmdline.cpp:109
bool set(const cmdlinet &cmdline)
Definition: config.cpp:863
std::string object_bits_info()
Definition: config.cpp:1431
struct configt::javat java
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
void convert_function(const irep_idt &identifier, goto_functionst::goto_functiont &result)
::goto_functiont goto_functiont
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:24
Interface providing access to a single function in a GOTO model, plus its associated symbol table.
Definition: goto_model.h:190
void validate(const validation_modet vm=validation_modet::INVARIANT, const goto_model_validation_optionst &goto_model_validation_options=goto_model_validation_optionst{}) const override
Check that the goto model is well-formed.
Definition: goto_model.h:105
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:34
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
bool is_nil() const
Definition: irep.h:368
bool show_loaded_functions(const abstract_goto_modelt &goto_model)
void get_command_line_options(optionst &)
bool can_generate_function_body(const irep_idt &name)
std::unique_ptr< class_hierarchyt > class_hierarchy
bool show_loaded_symbols(const abstract_goto_modelt &goto_model)
virtual int doit() override
invoke main modules
std::optional< prefix_filtert > method_context
See java_bytecode_languaget::method_context.
virtual void help() override
display command line help
void process_goto_function(goto_model_functiont &function, const abstract_goto_modelt &, const optionst &)
java_object_factory_parameterst object_factory_params
bool process_goto_functions(goto_modelt &goto_model, const optionst &options)
int get_goto_program(std::unique_ptr< abstract_goto_modelt > &goto_model, const optionst &)
jbmc_parse_optionst(int argc, const char **argv)
bool generate_function_body(const irep_idt &function_name, symbol_table_baset &symbol_table, goto_functiont &function, bool body_available)
static void set_default_options(optionst &)
Set the options that have default values.
A symbol table wrapper that records which entries have been updated/removedA caller can pass a journa...
virtual const symbol_tablet & get_symbol_table() const override
std::unordered_set< irep_idt > changesett
const changesett & get_inserted() const
A GOTO model that produces function bodies on demand.
void load_all_functions() const
Eagerly loads all functions from the symbol table.
void validate(const validation_modet vm=validation_modet::INVARIANT, const goto_model_validation_optionst &goto_model_validation_options=goto_model_validation_optionst{}) const override
Check that the goto model is well-formed.
static lazy_goto_modelt from_handler_object(THandler &handler, const optionst &options, message_handlert &message_handler)
Create a lazy_goto_modelt from a object that defines function/module pass handlers.
void initialize(const std::vector< std::string > &files, const optionst &options)
Performs initial symbol table and language_filest initialization from a given commandline and parsed ...
symbol_tablet & symbol_table
Reference to symbol_table in the internal goto_model.
static std::unique_ptr< goto_modelt > process_whole_model_and_freeze(lazy_goto_modelt &&model)
The model returned here has access to the functions we've already loaded but is frozen in the sense t...
static unsigned eval_verbosity(const std::string &user_input, const message_levelt default_verbosity, message_handlert &dest)
Parse a (user-)provided string as a verbosity level and set it as the verbosity of dest.
Definition: message.cpp:105
mstreamt & error() const
Definition: message.h:391
mstreamt & warning() const
Definition: message.h:396
mstreamt & status() const
Definition: message.h:406
void conditional_output(mstreamt &mstream, const std::function< void(mstreamt &)> &output_generator) const
Generate output to message_stream using output_generator if the configured verbosity is at least as h...
Definition: message.cpp:139
mstreamt & debug() const
Definition: message.h:421
@ M_STATISTICS
Definition: message.h:170
static eomt eom
Definition: message.h:289
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
bool is_set(const std::string &option) const
N.B. opts.is_set("foo") does not imply opts.get_bool_option("foo")
Definition: options.cpp:62
json_objectt to_json() const
Returns the options as JSON key value pairs.
Definition: options.cpp:93
bool get_bool_option(const std::string &option) const
Definition: options.cpp:44
void set_option(const std::string &option, const bool value)
Definition: options.cpp:28
const std::string get_option(const std::string &option) const
Definition: options.cpp:67
xmlt to_xml() const
Returns the options in XML format.
Definition: options.cpp:104
virtual void usage_error()
void log_version_and_architecture(const std::string &front_end)
Write version and system architecture to log.status().
ui_message_handlert ui_message_handler
Definition: parse_options.h:45
Stops when the first failing property is found and localizes the fault Requires an incremental goto c...
Stops when the first failing property is found.
The symbol table base class interface.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
exprt value
Initial value of symbol.
Definition: symbol.h:34
irep_idt mode
Language mode.
Definition: symbol.h:49
virtual uit get_ui() const
Definition: ui_message.h:33
#define HELP_CONFIG_PLATFORM
Definition: config.h:96
#define HELP_CONFIG_BACKEND
Definition: config.h:126
void convert_nondet(const irep_idt &function_identifier, goto_programt &goto_program, symbol_table_baset &symbol_table, message_handlert &message_handler, const java_object_factory_parameterst &user_object_factory_parameters, const irep_idt &mode)
For each instruction in the goto program, checks if it is an assignment from nondet and replaces it w...
Convert side_effect_expr_nondett expressions using java_object_factory.
static void show_goto_functions(const goto_modelt &goto_model)
Document and give macros for the exit codes of CPROVER binaries.
#define CPROVER_EXIT_INTERNAL_ERROR
An error has been encountered during processing the requested analysis.
Definition: exit_codes.h:45
#define CPROVER_EXIT_INCORRECT_TASK
The command line is correctly structured but cannot be carried out due to missing files,...
Definition: exit_codes.h:49
#define CPROVER_EXIT_PARSE_ERROR
An error during parsing of the input program.
Definition: exit_codes.h:37
#define CPROVER_EXIT_USAGE_ERROR
A usage error is returned when the command line is invalid or conflicting.
Definition: exit_codes.h:33
#define CPROVER_EXIT_SUCCESS
Success indicates the required analysis has been performed without error.
Definition: exit_codes.h:16
void property_slicer(goto_functionst &goto_functions, const namespacet &ns, const std::list< std::string > &properties, message_handlert &message_handler)
void full_slicer(goto_functionst &goto_functions, const namespacet &ns, const slicing_criteriont &criterion, message_handlert &message_handler)
static void transform_assertions_assumptions(goto_programt &goto_program, bool enable_assertions, bool enable_built_in_assertions, bool enable_assumptions)
Definition: goto_check.cpp:19
Checks for Errors in C and Java Programs.
Goto Programs with Functions.
#define PARSE_OPTIONS_GOTO_TRACE(cmdline, options)
Definition: goto_trace.h:287
#define HELP_GOTO_TRACE
Definition: goto_trace.h:279
Help Formatter.
static help_formattert help_formatter(const std::string &s)
void instrument_preconditions(const goto_modelt &goto_model, goto_programt &goto_program)
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
void parse_java_language_options(const cmdlinet &cmd, optionst &options)
Parse options that are java bytecode specific.
prefix_filtert get_context(const optionst &options)
std::unique_ptr< languaget > new_java_bytecode_language()
#define HELP_JAVA_METHOD_NAME
#define JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP
#define HELP_JAVA_GOTO_BINARY
#define HELP_JAVA_CLASSPATH
#define HELP_JAVA_JAR
#define HELP_JAVA_CLASS_NAME
Goto Checker using Bounded Model Checking for Java.
Goto Checker using Bounded Model Checking for Java.
void parse_java_object_factory_options(const cmdlinet &cmdline, optionst &options)
Parse the java object factory parameters from a given command line.
Goto Checker using Single Path Symbolic Execution for Java.
Goto Checker using Single Path Symbolic Execution for Java.
#define HELP_JAVA_TRACE_VALIDATION
JBMC Command Line Option Processing.
#define JBMC_OPTIONS
void json_interface(cmdlinet &cmdline, message_handlert &message_handler)
Parses the JSON-formatted command line from stdin.
#define HELP_JSON_INTERFACE
Abstract interface to support a programming language.
#define HELP_FUNCTIONS
Definition: language.h:34
Author: Diffblue Ltd.
void show_loop_ids(ui_message_handlert::uit ui, const goto_modelt &goto_model)
Definition: loop_ids.cpp:21
Loop IDs.
void register_language(language_factoryt factory)
Register a language Note: registering a language is required for using the functions in language_util...
Definition: mode.cpp:39
std::unique_ptr< languaget > get_language_from_mode(const irep_idt &mode)
Get the language corresponding to the given mode.
Definition: mode.cpp:51
static void nondet_static(const namespacet &ns, goto_modelt &goto_model, const irep_idt &fct_name)
Nondeterministically initializes global scope variables in a goto-function.
Nondeterministically initializes global scope variables, except for constants (such as string literal...
std::string align_center_with_border(const std::string &text)
Utility for displaying help centered messages borderered by "* *".
std::string banner_string(const std::string &front_end, const std::string &version)
void parse_path_strategy_options(const cmdlinet &cmdline, optionst &options, message_handlert &message_handler)
add paths and exploration-strategy option, suitable to be invoked from front-ends.
std::string show_path_strategies()
suitable for displaying as a front-end help message
Storage of symbolic execution paths to resume.
int result_to_exit_code(resultt result)
Definition: properties.cpp:147
resultt
The result of goto verifying.
Definition: properties.h:45
void reachability_slicer(goto_modelt &goto_model, const bool include_forward_reachability, message_handlert &message_handler)
Perform reachability slicing on goto_model, with respect to the criterion given by all properties.
#define HELP_REACHABILITY_SLICER
void remove_exceptions(symbol_table_baset &symbol_table, goto_functionst &goto_functions, const class_hierarchyt &class_hierarchy, message_handlert &message_handler)
removes throws/CATCH-POP/CATCH-PUSH
Remove function exceptional returns.
void remove_instanceof(const irep_idt &function_identifier, goto_programt::targett target, goto_programt &goto_program, symbol_table_baset &symbol_table, const class_hierarchyt &class_hierarchy, message_handlert &message_handler)
Replace an instanceof in the expression or guard of the passed instruction of the given function body...
Remove Instance-of Operators.
void remove_java_new(const irep_idt &function_identifier, goto_programt::targett target, goto_programt &goto_program, symbol_table_baset &symbol_table, message_handlert &message_handler)
Replace every java_new or java_new_array by a malloc side-effect and zero initialization.
Remove Java New Operators.
void remove_returns(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
removes returns
Replace function returns by assignments to global variables.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Definition: remove_skip.cpp:87
Program Transformation.
void remove_unused_functions(goto_modelt &goto_model, message_handlert &message_handler)
Unused function removal.
void remove_virtual_functions(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
Remove virtual function calls from all functions in the specified list and replace them with their mo...
Functions for replacing virtual function call with a static function calls in functions,...
static void replace_java_nondet(goto_programt &goto_program)
Checks each instruction in the goto program to see whether it is a method returning nondet.
Replace Java Nondet expressions.
void set_properties(goto_programt &goto_program, std::unordered_set< irep_idt > &property_set)
void label_properties(goto_modelt &goto_model)
Set the properties to check.
Show the goto functions.
#define HELP_SHOW_GOTO_FUNCTIONS
void show_properties(const namespacet &ns, const irep_idt &identifier, message_handlert &message_handler, ui_message_handlert::uit ui, const goto_programt &goto_program)
Show the properties.
#define HELP_SHOW_PROPERTIES
void show_symbol_table(const symbol_table_baset &symbol_table, ui_message_handlert &ui)
void show_symbol_table_brief(const symbol_table_baset &symbol_table, ui_message_handlert &ui)
Show the symbol table.
void java_generate_simple_method_stub(const irep_idt &function_name, symbol_table_baset &symbol_table, bool assume_non_null, const java_object_factory_parameterst &object_factory_parameters, message_handlert &message_handler)
Java simple opaque stub generation.
void parse_solver_options(const cmdlinet &cmdline, optionst &options)
Parse solver-related command-line parameters in cmdline and set corresponding values in options.
#define HELP_SOLVER
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:495
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:525
#define INITIALIZE_FUNCTION
void exit(int status)
Definition: stdlib.c:102
Goto Verifier for stopping at the first failing property.
Goto Verifier for stopping at the first failing property and localizing the fault.
void replace(const union_find_replacet &replace_map, string_not_contains_constraintt &constraint)
#define HELP_STRING_REFINEMENT
irep_idt main_class
Definition: config.h:347
void set(const optionst &)
Assigns the parameters from given options.
#define HELP_TIMESTAMP
Definition: timestamper.h:14
#define HELP_FLUSH
Definition: ui_message.h:108
#define HELP_VALIDATE
const char * CBMC_VERSION
void xml_interface(cmdlinet &cmdline, message_handlert &message_handler)
Parse XML-formatted commandline options from stdin.
#define HELP_XML_INTERFACE
Definition: xml_interface.h:39