CBMC
cbmc_parse_options.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: CBMC Command Line Option Processing
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "cbmc_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/unicode.h>
19 #include <util/version.h>
20 
23 #include <goto-programs/loop_ids.h>
33 
34 #include <ansi-c/c_preprocess.h>
35 #include <ansi-c/cprover_library.h>
36 #include <ansi-c/gcc_version.h>
37 #include <assembler/remove_asm.h>
38 #include <cpp/cprover_library.h>
42 #include <goto-checker/bmc_util.h>
52 #include <goto-instrument/cover.h>
57 #include <langapi/language.h>
58 #include <langapi/mode.h>
60 
61 #include "c_test_input_generator.h"
62 
63 #include <cstdlib> // exit()
64 #include <fstream> // IWYU pragma: keep
65 #include <iostream>
66 #include <memory>
67 
68 cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv)
71  argc,
72  argv,
73  std::string("CBMC ") + CBMC_VERSION)
74 {
77 }
78 
80  int argc,
81  const char **argv,
82  const std::string &extra_options)
84  CBMC_OPTIONS + extra_options,
85  argc,
86  argv,
87  std::string("CBMC ") + CBMC_VERSION)
88 {
91 }
92 
94 {
95  // Default true
96  options.set_option("built-in-assertions", true);
97  options.set_option("propagation", true);
98  options.set_option("simple-slice", true);
99  options.set_option("simplify", true);
100  options.set_option("show-goto-symex-steps", false);
101  options.set_option("show-points-to-sets", false);
102  options.set_option("show-array-constraints", false);
103 
104  // Other default
105  options.set_option("arrays-uf", "auto");
106  options.set_option("depth", UINT32_MAX);
107 }
108 
110  optionst &options,
111  const bool enabled)
112 {
113  // Checks enabled by default in v6.0+.
114  options.set_option("bounds-check", enabled);
115  options.set_option("pointer-check", enabled);
116  options.set_option("pointer-primitive-check", enabled);
117  options.set_option("div-by-zero-check", enabled);
118  options.set_option("signed-overflow-check", enabled);
119  options.set_option("undefined-shift-check", enabled);
120 
121  // Unwinding assertions required in certain cases for sound verification
122  // results. See https://github.com/diffblue/cbmc/issues/6561 for elaboration.
123  // As the unwinding-assertions is processed earlier, we set it only if it has
124  // not been set yet.
125  if(!options.is_set("unwinding-assertions"))
126  {
127  options.set_option("unwinding-assertions", enabled);
128  }
129 
130  if(enabled)
131  {
134  configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_return_null;
135  }
136  else
137  {
138  config.ansi_c.malloc_may_fail = false;
140  configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_none;
141  }
142 }
143 
145 {
146  // Enable flags that in combination provide analysis with no surprises
147  // (expected checks and no unsoundness by missing checks).
149  options, !cmdline.isset("no-standard-checks"));
150 
151  if(config.set(cmdline))
152  {
153  usage_error();
155  }
156 
159 
160  if(cmdline.isset("function"))
161  options.set_option("function", cmdline.get_value("function"));
162 
163  if(cmdline.isset("cover") && cmdline.isset("unwinding-assertions"))
164  {
165  log.error()
166  << "--cover and --unwinding-assertions must not be given together"
167  << messaget::eom;
169  }
170 
171  // We want to warn the user that if we are using standard checks (that enables
172  // unwinding-assertions) and we did not disable them manually.
173  if(
174  cmdline.isset("cover") && !cmdline.isset("no-standard-checks") &&
175  !cmdline.isset("no-unwinding-assertions"))
176  {
177  log.warning() << "--cover is incompatible with --unwinding-assertions, so "
178  "unwinding-assertions will be defaulted to false"
179  << messaget::eom;
180  }
181 
182  // We want to set the unwinding-assertions option as early as we can,
183  // otherwise we come across two issues: 1) there's no way to deactivate it
184  // with `--no-unwinding-assertions`, as the `--no-xxx` flags are set by
185  // `goto_check_c` which doesn't provide handling for the options, and 2) we
186  // handle it only when we use `--no-standard-checks`, but if we do so, we have
187  // already printed a couple times to the screen that `--unwinding-assertions`
188  // must be passed because of some activation/sensitive further down below.
189  if(cmdline.isset("unwinding-assertions"))
190  {
191  options.set_option("unwinding-assertions", true);
192  options.set_option("paths-symex-explore-all", true);
193  }
194  else if(cmdline.isset("no-unwinding-assertions"))
195  {
196  options.set_option("unwinding-assertions", false);
197  options.set_option("paths-symex-explore-all", false);
198  }
199 
200  if(cmdline.isset("max-field-sensitivity-array-size"))
201  {
202  options.set_option(
203  "max-field-sensitivity-array-size",
204  cmdline.get_value("max-field-sensitivity-array-size"));
205  }
206 
207  if(cmdline.isset("no-array-field-sensitivity"))
208  {
209  if(cmdline.isset("max-field-sensitivity-array-size"))
210  {
211  log.error()
212  << "--no-array-field-sensitivity and --max-field-sensitivity-array-size"
213  << " must not be given together" << messaget::eom;
215  }
216  options.set_option("no-array-field-sensitivity", true);
217  }
218 
219  if(cmdline.isset("reachability-slice") &&
220  cmdline.isset("reachability-slice-fb"))
221  {
222  log.error()
223  << "--reachability-slice and --reachability-slice-fb must not be "
224  << "given together" << messaget::eom;
226  }
227 
228  if(cmdline.isset("full-slice"))
229  options.set_option("full-slice", true);
230 
231  if(cmdline.isset("show-symex-strategies"))
232  {
235  }
236 
238 
239  if(cmdline.isset("program-only"))
240  options.set_option("program-only", true);
241 
242  if(cmdline.isset("show-byte-ops"))
243  options.set_option("show-byte-ops", true);
244 
245  if(cmdline.isset("show-vcc"))
246  options.set_option("show-vcc", true);
247 
248  if(cmdline.isset("cover"))
249  {
250  parse_cover_options(cmdline, options);
251  // The default unwinding assertions option needs to be switched off when
252  // performing coverage checks because we intend to solve for coverage rather
253  // than assertions.
254  options.set_option("unwinding-assertions", false);
255  }
256 
257  if(cmdline.isset("mm"))
258  options.set_option("mm", cmdline.get_value("mm"));
259 
260  if(cmdline.isset("symex-complexity-limit"))
261  {
262  options.set_option(
263  "symex-complexity-limit", cmdline.get_value("symex-complexity-limit"));
264  log.warning() << "**** WARNING: Complexity-limited analysis may yield "
265  "unsound verification results"
266  << messaget::eom;
267  }
268 
269  if(cmdline.isset("symex-complexity-failed-child-loops-limit"))
270  {
271  options.set_option(
272  "symex-complexity-failed-child-loops-limit",
273  cmdline.get_value("symex-complexity-failed-child-loops-limit"));
274  if(!cmdline.isset("symex-complexity-limit"))
275  {
276  log.warning() << "**** WARNING: Complexity-limited analysis may yield "
277  "unsound verification results"
278  << messaget::eom;
279  }
280  }
281 
282  if(cmdline.isset("property"))
283  options.set_option("property", cmdline.get_values("property"));
284 
285  if(cmdline.isset("drop-unused-functions"))
286  options.set_option("drop-unused-functions", true);
287 
288  if(cmdline.isset("havoc-undefined-functions"))
289  options.set_option("havoc-undefined-functions", true);
290 
291  if(cmdline.isset("string-abstraction"))
292  options.set_option("string-abstraction", true);
293 
294  if(cmdline.isset("reachability-slice-fb"))
295  options.set_option("reachability-slice-fb", true);
296 
297  if(cmdline.isset("reachability-slice"))
298  options.set_option("reachability-slice", true);
299 
300  if(cmdline.isset("nondet-static"))
301  options.set_option("nondet-static", true);
302 
303  if(cmdline.isset("no-simplify"))
304  options.set_option("simplify", false);
305 
306  if(cmdline.isset("stop-on-fail") ||
307  cmdline.isset("dimacs") ||
308  cmdline.isset("outfile"))
309  options.set_option("stop-on-fail", true);
310 
311  if(
312  cmdline.isset("trace") || cmdline.isset("compact-trace") ||
313  cmdline.isset("stack-trace") || cmdline.isset("stop-on-fail") ||
315  !cmdline.isset("cover")))
316  {
317  options.set_option("trace", true);
318  }
319 
320  if(cmdline.isset("export-symex-ready-goto"))
321  {
322  options.set_option(
323  "export-symex-ready-goto", cmdline.get_value("export-symex-ready-goto"));
324  if(options.get_option("export-symex-ready-goto").empty())
325  {
326  log.error()
327  << "ERROR: Please provide a filename to write the goto-binary to."
328  << messaget::eom;
330  }
331  }
332 
333  if(cmdline.isset("localize-faults"))
334  options.set_option("localize-faults", true);
335 
336  if(cmdline.isset("unwind"))
337  {
338  options.set_option("unwind", cmdline.get_value("unwind"));
339  if(
340  !options.get_bool_option("unwinding-assertions") &&
341  !cmdline.isset("unwinding-assertions"))
342  {
343  log.warning() << "**** WARNING: Use --unwinding-assertions to obtain "
344  "sound verification results"
345  << messaget::eom;
346  }
347  }
348 
349  if(cmdline.isset("depth"))
350  {
351  options.set_option("depth", cmdline.get_value("depth"));
352  log.warning()
353  << "**** WARNING: Depth-bounded analysis may yield unsound verification "
354  "results"
355  << messaget::eom;
356  }
357 
358  if(cmdline.isset("slice-by-trace"))
359  {
360  log.error() << "--slice-by-trace has been removed" << messaget::eom;
362  }
363 
364  if(cmdline.isset("unwindset"))
365  {
366  options.set_option(
367  "unwindset", cmdline.get_comma_separated_values("unwindset"));
368  if(
369  !options.get_bool_option("unwinding-assertions") &&
370  !cmdline.isset("unwinding-assertions"))
371  {
372  log.warning() << "**** WARNING: Use --unwinding-assertions to obtain "
373  "sound verification results"
374  << messaget::eom;
375  }
376  }
377 
378  // constant propagation
379  if(cmdline.isset("no-propagation"))
380  options.set_option("propagation", false);
381 
382  // transform self loops to assumptions
383  options.set_option(
384  "self-loops-to-assumptions",
385  !cmdline.isset("no-self-loops-to-assumptions"));
386 
387  // all (other) checks supported by goto_check
389 
390  if(cmdline.isset("partial-loops"))
391  {
392  options.set_option("partial-loops", true);
393  log.warning()
394  << "**** WARNING: --partial-loops may yield unsound verification results"
395  << messaget::eom;
396  }
397 
398  // remove unused equations
399  if(cmdline.isset("slice-formula"))
400  options.set_option("slice-formula", true);
401 
402  if(cmdline.isset("arrays-uf-always"))
403  options.set_option("arrays-uf", "always");
404  else if(cmdline.isset("arrays-uf-never"))
405  options.set_option("arrays-uf", "never");
406 
407  if(cmdline.isset("show-array-constraints"))
408  options.set_option("show-array-constraints", true);
409 
410  if(cmdline.isset("refine-strings"))
411  {
412  options.set_option("refine-strings", true);
413  options.set_option("string-printable", cmdline.isset("string-printable"));
414  }
415 
416  options.set_option(
417  "symex-cache-dereferences", cmdline.isset("symex-cache-dereferences"));
418 
419  if(cmdline.isset("incremental-loop"))
420  {
421  options.set_option(
422  "incremental-loop", cmdline.get_value("incremental-loop"));
423  options.set_option("refine", true);
424  options.set_option("refine-arrays", true);
425 
426  if(cmdline.isset("unwind-min"))
427  options.set_option("unwind-min", cmdline.get_value("unwind-min"));
428 
429  if(cmdline.isset("unwind-max"))
430  options.set_option("unwind-max", cmdline.get_value("unwind-max"));
431 
432  if(cmdline.isset("ignore-properties-before-unwind-min"))
433  options.set_option("ignore-properties-before-unwind-min", true);
434 
435  if(cmdline.isset("paths"))
436  {
437  log.error() << "--paths not supported with --incremental-loop"
438  << messaget::eom;
440  }
441  }
442 
443  if(cmdline.isset("graphml-witness"))
444  {
445  options.set_option("graphml-witness", cmdline.get_value("graphml-witness"));
446  options.set_option("stop-on-fail", true);
447  options.set_option("trace", true);
448  }
449 
450  if(cmdline.isset("symex-coverage-report"))
451  {
452  options.set_option(
453  "symex-coverage-report",
454  cmdline.get_value("symex-coverage-report"));
455  options.set_option("paths-symex-explore-all", true);
456  }
457 
458  if(cmdline.isset("validate-ssa-equation"))
459  {
460  options.set_option("validate-ssa-equation", true);
461  }
462 
463  if(cmdline.isset("validate-goto-model"))
464  {
465  options.set_option("validate-goto-model", true);
466  }
467 
468  if(cmdline.isset("show-goto-symex-steps"))
469  options.set_option("show-goto-symex-steps", true);
470 
471  if(cmdline.isset("show-points-to-sets"))
472  options.set_option("show-points-to-sets", true);
473 
475 
476  // Options for process_goto_program
477  options.set_option("rewrite-rw-ok", true);
478  options.set_option("rewrite-union", true);
479 
480  if(cmdline.isset("smt1"))
481  {
482  log.error() << "--smt1 is no longer supported" << messaget::eom;
484  }
485 
486  parse_solver_options(cmdline, options);
487 }
488 
491 {
492  if(cmdline.isset("version"))
493  {
494  std::cout << CBMC_VERSION << '\n';
495  return CPROVER_EXIT_SUCCESS;
496  }
497 
498  //
499  // command line options
500  //
501 
502  optionst options;
503  get_command_line_options(options);
504 
507 
509 
510  //
511  // Unwinding of transition systems is done by hw-cbmc.
512  //
513 
514  if(cmdline.isset("module") ||
515  cmdline.isset("gen-interface"))
516  {
517  log.error() << "This version of CBMC has no support for "
518  " hardware modules. Please use hw-cbmc."
519  << messaget::eom;
521  }
522 
523  if(cmdline.isset("show-points-to-sets"))
524  {
525  if(!cmdline.isset("json-ui") || cmdline.isset("xml-ui"))
526  {
527  log.error() << "--show-points-to-sets supports only"
528  " json output. Use --json-ui."
529  << messaget::eom;
531  }
532  }
533 
534  if(cmdline.isset("show-array-constraints"))
535  {
536  if(!cmdline.isset("json-ui") || cmdline.isset("xml-ui"))
537  {
538  log.error() << "--show-array-constraints supports only"
539  " json output. Use --json-ui."
540  << messaget::eom;
542  }
543  }
544 
546 
547  // configure gcc, if required
549  {
550  gcc_versiont gcc_version;
551  gcc_version.get("gcc");
552  configure_gcc(gcc_version);
553  }
554 
555  if(cmdline.isset("test-preprocessor"))
559 
560  if(cmdline.isset("preprocess"))
561  {
562  preprocessing(options);
563  return CPROVER_EXIT_SUCCESS;
564  }
565 
566  if(cmdline.isset("show-parse-tree"))
567  {
568  if(
569  cmdline.args.size() != 1 ||
571  {
572  log.error() << "Please give exactly one source file" << messaget::eom;
574  }
575 
576  std::string filename=cmdline.args[0];
577 
578  std::ifstream infile(widen_if_needed(filename));
579 
580  if(!infile)
581  {
582  log.error() << "failed to open input file '" << filename << "'"
583  << messaget::eom;
585  }
586 
587  std::unique_ptr<languaget> language=
588  get_language_from_filename(filename);
589 
590  if(language==nullptr)
591  {
592  log.error() << "failed to figure out type of file '" << filename << "'"
593  << messaget::eom;
595  }
596 
597  language->set_language_options(options, ui_message_handler);
598 
599  log.status() << "Parsing " << filename << messaget::eom;
600 
601  if(language->parse(infile, filename, ui_message_handler))
602  {
603  log.error() << "PARSING ERROR" << messaget::eom;
605  }
606 
607  language->show_parse(std::cout, ui_message_handler);
608  return CPROVER_EXIT_SUCCESS;
609  }
610 
611  int get_goto_program_ret =
613 
614  if(get_goto_program_ret!=-1)
615  return get_goto_program_ret;
616 
617  if(cmdline.isset("show-claims") || // will go away
618  cmdline.isset("show-properties")) // use this one
619  {
621  return CPROVER_EXIT_SUCCESS;
622  }
623 
624  if(set_properties())
626 
627  // At this point, our goto-model should be in symex-ready-goto form (all of
628  // the transformations have been run and the program is ready to be given
629  // to the solver).
630  if(options.is_set("export-symex-ready-goto"))
631  {
632  auto symex_ready_goto_filename =
633  options.get_option("export-symex-ready-goto");
634 
635  bool success = !write_goto_binary(
636  symex_ready_goto_filename, goto_model, ui_message_handler);
637 
638  if(!success)
639  {
640  log.error() << "ERROR: Unable to export goto-program in file "
641  << symex_ready_goto_filename << messaget::eom;
643  }
644  else
645  {
646  log.status() << "Exported goto-program in symex-ready-goto form at "
647  << symex_ready_goto_filename << messaget::eom;
648  return CPROVER_EXIT_SUCCESS;
649  }
650  }
651 
652  if(
653  options.get_bool_option("program-only") ||
654  options.get_bool_option("show-vcc") ||
655  options.get_bool_option("show-byte-ops"))
656  {
657  if(options.get_bool_option("paths"))
658  {
660  options, ui_message_handler, goto_model);
661  (void)verifier();
662  }
663  else
664  {
666  options, ui_message_handler, goto_model);
667  (void)verifier();
668  }
669 
670  return CPROVER_EXIT_SUCCESS;
671  }
672 
673  if(
674  options.get_bool_option("dimacs") || !options.get_option("outfile").empty())
675  {
676  if(options.get_bool_option("paths"))
677  {
679  options, ui_message_handler, goto_model);
680  (void)verifier();
681  }
682  else
683  {
685  options, ui_message_handler, goto_model);
686  (void)verifier();
687  }
688 
689  return CPROVER_EXIT_SUCCESS;
690  }
691 
692  if(options.is_set("cover"))
693  {
695  verifier(options, ui_message_handler, goto_model);
696  (void)verifier();
697  verifier.report();
698 
699  if(options.get_bool_option("show-test-suite"))
700  {
701  c_test_input_generatort test_generator(ui_message_handler, options);
702  test_generator(verifier.get_traces());
703  }
704 
705  return CPROVER_EXIT_SUCCESS;
706  }
707 
708  std::unique_ptr<goto_verifiert> verifier = nullptr;
709 
710  if(options.is_set("incremental-loop"))
711  {
712  if(options.get_bool_option("stop-on-fail"))
713  {
714  verifier = std::make_unique<
716  options, ui_message_handler, goto_model);
717  }
718  else
719  {
720  verifier = std::make_unique<all_properties_verifier_with_trace_storaget<
722  options, ui_message_handler, goto_model);
723  }
724  }
725  else if(
726  options.get_bool_option("stop-on-fail") && options.get_bool_option("paths"))
727  {
728  verifier =
729  std::make_unique<stop_on_fail_verifiert<single_path_symex_checkert>>(
730  options, ui_message_handler, goto_model);
731  }
732  else if(
733  options.get_bool_option("stop-on-fail") &&
734  !options.get_bool_option("paths"))
735  {
736  if(options.get_bool_option("localize-faults"))
737  {
738  verifier =
741  }
742  else
743  {
744  verifier =
745  std::make_unique<stop_on_fail_verifiert<multi_path_symex_checkert>>(
746  options, ui_message_handler, goto_model);
747  }
748  }
749  else if(
750  !options.get_bool_option("stop-on-fail") &&
751  options.get_bool_option("paths"))
752  {
753  verifier = std::make_unique<
755  options, ui_message_handler, goto_model);
756  }
757  else if(
758  !options.get_bool_option("stop-on-fail") &&
759  !options.get_bool_option("paths"))
760  {
761  if(options.get_bool_option("localize-faults"))
762  {
763  verifier =
766  }
767  else
768  {
769  verifier = std::make_unique<
771  options, ui_message_handler, goto_model);
772  }
773  }
774  else
775  {
776  UNREACHABLE;
777  }
778 
779  const resultt result = (*verifier)();
780  verifier->report();
781 
782  return result_to_exit_code(result);
783 }
784 
786 {
787  if(cmdline.isset("claim")) // will go away
789 
790  if(cmdline.isset("property")) // use this one
792 
793  return false;
794 }
795 
797  goto_modelt &goto_model,
798  const optionst &options,
799  const cmdlinet &cmdline,
800  ui_message_handlert &ui_message_handler)
801 {
803  if(cmdline.args.empty())
804  {
805  log.error() << "Please provide a program to verify" << messaget::eom;
807  }
808 
810 
811  if(cmdline.isset("show-symbol-table"))
812  {
814  return CPROVER_EXIT_SUCCESS;
815  }
816 
819 
820  if(cmdline.isset("validate-goto-model"))
821  {
823  }
824 
825  // show it?
826  if(cmdline.isset("show-loops"))
827  {
829  return CPROVER_EXIT_SUCCESS;
830  }
831 
832  // show it?
833  if(
834  cmdline.isset("show-goto-functions") ||
835  cmdline.isset("list-goto-functions"))
836  {
838  goto_model, ui_message_handler, cmdline.isset("list-goto-functions"));
839  return CPROVER_EXIT_SUCCESS;
840  }
841 
843 
844  return -1; // no error, continue
845 }
846 
848 {
849  if(cmdline.args.size() != 1)
850  {
851  log.error() << "Please provide one program to preprocess" << messaget::eom;
852  return;
853  }
854 
855  std::string filename = cmdline.args[0];
856 
857  std::ifstream infile(filename);
858 
859  if(!infile)
860  {
861  log.error() << "failed to open input file" << messaget::eom;
862  return;
863  }
864 
865  std::unique_ptr<languaget> language = get_language_from_filename(filename);
866 
867  if(language == nullptr)
868  {
869  log.error() << "failed to figure out type of file" << messaget::eom;
870  return;
871  }
872 
873  language->set_language_options(options, ui_message_handler);
874 
875  if(language->preprocess(infile, filename, std::cout, ui_message_handler))
876  log.error() << "PREPROCESSING ERROR" << messaget::eom;
877 }
878 
880  goto_modelt &goto_model,
881  const optionst &options,
882  messaget &log)
883 {
884  // Remove inline assembler; this needs to happen before
885  // adding the library.
887 
888  // add the library
889  log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
890  << messaget::eom;
895  // library functions may introduce inline assembler
896  while(has_asm(goto_model))
897  {
903  }
904 
905  // Common removal of types and complex constructs
906  if(::process_goto_program(goto_model, options, log))
907  return true;
908 
909  // ignore default/user-specified initialization
910  // of variables with static lifetime
911  if(options.get_bool_option("nondet-static"))
912  {
913  log.status() << "Adding nondeterministic initialization "
914  "of static/global variables"
915  << messaget::eom;
917  }
918 
919  // add failed symbols
920  // needs to be done before pointer analysis
922 
923  if(options.get_bool_option("drop-unused-functions"))
924  {
925  // Entry point will have been set before and function pointers removed
926  log.status() << "Removing unused functions" << messaget::eom;
928  }
929 
930  // remove skips such that trivial GOTOs are deleted and not considered
931  // for coverage annotation:
933 
934  // instrument cover goals
935  if(options.is_set("cover"))
936  {
937  const auto cover_config = get_cover_config(
940  cover_config, goto_model, log.get_message_handler()))
941  return true;
942  }
943 
944  // label the assertions
945  // This must be done after adding assertions and
946  // before using the argument of the "property" option.
947  // Do not re-label after using the property slicer because
948  // this would cause the property identifiers to change.
950 
951  // reachability slice?
952  if(options.get_bool_option("reachability-slice-fb"))
953  {
954  log.status() << "Performing a forwards-backwards reachability slice"
955  << messaget::eom;
956  if(options.is_set("property"))
957  {
959  goto_model,
960  options.get_list_option("property"),
961  true,
963  }
964  else
966  }
967 
968  if(options.get_bool_option("reachability-slice"))
969  {
970  log.status() << "Performing a reachability slice" << messaget::eom;
971  if(options.is_set("property"))
972  {
974  goto_model,
975  options.get_list_option("property"),
977  }
978  else
980  }
981 
982  // full slice?
983  if(options.get_bool_option("full-slice"))
984  {
985  log.warning() << "**** WARNING: Experimental option --full-slice, "
986  << "analysis results may be unsound. See "
987  << "https://github.com/diffblue/cbmc/issues/260"
988  << messaget::eom;
989  log.status() << "Performing a full slice" << messaget::eom;
990  if(options.is_set("property"))
992  goto_model,
993  options.get_list_option("property"),
995  else
997  }
998 
999  // remove any skips introduced since coverage instrumentation
1001 
1002  return false;
1003 }
1004 
1007 {
1008  // clang-format off
1009  std::cout << '\n' << banner_string("CBMC", CBMC_VERSION) << '\n'
1010  << align_center_with_border("Copyright (C) 2001-2018") << '\n'
1011  << align_center_with_border("Daniel Kroening, Edmund Clarke") << '\n' // NOLINT(*)
1012  << align_center_with_border("Carnegie Mellon University, Computer Science Department") << '\n' // NOLINT(*)
1013  << align_center_with_border("kroening@kroening.com") << '\n' // NOLINT(*)
1014  << align_center_with_border("Protected in part by U.S. patent 7,225,417") << '\n'; // NOLINT(*)
1015 
1016  std::cout << help_formatter(
1017  "\n"
1018  "Usage: \tPurpose:\n"
1019  "\n"
1020  " {bcbmc} [{y-?}] [{y-h}] [{y--help}] \t show this help\n"
1021  " {bcbmc} {y--version} \t show version and exit\n"
1022  " {bcbmc} [options] {ufile.c} {u...} \t perform bounded model checking\n"
1023  "\n"
1024  "Analysis options:\n"
1026  " {y--symex-coverage-report} {uf} \t generate a Cobertura XML coverage"
1027  " report in {uf}\n"
1028  " {y--property} {uid} \t only check one specific property\n"
1029  " {y--trace} \t give a counterexample trace for failed properties\n"
1030  " {y--stop-on-fail} \t stop analysis once a failed property is detected"
1031  " (implies {y--trace})\n"
1032  " {y--localize-faults} \t localize faults (experimental)\n"
1033  "\n"
1034  "C/C++ frontend options:\n"
1035  " {y--preprocess} \t stop after preprocessing\n"
1036  " {y--test-preprocessor} \t stop after preprocessing, discard output\n"
1040  "\n"
1041  "Platform options:\n"
1043  "\n"
1044  "Program representations:\n"
1045  " {y--show-parse-tree} \t show parse tree\n"
1046  " {y--show-symbol-table} \t show loaded symbol table\n"
1049  " {y--export-symex-ready-goto} {uf} \t "
1050  "serialise goto-program in symex-ready-goto form in {uf}\n"
1051  "\n"
1052  "Program instrumentation options:\n"
1054  HELP_COVER
1055  " {y--mm} {uMM} \t memory consistency model for concurrent programs"
1056  " (default: {ysc})\n"
1059  " {y--full-slice} \t run full slicer (experimental)\n"
1060  " {y--drop-unused-functions} \t drop functions trivially unreachable from"
1061  " main function\n"
1062  " {y--havoc-undefined-functions} \t for any function that has no body,"
1063  " assign non-deterministic values to any parameters passed as non-const"
1064  " pointers and the return value\n"
1065  "\n"
1066  "Semantic transformations:\n"
1067  " {y--nondet-static} \t add nondeterministic initialization of variables"
1068  " with static lifetime\n"
1069  "\n"
1070  "BMC options:\n"
1071  HELP_BMC
1072  "\n"
1073  "Backend options:\n"
1075  HELP_SOLVER
1077  " {y--arrays-uf-never} \t never turn arrays into uninterpreted functions\n"
1078  " {y--arrays-uf-always} \t always turn arrays into uninterpreted"
1079  " functions\n"
1080  " {y--show-array-constraints} \t show array theory constraints added"
1081  " during post processing. Requires {y--json-ui}.\n"
1082  "\n"
1083  "User-interface options:\n"
1087  HELP_FLUSH
1088  " {y--verbosity} {u#} \t verbosity level\n"
1090  "\n");
1091  // clang-format on
1092 }
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.
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.
void cprover_c_library_factory(const std::set< irep_idt > &functions, const symbol_table_baset &symbol_table, symbol_table_baset &dest_symbol_table, message_handlert &message_handler)
#define HELP_ANSI_C_LANGUAGE
configt config
Definition: config.cpp:25
Bounded Model Checking Utilities.
#define HELP_BMC
Definition: bmc_util.h:197
void parse_c_object_factory_options(const cmdlinet &cmdline, optionst &options)
Parse the c object factory parameters from a given command line.
bool test_c_preprocessor(message_handlert &message_handler)
Test Input Generator for C.
CBMC Command Line Option Processing.
#define CBMC_OPTIONS
Requires an incremental goto checker that is a goto_trace_providert and fault_localization_providert.
virtual int doit() override
invoke main modules
static bool process_goto_program(goto_modelt &, const optionst &, messaget &)
static void set_default_options(optionst &)
Set the options that have default values.
static int get_goto_program(goto_modelt &, const optionst &, const cmdlinet &, ui_message_handlert &)
void get_command_line_options(optionst &)
void register_languages() override
void preprocessing(const optionst &)
static void set_default_analysis_flags(optionst &, const bool enabled)
Setup default analysis flags.
virtual void help() override
display command line help
cbmc_parse_optionst(int argc, const char **argv)
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:798
std::string object_bits_info()
Definition: config.cpp:1350
struct configt::ansi_ct ansi_c
void get(const std::string &executable)
Definition: gcc_version.cpp:18
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
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:31
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
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:399
mstreamt & warning() const
Definition: message.h:404
mstreamt & status() const
Definition: message.h:414
message_handlert & get_message_handler()
Definition: message.h:184
@ M_STATISTICS
Definition: message.h:171
static eomt eom
Definition: message.h:297
Performs a multi-path symbolic execution using goto-symex and calls a SAT/SMT solver to check the sta...
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
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
const value_listt & get_list_option(const std::string &option) const
Definition: options.cpp:80
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
Performs a multi-path symbolic execution using goto-symex that incrementally unwinds a given loop and...
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.
virtual uit get_ui() const
Definition: ui_message.h:33
#define HELP_CONFIG_LIBRARY
Definition: config.h:77
#define HELP_CONFIG_PLATFORM
Definition: config.h:96
#define HELP_CONFIG_C_CPP
Definition: config.h:32
#define HELP_CONFIG_BACKEND
Definition: config.h:126
static void instrument_cover_goals(const irep_idt &function_id, goto_programt &goto_program, const cover_instrumenterst &instrumenters, const irep_idt &mode, message_handlert &message_handler, const cover_instrumenter_baset::assertion_factoryt &make_assertion)
Applies instrumenters to given goto program.
Definition: cover.cpp:36
cover_configt get_cover_config(const optionst &options, const symbol_tablet &symbol_table, message_handlert &message_handler)
Build data structures controlling coverage from command-line options.
Definition: cover.cpp:181
void parse_cover_options(const cmdlinet &cmdline, optionst &options)
Parses coverage-related command line options.
Definition: cover.cpp:143
Coverage Instrumentation.
#define HELP_COVER
Definition: cover.h:32
Goto verifier for covering goals that stores traces.
void cprover_cpp_library_factory(const std::set< irep_idt > &functions, const symbol_table_baset &symbol_table, symbol_table_baset &dest_symbol_table, message_handlert &message_handler)
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_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
#define CPROVER_EXIT_SET_PROPERTIES_FAILED
Failure to identify the properties to verify.
Definition: exit_codes.h:55
#define CPROVER_EXIT_PREPROCESSOR_TEST_FAILED
Failure of the test-preprocessor method.
Definition: exit_codes.h:59
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)
void configure_gcc(const gcc_versiont &gcc_version)
#define PARSE_OPTIONS_GOTO_CHECK(cmdline, options)
Definition: goto_check_c.h:109
#define HELP_GOTO_CHECK
Definition: goto_check_c.h:57
#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)
goto_modelt initialize_goto_model(const std::vector< std::string > &files, message_handlert &message_handler, const optionst &options)
Initialize a Goto Program.
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
void show_loop_ids(ui_message_handlert::uit ui, const goto_modelt &goto_model)
Definition: loop_ids.cpp:21
Loop IDs.
double log(double x)
Definition: math.c:2776
std::unique_ptr< languaget > get_language_from_filename(const std::string &filename)
Get the language corresponding to the registered file name extensions.
Definition: mode.cpp:102
Goto Checker using Multi-Path Symbolic Execution.
Goto Checker using Multi-Path Symbolic Execution only (no SAT solving)
static void nondet_static(const namespacet &ns, goto_functionst &goto_functions, 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
Properties.
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
bool is_goto_binary(const std::string &filename, message_handlert &message_handler)
Read Goto Programs.
void remove_asm(goto_functionst &goto_functions, symbol_tablet &symbol_table, message_handlert &message_handler)
Replaces inline assembly instructions in the goto program (i.e., instructions of kind OTHER with a co...
Definition: remove_asm.cpp:575
bool has_asm(const goto_functionst &goto_functions)
returns true iff the given goto functions use asm instructions
Definition: remove_asm.cpp:598
Remove 'asm' statements by compiling them into suitable standard goto program instructions.
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 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)
Show the symbol table.
Goto Checker using multi-path symbolic execution with incremental unwinding of a specified loop.
Goto Checker using Single Path Symbolic Execution.
Goto Checker using Single Path Symbolic Execution only.
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 UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:525
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.
#define HELP_STRING_REFINEMENT_CBMC
irep_idt arch
Definition: config.h:221
preprocessort preprocessor
Definition: config.h:263
bool malloc_may_fail
Definition: config.h:279
malloc_failure_modet malloc_failure_mode
Definition: config.h:288
#define HELP_TIMESTAMP
Definition: timestamper.h:14
#define HELP_FLUSH
Definition: ui_message.h:108
#define widen_if_needed(s)
Definition: unicode.h:28
#define HELP_VALIDATE
const char * CBMC_VERSION
static void write_goto_binary(std::ostream &out, const symbol_table_baset &symbol_table, const goto_functionst &goto_functions, irep_serializationt &irepconverter)
Writes a goto program to disc, using goto binary format.
Write GOTO binaries.
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