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 
22 #include <goto-programs/loop_ids.h>
32 
33 #include <ansi-c/c_preprocess.h>
34 #include <ansi-c/cprover_library.h>
35 #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("string-abstraction"))
289  options.set_option("string-abstraction", true);
290 
291  if(cmdline.isset("reachability-slice-fb"))
292  options.set_option("reachability-slice-fb", true);
293 
294  if(cmdline.isset("reachability-slice"))
295  options.set_option("reachability-slice", true);
296 
297  if(cmdline.isset("nondet-static"))
298  options.set_option("nondet-static", true);
299 
300  if(cmdline.isset("no-simplify"))
301  options.set_option("simplify", false);
302 
303  if(cmdline.isset("stop-on-fail") ||
304  cmdline.isset("dimacs") ||
305  cmdline.isset("outfile"))
306  options.set_option("stop-on-fail", true);
307 
308  if(
309  cmdline.isset("trace") || cmdline.isset("compact-trace") ||
310  cmdline.isset("stack-trace") || cmdline.isset("stop-on-fail") ||
312  !cmdline.isset("cover")))
313  {
314  options.set_option("trace", true);
315  }
316 
317  if(cmdline.isset("export-symex-ready-goto"))
318  {
319  options.set_option(
320  "export-symex-ready-goto", cmdline.get_value("export-symex-ready-goto"));
321  if(options.get_option("export-symex-ready-goto").empty())
322  {
323  log.error()
324  << "ERROR: Please provide a filename to write the goto-binary to."
325  << messaget::eom;
327  }
328  }
329 
330  if(cmdline.isset("localize-faults"))
331  options.set_option("localize-faults", true);
332 
333  if(cmdline.isset("unwind"))
334  {
335  options.set_option("unwind", cmdline.get_value("unwind"));
336  if(
337  !options.get_bool_option("unwinding-assertions") &&
338  !cmdline.isset("unwinding-assertions"))
339  {
340  log.warning() << "**** WARNING: Use --unwinding-assertions to obtain "
341  "sound verification results"
342  << messaget::eom;
343  }
344  }
345 
346  if(cmdline.isset("depth"))
347  {
348  options.set_option("depth", cmdline.get_value("depth"));
349  log.warning()
350  << "**** WARNING: Depth-bounded analysis may yield unsound verification "
351  "results"
352  << messaget::eom;
353  }
354 
355  if(cmdline.isset("slice-by-trace"))
356  {
357  log.error() << "--slice-by-trace has been removed" << messaget::eom;
359  }
360 
361  if(cmdline.isset("unwindset"))
362  {
363  options.set_option(
364  "unwindset", cmdline.get_comma_separated_values("unwindset"));
365  if(
366  !options.get_bool_option("unwinding-assertions") &&
367  !cmdline.isset("unwinding-assertions"))
368  {
369  log.warning() << "**** WARNING: Use --unwinding-assertions to obtain "
370  "sound verification results"
371  << messaget::eom;
372  }
373  }
374 
375  // constant propagation
376  if(cmdline.isset("no-propagation"))
377  options.set_option("propagation", false);
378 
379  // transform self loops to assumptions
380  options.set_option(
381  "self-loops-to-assumptions",
382  !cmdline.isset("no-self-loops-to-assumptions"));
383 
384  // all (other) checks supported by goto_check
386 
387  if(cmdline.isset("partial-loops"))
388  {
389  options.set_option("partial-loops", true);
390  log.warning()
391  << "**** WARNING: --partial-loops may yield unsound verification results"
392  << messaget::eom;
393  }
394 
395  // remove unused equations
396  if(cmdline.isset("slice-formula"))
397  options.set_option("slice-formula", true);
398 
399  if(cmdline.isset("arrays-uf-always"))
400  options.set_option("arrays-uf", "always");
401  else if(cmdline.isset("arrays-uf-never"))
402  options.set_option("arrays-uf", "never");
403 
404  if(cmdline.isset("show-array-constraints"))
405  options.set_option("show-array-constraints", true);
406 
407  if(cmdline.isset("refine-strings"))
408  {
409  options.set_option("refine-strings", true);
410  options.set_option("string-printable", cmdline.isset("string-printable"));
411  }
412 
413  options.set_option(
414  "symex-cache-dereferences", cmdline.isset("symex-cache-dereferences"));
415 
416  if(cmdline.isset("incremental-loop"))
417  {
418  options.set_option(
419  "incremental-loop", cmdline.get_value("incremental-loop"));
420  options.set_option("refine", true);
421  options.set_option("refine-arrays", true);
422 
423  if(cmdline.isset("unwind-min"))
424  options.set_option("unwind-min", cmdline.get_value("unwind-min"));
425 
426  if(cmdline.isset("unwind-max"))
427  options.set_option("unwind-max", cmdline.get_value("unwind-max"));
428 
429  if(cmdline.isset("ignore-properties-before-unwind-min"))
430  options.set_option("ignore-properties-before-unwind-min", true);
431 
432  if(cmdline.isset("paths"))
433  {
434  log.error() << "--paths not supported with --incremental-loop"
435  << messaget::eom;
437  }
438  }
439 
440  if(cmdline.isset("graphml-witness"))
441  {
442  options.set_option("graphml-witness", cmdline.get_value("graphml-witness"));
443  options.set_option("stop-on-fail", true);
444  options.set_option("trace", true);
445  }
446 
447  if(cmdline.isset("symex-coverage-report"))
448  {
449  options.set_option(
450  "symex-coverage-report",
451  cmdline.get_value("symex-coverage-report"));
452  options.set_option("paths-symex-explore-all", true);
453  }
454 
455  if(cmdline.isset("validate-ssa-equation"))
456  {
457  options.set_option("validate-ssa-equation", true);
458  }
459 
460  if(cmdline.isset("validate-goto-model"))
461  {
462  options.set_option("validate-goto-model", true);
463  }
464 
465  if(cmdline.isset("show-goto-symex-steps"))
466  options.set_option("show-goto-symex-steps", true);
467 
468  if(cmdline.isset("show-points-to-sets"))
469  options.set_option("show-points-to-sets", true);
470 
472 
473  // Options for process_goto_program
474  options.set_option("rewrite-rw-ok", true);
475  options.set_option("rewrite-union", true);
476 
477  if(cmdline.isset("smt1"))
478  {
479  log.error() << "--smt1 is no longer supported" << messaget::eom;
481  }
482 
483  parse_solver_options(cmdline, options);
484 }
485 
488 {
489  if(cmdline.isset("version"))
490  {
491  std::cout << CBMC_VERSION << '\n';
492  return CPROVER_EXIT_SUCCESS;
493  }
494 
495  //
496  // command line options
497  //
498 
499  optionst options;
500  get_command_line_options(options);
501 
504 
506 
507  //
508  // Unwinding of transition systems is done by hw-cbmc.
509  //
510 
511  if(cmdline.isset("module") ||
512  cmdline.isset("gen-interface"))
513  {
514  log.error() << "This version of CBMC has no support for "
515  " hardware modules. Please use hw-cbmc."
516  << messaget::eom;
518  }
519 
520  if(cmdline.isset("show-points-to-sets"))
521  {
522  if(!cmdline.isset("json-ui") || cmdline.isset("xml-ui"))
523  {
524  log.error() << "--show-points-to-sets supports only"
525  " json output. Use --json-ui."
526  << messaget::eom;
528  }
529  }
530 
531  if(cmdline.isset("show-array-constraints"))
532  {
533  if(!cmdline.isset("json-ui") || cmdline.isset("xml-ui"))
534  {
535  log.error() << "--show-array-constraints supports only"
536  " json output. Use --json-ui."
537  << messaget::eom;
539  }
540  }
541 
543 
544  // configure gcc, if required
546  {
547  gcc_versiont gcc_version;
548  gcc_version.get("gcc");
549  configure_gcc(gcc_version);
550  }
551 
552  if(cmdline.isset("test-preprocessor"))
556 
557  if(cmdline.isset("preprocess"))
558  {
559  preprocessing(options);
560  return CPROVER_EXIT_SUCCESS;
561  }
562 
563  if(cmdline.isset("show-parse-tree"))
564  {
565  if(
566  cmdline.args.size() != 1 ||
568  {
569  log.error() << "Please give exactly one source file" << messaget::eom;
571  }
572 
573  std::string filename=cmdline.args[0];
574 
575  std::ifstream infile(widen_if_needed(filename));
576 
577  if(!infile)
578  {
579  log.error() << "failed to open input file '" << filename << "'"
580  << messaget::eom;
582  }
583 
584  std::unique_ptr<languaget> language=
585  get_language_from_filename(filename);
586 
587  if(language==nullptr)
588  {
589  log.error() << "failed to figure out type of file '" << filename << "'"
590  << messaget::eom;
592  }
593 
594  language->set_language_options(options, ui_message_handler);
595 
596  log.status() << "Parsing " << filename << messaget::eom;
597 
598  if(language->parse(infile, filename, ui_message_handler))
599  {
600  log.error() << "PARSING ERROR" << messaget::eom;
602  }
603 
604  language->show_parse(std::cout, ui_message_handler);
605  return CPROVER_EXIT_SUCCESS;
606  }
607 
608  int get_goto_program_ret =
610 
611  if(get_goto_program_ret!=-1)
612  return get_goto_program_ret;
613 
614  if(cmdline.isset("show-claims") || // will go away
615  cmdline.isset("show-properties")) // use this one
616  {
618  return CPROVER_EXIT_SUCCESS;
619  }
620 
621  if(set_properties())
623 
624  // At this point, our goto-model should be in symex-ready-goto form (all of
625  // the transformations have been run and the program is ready to be given
626  // to the solver).
627  if(options.is_set("export-symex-ready-goto"))
628  {
629  auto symex_ready_goto_filename =
630  options.get_option("export-symex-ready-goto");
631 
632  bool success = !write_goto_binary(
633  symex_ready_goto_filename, goto_model, ui_message_handler);
634 
635  if(!success)
636  {
637  log.error() << "ERROR: Unable to export goto-program in file "
638  << symex_ready_goto_filename << messaget::eom;
640  }
641  else
642  {
643  log.status() << "Exported goto-program in symex-ready-goto form at "
644  << symex_ready_goto_filename << messaget::eom;
645  return CPROVER_EXIT_SUCCESS;
646  }
647  }
648 
649  if(
650  options.get_bool_option("program-only") ||
651  options.get_bool_option("show-vcc") ||
652  options.get_bool_option("show-byte-ops"))
653  {
654  if(options.get_bool_option("paths"))
655  {
657  options, ui_message_handler, goto_model);
658  (void)verifier();
659  }
660  else
661  {
663  options, ui_message_handler, goto_model);
664  (void)verifier();
665  }
666 
667  return CPROVER_EXIT_SUCCESS;
668  }
669 
670  if(
671  options.get_bool_option("dimacs") || !options.get_option("outfile").empty())
672  {
673  if(options.get_bool_option("paths"))
674  {
676  options, ui_message_handler, goto_model);
677  (void)verifier();
678  }
679  else
680  {
682  options, ui_message_handler, goto_model);
683  (void)verifier();
684  }
685 
686  return CPROVER_EXIT_SUCCESS;
687  }
688 
689  if(options.is_set("cover"))
690  {
692  verifier(options, ui_message_handler, goto_model);
693  (void)verifier();
694  verifier.report();
695 
696  if(options.get_bool_option("show-test-suite"))
697  {
698  c_test_input_generatort test_generator(ui_message_handler, options);
699  test_generator(verifier.get_traces());
700  }
701 
702  return CPROVER_EXIT_SUCCESS;
703  }
704 
705  std::unique_ptr<goto_verifiert> verifier = nullptr;
706 
707  if(options.is_set("incremental-loop"))
708  {
709  if(options.get_bool_option("stop-on-fail"))
710  {
711  verifier = std::make_unique<
713  options, ui_message_handler, goto_model);
714  }
715  else
716  {
717  verifier = std::make_unique<all_properties_verifier_with_trace_storaget<
719  options, ui_message_handler, goto_model);
720  }
721  }
722  else if(
723  options.get_bool_option("stop-on-fail") && options.get_bool_option("paths"))
724  {
725  verifier =
726  std::make_unique<stop_on_fail_verifiert<single_path_symex_checkert>>(
727  options, ui_message_handler, goto_model);
728  }
729  else if(
730  options.get_bool_option("stop-on-fail") &&
731  !options.get_bool_option("paths"))
732  {
733  if(options.get_bool_option("localize-faults"))
734  {
735  verifier =
738  }
739  else
740  {
741  verifier =
742  std::make_unique<stop_on_fail_verifiert<multi_path_symex_checkert>>(
743  options, ui_message_handler, goto_model);
744  }
745  }
746  else if(
747  !options.get_bool_option("stop-on-fail") &&
748  options.get_bool_option("paths"))
749  {
750  verifier = std::make_unique<
752  options, ui_message_handler, goto_model);
753  }
754  else if(
755  !options.get_bool_option("stop-on-fail") &&
756  !options.get_bool_option("paths"))
757  {
758  if(options.get_bool_option("localize-faults"))
759  {
760  verifier =
763  }
764  else
765  {
766  verifier = std::make_unique<
768  options, ui_message_handler, goto_model);
769  }
770  }
771  else
772  {
773  UNREACHABLE;
774  }
775 
776  const resultt result = (*verifier)();
777  verifier->report();
778 
779  return result_to_exit_code(result);
780 }
781 
783 {
784  if(cmdline.isset("claim")) // will go away
786 
787  if(cmdline.isset("property")) // use this one
789 
790  return false;
791 }
792 
794  goto_modelt &goto_model,
795  const optionst &options,
796  const cmdlinet &cmdline,
797  ui_message_handlert &ui_message_handler)
798 {
800  if(cmdline.args.empty())
801  {
802  log.error() << "Please provide a program to verify" << messaget::eom;
804  }
805 
807 
809 
810  if(cmdline.isset("show-symbol-table"))
811  {
813  return CPROVER_EXIT_SUCCESS;
814  }
815 
818 
819  if(cmdline.isset("validate-goto-model"))
820  {
822  }
823 
824  // show it?
825  if(cmdline.isset("show-loops"))
826  {
828  return CPROVER_EXIT_SUCCESS;
829  }
830 
831  // show it?
832  if(
833  cmdline.isset("show-goto-functions") ||
834  cmdline.isset("list-goto-functions"))
835  {
837  goto_model, ui_message_handler, cmdline.isset("list-goto-functions"));
838  return CPROVER_EXIT_SUCCESS;
839  }
840 
842 
843  return -1; // no error, continue
844 }
845 
847 {
848  if(cmdline.args.size() != 1)
849  {
850  log.error() << "Please provide one program to preprocess" << messaget::eom;
851  return;
852  }
853 
854  std::string filename = cmdline.args[0];
855 
856  std::ifstream infile(filename);
857 
858  if(!infile)
859  {
860  log.error() << "failed to open input file" << messaget::eom;
861  return;
862  }
863 
864  std::unique_ptr<languaget> language = get_language_from_filename(filename);
865 
866  if(language == nullptr)
867  {
868  log.error() << "failed to figure out type of file" << messaget::eom;
869  return;
870  }
871 
872  language->set_language_options(options, ui_message_handler);
873 
874  if(language->preprocess(infile, filename, std::cout, ui_message_handler))
875  log.error() << "PREPROCESSING ERROR" << messaget::eom;
876 }
877 
879  goto_modelt &goto_model,
880  const optionst &options,
881  messaget &log)
882 {
883  // Remove inline assembler; this needs to happen before
884  // adding the library.
886 
887  // add the library
888  log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
889  << messaget::eom;
894  // library functions may introduce inline assembler
895  while(has_asm(goto_model))
896  {
902  }
903 
904  // Common removal of types and complex constructs
905  if(::process_goto_program(goto_model, options, log))
906  return true;
907 
908  // ignore default/user-specified initialization
909  // of variables with static lifetime
910  if(options.get_bool_option("nondet-static"))
911  {
912  log.status() << "Adding nondeterministic initialization "
913  "of static/global variables"
914  << messaget::eom;
916  }
917 
918  // add failed symbols
919  // needs to be done before pointer analysis
921 
922  if(options.get_bool_option("drop-unused-functions"))
923  {
924  // Entry point will have been set before and function pointers removed
925  log.status() << "Removing unused functions" << messaget::eom;
927  }
928 
929  // remove skips such that trivial GOTOs are deleted and not considered
930  // for coverage annotation:
932 
933  // instrument cover goals
934  if(options.is_set("cover"))
935  {
936  const auto cover_config = get_cover_config(
939  cover_config, goto_model, log.get_message_handler()))
940  return true;
941  }
942 
943  // label the assertions
944  // This must be done after adding assertions and
945  // before using the argument of the "property" option.
946  // Do not re-label after using the property slicer because
947  // this would cause the property identifiers to change.
949 
950  // reachability slice?
951  if(options.get_bool_option("reachability-slice-fb"))
952  {
953  log.status() << "Performing a forwards-backwards reachability slice"
954  << messaget::eom;
955  if(options.is_set("property"))
956  {
958  goto_model,
959  options.get_list_option("property"),
960  true,
962  }
963  else
965  }
966 
967  if(options.get_bool_option("reachability-slice"))
968  {
969  log.status() << "Performing a reachability slice" << messaget::eom;
970  if(options.is_set("property"))
971  {
973  goto_model,
974  options.get_list_option("property"),
976  }
977  else
979  }
980 
981  // full slice?
982  if(options.get_bool_option("full-slice"))
983  {
984  log.warning() << "**** WARNING: Experimental option --full-slice, "
985  << "analysis results may be unsound. See "
986  << "https://github.com/diffblue/cbmc/issues/260"
987  << messaget::eom;
988  log.status() << "Performing a full slice" << messaget::eom;
989  if(options.is_set("property"))
991  goto_model,
992  options.get_list_option("property"),
994  else
996  }
997 
998  // remove any skips introduced since coverage instrumentation
1000 
1001  return false;
1002 }
1003 
1006 {
1007  // clang-format off
1008  std::cout << '\n' << banner_string("CBMC", CBMC_VERSION) << '\n'
1009  << align_center_with_border("Copyright (C) 2001-2018") << '\n'
1010  << align_center_with_border("Daniel Kroening, Edmund Clarke") << '\n' // NOLINT(*)
1011  << align_center_with_border("Carnegie Mellon University, Computer Science Department") << '\n' // NOLINT(*)
1012  << align_center_with_border("kroening@kroening.com") << '\n' // NOLINT(*)
1013  << align_center_with_border("Protected in part by U.S. patent 7,225,417") << '\n'; // NOLINT(*)
1014 
1015  std::cout << help_formatter(
1016  "\n"
1017  "Usage: \tPurpose:\n"
1018  "\n"
1019  " {bcbmc} [{y-?}] [{y-h}] [{y--help}] \t show this help\n"
1020  " {bcbmc} {y--version} \t show version and exit\n"
1021  " {bcbmc} [options] {ufile.c} {u...} \t perform bounded model checking\n"
1022  "\n"
1023  "Analysis options:\n"
1025  " {y--symex-coverage-report} {uf} \t generate a Cobertura XML coverage"
1026  " report in {uf}\n"
1027  " {y--property} {uid} \t only check one specific property\n"
1028  " {y--trace} \t give a counterexample trace for failed properties\n"
1029  " {y--stop-on-fail} \t stop analysis once a failed property is detected"
1030  " (implies {y--trace})\n"
1031  " {y--localize-faults} \t localize faults (experimental)\n"
1032  "\n"
1033  "C/C++ frontend options:\n"
1034  " {y--preprocess} \t stop after preprocessing\n"
1035  " {y--test-preprocessor} \t stop after preprocessing, discard output\n"
1039  "\n"
1040  "Platform options:\n"
1042  "\n"
1043  "Program representations:\n"
1044  " {y--show-parse-tree} \t show parse tree\n"
1045  " {y--show-symbol-table} \t show loaded symbol table\n"
1048  " {y--export-symex-ready-goto} {uf} \t "
1049  "serialise goto-program in symex-ready-goto form in {uf}\n"
1050  "\n"
1051  "Program instrumentation options:\n"
1053  HELP_COVER
1054  " {y--mm} {uMM} \t memory consistency model for concurrent programs"
1055  " (default: {ysc})\n"
1058  " {y--full-slice} \t run full slicer (experimental)\n"
1059  " {y--drop-unused-functions} \t drop functions trivially unreachable from"
1060  " main function\n"
1061  "\n"
1062  "Semantic transformations:\n"
1063  " {y--nondet-static} \t add nondeterministic initialization of variables"
1064  " with static lifetime\n"
1065  "\n"
1066  "BMC options:\n"
1067  HELP_BMC
1068  "\n"
1069  "Backend options:\n"
1071  HELP_SOLVER
1073  " {y--arrays-uf-never} \t never turn arrays into uninterpreted functions\n"
1074  " {y--arrays-uf-always} \t always turn arrays into uninterpreted"
1075  " functions\n"
1076  " {y--show-array-constraints} \t show array theory constraints added"
1077  " during post processing. Requires {y--json-ui}.\n"
1078  "\n"
1079  "User-interface options:\n"
1083  HELP_FLUSH
1084  " {y--verbosity} {u#} \t verbosity level (default 6)\n"
1086  "\n");
1087  // clang-format on
1088 }
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:863
std::string object_bits_info()
Definition: config.cpp:1431
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:154
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 & statistics() const
Definition: message.h:411
mstreamt & warning() const
Definition: message.h:396
mstreamt & status() const
Definition: message.h:406
message_handlert & get_message_handler()
Definition: message.h:183
@ M_STATUS
Definition: message.h:169
static eomt eom
Definition: message.h:289
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)
void update_max_malloc_size(goto_modelt &goto_model, message_handlert &message_handler)
Update the initial value of __CPROVER_max_malloc_size in case the number of object bits has changed.
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_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
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:223
preprocessort preprocessor
Definition: config.h:267
bool malloc_may_fail
Definition: config.h:283
malloc_failure_modet malloc_failure_mode
Definition: config.h:292
#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