2222#include < util/unicode.h>
2323#include < util/memory_info.h>
2424#include < util/invariant.h>
25+ #include < util/exit_codes.h>
2526
2627#include < ansi-c/c_preprocess.h>
2728
@@ -106,7 +107,7 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
106107 if (config.set (cmdline))
107108 {
108109 usage_error ();
109- exit (1 ); // should contemplate EX_USAGE from sysexits.h
110+ exit (CPROVER_EXIT_USAGE_ERROR);
110111 }
111112
112113 if (cmdline.isset (" program-only" ))
@@ -224,7 +225,7 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
224225 {
225226 error () << " --partial-loops and --unwinding-assertions "
226227 << " must not be given together" << eom;
227- exit (1 ); // should contemplate EX_USAGE from sysexits.h
228+ exit (CPROVER_EXIT_USAGE_ERROR);
228229 }
229230
230231 // remove unused equations
@@ -415,7 +416,7 @@ int cbmc_parse_optionst::doit()
415416 if (cmdline.isset (" version" ))
416417 {
417418 std::cout << CBMC_VERSION << ' \n ' ;
418- return 0 ; // should contemplate EX_OK from sysexits.h
419+ return CPROVER_EXIT_SUCCESS;
419420 }
420421
421422 //
@@ -431,13 +432,13 @@ int cbmc_parse_optionst::doit()
431432 catch (const char *error_msg)
432433 {
433434 error () << error_msg << eom;
434- return 6 ; // should contemplate EX_SOFTWARE from sysexits.h
435+ return CPROVER_EXIT_EXCEPTION;
435436 }
436437
437438 catch (const std::string error_msg)
438439 {
439440 error () << error_msg << eom;
440- return 6 ; // should contemplate EX_SOFTWARE from sysexits.h
441+ return CPROVER_EXIT_EXCEPTION;
441442 }
442443
443444 eval_verbosity ();
@@ -459,18 +460,20 @@ int cbmc_parse_optionst::doit()
459460 {
460461 error () << " This version of CBMC has no support for "
461462 " hardware modules. Please use hw-cbmc." << eom;
462- return 1 ; // should contemplate EX_USAGE from sysexits.h
463+ return CPROVER_EXIT_USAGE_ERROR;
463464 }
464465
465466 register_languages ();
466467
467468 if (cmdline.isset (" test-preprocessor" ))
468- return test_c_preprocessor (get_message_handler ())?8 :0 ;
469+ return test_c_preprocessor (get_message_handler ())
470+ ? CPROVER_EXIT_PREPROCESSOR_TEST_FAILED
471+ : CPROVER_EXIT_SUCCESS;
469472
470473 if (cmdline.isset (" preprocess" ))
471474 {
472475 preprocessing ();
473- return 0 ; // should contemplate EX_OK from sysexits.h
476+ return CPROVER_EXIT_SUCCESS;
474477 }
475478
476479 if (cmdline.isset (" show-parse-tree" ))
@@ -479,7 +482,7 @@ int cbmc_parse_optionst::doit()
479482 is_goto_binary (cmdline.args [0 ]))
480483 {
481484 error () << " Please give exactly one source file" << eom;
482- return 6 ;
485+ return CPROVER_EXIT_INCORRECT_TASK ;
483486 }
484487
485488 std::string filename=cmdline.args [0 ];
@@ -494,7 +497,7 @@ int cbmc_parse_optionst::doit()
494497 {
495498 error () << " failed to open input file `"
496499 << filename << " '" << eom;
497- return 6 ;
500+ return CPROVER_EXIT_INCORRECT_TASK ;
498501 }
499502
500503 std::unique_ptr<languaget> language=
@@ -504,7 +507,7 @@ int cbmc_parse_optionst::doit()
504507 {
505508 error () << " failed to figure out type of file `"
506509 << filename << " '" << eom;
507- return 6 ;
510+ return CPROVER_EXIT_INCORRECT_TASK ;
508511 }
509512
510513 language->get_language_options (cmdline);
@@ -515,11 +518,11 @@ int cbmc_parse_optionst::doit()
515518 if (language->parse (infile, filename))
516519 {
517520 error () << " PARSING ERROR" << eom;
518- return 6 ;
521+ return CPROVER_EXIT_INCORRECT_TASK ;
519522 }
520523
521524 language->show_parse (std::cout);
522- return 0 ;
525+ return CPROVER_EXIT_SUCCESS ;
523526 }
524527
525528 int get_goto_program_ret=get_goto_program (options);
@@ -531,11 +534,11 @@ int cbmc_parse_optionst::doit()
531534 cmdline.isset (" show-properties" )) // use this one
532535 {
533536 show_properties (goto_model, ui_message_handler.get_ui ());
534- return 0 ; // should contemplate EX_OK from sysexits.h
537+ return CPROVER_EXIT_SUCCESS;
535538 }
536539
537540 if (set_properties ())
538- return 7 ; // should contemplate EX_USAGE from sysexits.h
541+ return CPROVER_EXIT_SET_PROPERTIES_FAILED;
539542
540543 // get solver
541544 cbmc_solverst cbmc_solvers (
@@ -554,7 +557,7 @@ int cbmc_parse_optionst::doit()
554557 catch (const char *error_msg)
555558 {
556559 error () << error_msg << eom;
557- return 1 ; // should contemplate EX_SOFTWARE from sysexits.h
560+ return CPROVER_EXIT_EXCEPTION;
558561 }
559562
560563 prop_convt &prop_conv=cbmc_solver->prop_conv ();
@@ -592,8 +595,9 @@ bool cbmc_parse_optionst::set_properties()
592595 return true ;
593596 }
594597
595- catch (int )
598+ catch (int e )
596599 {
600+ error () << " Numeric exception : " << e << eom;
597601 return true ;
598602 }
599603
@@ -606,7 +610,7 @@ int cbmc_parse_optionst::get_goto_program(
606610 if (cmdline.args .empty ())
607611 {
608612 error () << " Please provide a program to verify" << eom;
609- return 6 ;
613+ return CPROVER_EXIT_INCORRECT_TASK ;
610614 }
611615
612616 try
@@ -616,24 +620,24 @@ int cbmc_parse_optionst::get_goto_program(
616620 if (cmdline.isset (" show-symbol-table" ))
617621 {
618622 show_symbol_table (goto_model, ui_message_handler.get_ui ());
619- return 0 ;
623+ return CPROVER_EXIT_SUCCESS ;
620624 }
621625
622626 if (process_goto_program (options))
623- return 6 ;
627+ return CPROVER_EXIT_INTERNAL_ERROR ;
624628
625629 // show it?
626630 if (cmdline.isset (" show-loops" ))
627631 {
628632 show_loop_ids (ui_message_handler.get_ui (), goto_model);
629- return 0 ;
633+ return CPROVER_EXIT_SUCCESS ;
630634 }
631635
632636 // show it?
633637 if (cmdline.isset (" show-goto-functions" ))
634638 {
635639 show_goto_functions (goto_model, ui_message_handler.get_ui ());
636- return 0 ;
640+ return CPROVER_EXIT_SUCCESS ;
637641 }
638642
639643 status () << config.object_bits_info () << eom;
@@ -642,24 +646,25 @@ int cbmc_parse_optionst::get_goto_program(
642646 catch (const char *e)
643647 {
644648 error () << e << eom;
645- return 6 ;
649+ return CPROVER_EXIT_EXCEPTION ;
646650 }
647651
648652 catch (const std::string e)
649653 {
650654 error () << e << eom;
651- return 6 ;
655+ return CPROVER_EXIT_EXCEPTION ;
652656 }
653657
654- catch (int )
658+ catch (int e )
655659 {
656- return 6 ;
660+ error () << " Numeric exception : " << e << eom;
661+ return CPROVER_EXIT_EXCEPTION;
657662 }
658663
659664 catch (std::bad_alloc)
660665 {
661666 error () << " Out of memory" << eom;
662- return 6 ;
667+ return CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY ;
663668 }
664669
665670 return -1 ; // no error, continue
@@ -710,13 +715,15 @@ void cbmc_parse_optionst::preprocessing()
710715 error () << e << eom;
711716 }
712717
713- catch (int )
718+ catch (int e )
714719 {
720+ error () << " Numeric exception : " << e << eom;
715721 }
716722
717723 catch (std::bad_alloc)
718724 {
719725 error () << " Out of memory" << eom;
726+ exit (CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY);
720727 }
721728}
722729
@@ -843,14 +850,16 @@ bool cbmc_parse_optionst::process_goto_program(
843850 return true ;
844851 }
845852
846- catch (int )
853+ catch (int e )
847854 {
855+ error () << " Numeric exception : " << e << eom;
848856 return true ;
849857 }
850858
851859 catch (std::bad_alloc)
852860 {
853861 error () << " Out of memory" << eom;
862+ exit (CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY);
854863 return true ;
855864 }
856865
@@ -862,19 +871,19 @@ int cbmc_parse_optionst::do_bmc(bmct &bmc)
862871{
863872 bmc.set_ui (ui_message_handler.get_ui ());
864873
865- int result= 6 ;
874+ int result = CPROVER_EXIT_INTERNAL_ERROR ;
866875
867876 // do actual BMC
868877 switch (bmc.run (goto_model.goto_functions ))
869878 {
870879 case safety_checkert::resultt::SAFE:
871- result= 0 ;
880+ result = CPROVER_EXIT_VERIFICATION_SAFE ;
872881 break ;
873882 case safety_checkert::resultt::UNSAFE:
874- result= 10 ;
883+ result = CPROVER_EXIT_VERIFICATION_UNSAFE ;
875884 break ;
876885 case safety_checkert::resultt::ERROR:
877- result= 6 ;
886+ result = CPROVER_EXIT_INTERNAL_ERROR ;
878887 break ;
879888 }
880889
0 commit comments