22
22
#include < util/unicode.h>
23
23
#include < util/memory_info.h>
24
24
#include < util/invariant.h>
25
+ #include < util/exit_codes.h>
25
26
26
27
#include < ansi-c/c_preprocess.h>
27
28
@@ -106,7 +107,7 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
106
107
if (config.set (cmdline))
107
108
{
108
109
usage_error ();
109
- exit (1 ); // should contemplate EX_USAGE from sysexits.h
110
+ exit (CPROVER_EXIT_USAGE_ERROR);
110
111
}
111
112
112
113
if (cmdline.isset (" program-only" ))
@@ -224,7 +225,7 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
224
225
{
225
226
error () << " --partial-loops and --unwinding-assertions "
226
227
<< " must not be given together" << eom;
227
- exit (1 ); // should contemplate EX_USAGE from sysexits.h
228
+ exit (CPROVER_EXIT_USAGE_ERROR);
228
229
}
229
230
230
231
// remove unused equations
@@ -415,7 +416,7 @@ int cbmc_parse_optionst::doit()
415
416
if (cmdline.isset (" version" ))
416
417
{
417
418
std::cout << CBMC_VERSION << ' \n ' ;
418
- return 0 ; // should contemplate EX_OK from sysexits.h
419
+ return CPROVER_EXIT_SUCCESS;
419
420
}
420
421
421
422
//
@@ -431,13 +432,13 @@ int cbmc_parse_optionst::doit()
431
432
catch (const char *error_msg)
432
433
{
433
434
error () << error_msg << eom;
434
- return 6 ; // should contemplate EX_SOFTWARE from sysexits.h
435
+ return CPROVER_EXIT_EXCEPTION;
435
436
}
436
437
437
438
catch (const std::string error_msg)
438
439
{
439
440
error () << error_msg << eom;
440
- return 6 ; // should contemplate EX_SOFTWARE from sysexits.h
441
+ return CPROVER_EXIT_EXCEPTION;
441
442
}
442
443
443
444
eval_verbosity ();
@@ -459,18 +460,20 @@ int cbmc_parse_optionst::doit()
459
460
{
460
461
error () << " This version of CBMC has no support for "
461
462
" hardware modules. Please use hw-cbmc." << eom;
462
- return 1 ; // should contemplate EX_USAGE from sysexits.h
463
+ return CPROVER_EXIT_USAGE_ERROR;
463
464
}
464
465
465
466
register_languages ();
466
467
467
468
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;
469
472
470
473
if (cmdline.isset (" preprocess" ))
471
474
{
472
475
preprocessing ();
473
- return 0 ; // should contemplate EX_OK from sysexits.h
476
+ return CPROVER_EXIT_SUCCESS;
474
477
}
475
478
476
479
if (cmdline.isset (" show-parse-tree" ))
@@ -479,7 +482,7 @@ int cbmc_parse_optionst::doit()
479
482
is_goto_binary (cmdline.args [0 ]))
480
483
{
481
484
error () << " Please give exactly one source file" << eom;
482
- return 6 ;
485
+ return CPROVER_EXIT_INCORRECT_TASK ;
483
486
}
484
487
485
488
std::string filename=cmdline.args [0 ];
@@ -494,7 +497,7 @@ int cbmc_parse_optionst::doit()
494
497
{
495
498
error () << " failed to open input file `"
496
499
<< filename << " '" << eom;
497
- return 6 ;
500
+ return CPROVER_EXIT_INCORRECT_TASK ;
498
501
}
499
502
500
503
std::unique_ptr<languaget> language=
@@ -504,7 +507,7 @@ int cbmc_parse_optionst::doit()
504
507
{
505
508
error () << " failed to figure out type of file `"
506
509
<< filename << " '" << eom;
507
- return 6 ;
510
+ return CPROVER_EXIT_INCORRECT_TASK ;
508
511
}
509
512
510
513
language->get_language_options (cmdline);
@@ -515,11 +518,11 @@ int cbmc_parse_optionst::doit()
515
518
if (language->parse (infile, filename))
516
519
{
517
520
error () << " PARSING ERROR" << eom;
518
- return 6 ;
521
+ return CPROVER_EXIT_INCORRECT_TASK ;
519
522
}
520
523
521
524
language->show_parse (std::cout);
522
- return 0 ;
525
+ return CPROVER_EXIT_SUCCESS ;
523
526
}
524
527
525
528
int get_goto_program_ret=get_goto_program (options);
@@ -531,11 +534,11 @@ int cbmc_parse_optionst::doit()
531
534
cmdline.isset (" show-properties" )) // use this one
532
535
{
533
536
show_properties (goto_model, ui_message_handler.get_ui ());
534
- return 0 ; // should contemplate EX_OK from sysexits.h
537
+ return CPROVER_EXIT_SUCCESS;
535
538
}
536
539
537
540
if (set_properties ())
538
- return 7 ; // should contemplate EX_USAGE from sysexits.h
541
+ return CPROVER_EXIT_SET_PROPERTIES_FAILED;
539
542
540
543
// get solver
541
544
cbmc_solverst cbmc_solvers (
@@ -554,7 +557,7 @@ int cbmc_parse_optionst::doit()
554
557
catch (const char *error_msg)
555
558
{
556
559
error () << error_msg << eom;
557
- return 1 ; // should contemplate EX_SOFTWARE from sysexits.h
560
+ return CPROVER_EXIT_EXCEPTION;
558
561
}
559
562
560
563
prop_convt &prop_conv=cbmc_solver->prop_conv ();
@@ -592,8 +595,9 @@ bool cbmc_parse_optionst::set_properties()
592
595
return true ;
593
596
}
594
597
595
- catch (int )
598
+ catch (int e )
596
599
{
600
+ error () << " Numeric exception : " << e << eom;
597
601
return true ;
598
602
}
599
603
@@ -606,7 +610,7 @@ int cbmc_parse_optionst::get_goto_program(
606
610
if (cmdline.args .empty ())
607
611
{
608
612
error () << " Please provide a program to verify" << eom;
609
- return 6 ;
613
+ return CPROVER_EXIT_INCORRECT_TASK ;
610
614
}
611
615
612
616
try
@@ -616,24 +620,24 @@ int cbmc_parse_optionst::get_goto_program(
616
620
if (cmdline.isset (" show-symbol-table" ))
617
621
{
618
622
show_symbol_table (goto_model, ui_message_handler.get_ui ());
619
- return 0 ;
623
+ return CPROVER_EXIT_SUCCESS ;
620
624
}
621
625
622
626
if (process_goto_program (options))
623
- return 6 ;
627
+ return CPROVER_EXIT_INTERNAL_ERROR ;
624
628
625
629
// show it?
626
630
if (cmdline.isset (" show-loops" ))
627
631
{
628
632
show_loop_ids (ui_message_handler.get_ui (), goto_model);
629
- return 0 ;
633
+ return CPROVER_EXIT_SUCCESS ;
630
634
}
631
635
632
636
// show it?
633
637
if (cmdline.isset (" show-goto-functions" ))
634
638
{
635
639
show_goto_functions (goto_model, ui_message_handler.get_ui ());
636
- return 0 ;
640
+ return CPROVER_EXIT_SUCCESS ;
637
641
}
638
642
639
643
status () << config.object_bits_info () << eom;
@@ -642,24 +646,25 @@ int cbmc_parse_optionst::get_goto_program(
642
646
catch (const char *e)
643
647
{
644
648
error () << e << eom;
645
- return 6 ;
649
+ return CPROVER_EXIT_EXCEPTION ;
646
650
}
647
651
648
652
catch (const std::string e)
649
653
{
650
654
error () << e << eom;
651
- return 6 ;
655
+ return CPROVER_EXIT_EXCEPTION ;
652
656
}
653
657
654
- catch (int )
658
+ catch (int e )
655
659
{
656
- return 6 ;
660
+ error () << " Numeric exception : " << e << eom;
661
+ return CPROVER_EXIT_EXCEPTION;
657
662
}
658
663
659
664
catch (std::bad_alloc)
660
665
{
661
666
error () << " Out of memory" << eom;
662
- return 6 ;
667
+ return CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY ;
663
668
}
664
669
665
670
return -1 ; // no error, continue
@@ -710,13 +715,15 @@ void cbmc_parse_optionst::preprocessing()
710
715
error () << e << eom;
711
716
}
712
717
713
- catch (int )
718
+ catch (int e )
714
719
{
720
+ error () << " Numeric exception : " << e << eom;
715
721
}
716
722
717
723
catch (std::bad_alloc)
718
724
{
719
725
error () << " Out of memory" << eom;
726
+ exit (CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY);
720
727
}
721
728
}
722
729
@@ -843,14 +850,16 @@ bool cbmc_parse_optionst::process_goto_program(
843
850
return true ;
844
851
}
845
852
846
- catch (int )
853
+ catch (int e )
847
854
{
855
+ error () << " Numeric exception : " << e << eom;
848
856
return true ;
849
857
}
850
858
851
859
catch (std::bad_alloc)
852
860
{
853
861
error () << " Out of memory" << eom;
862
+ exit (CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY);
854
863
return true ;
855
864
}
856
865
@@ -862,19 +871,19 @@ int cbmc_parse_optionst::do_bmc(bmct &bmc)
862
871
{
863
872
bmc.set_ui (ui_message_handler.get_ui ());
864
873
865
- int result= 6 ;
874
+ int result = CPROVER_EXIT_INTERNAL_ERROR ;
866
875
867
876
// do actual BMC
868
877
switch (bmc.run (goto_model.goto_functions ))
869
878
{
870
879
case safety_checkert::resultt::SAFE:
871
- result= 0 ;
880
+ result = CPROVER_EXIT_VERIFICATION_SAFE ;
872
881
break ;
873
882
case safety_checkert::resultt::UNSAFE:
874
- result= 10 ;
883
+ result = CPROVER_EXIT_VERIFICATION_UNSAFE ;
875
884
break ;
876
885
case safety_checkert::resultt::ERROR:
877
- result= 6 ;
886
+ result = CPROVER_EXIT_INTERNAL_ERROR ;
878
887
break ;
879
888
}
880
889
0 commit comments