Skip to content

Commit 961d33a

Browse files
author
martin
committed
Replace literal constants in returns / exits with their symbolic names.
This should not alter the compiled binary or it's behaviour.
1 parent e74b442 commit 961d33a

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

src/cbmc/cbmc_parse_options.cpp

+32-29
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Author: Daniel Kroening, [email protected]
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_USAGE_ERROR; // should contemplate EX_SOFTWARE from sysexits.h
558561
}
559562

560563
prop_convt &prop_conv=cbmc_solver->prop_conv();
@@ -606,7 +609,7 @@ int cbmc_parse_optionst::get_goto_program(
606609
if(cmdline.args.empty())
607610
{
608611
error() << "Please provide a program to verify" << eom;
609-
return 6;
612+
return CPROVER_EXIT_INCORRECT_TASK;
610613
}
611614

612615
try
@@ -616,24 +619,24 @@ int cbmc_parse_optionst::get_goto_program(
616619
if(cmdline.isset("show-symbol-table"))
617620
{
618621
show_symbol_table(goto_model, ui_message_handler.get_ui());
619-
return 0;
622+
return CPROVER_EXIT_SUCCESS;
620623
}
621624

622625
if(process_goto_program(options))
623-
return 6;
626+
return CPROVER_EXIT_INTERNAL_ERROR;
624627

625628
// show it?
626629
if(cmdline.isset("show-loops"))
627630
{
628631
show_loop_ids(ui_message_handler.get_ui(), goto_model);
629-
return 0;
632+
return CPROVER_EXIT_SUCCESS;
630633
}
631634

632635
// show it?
633636
if(cmdline.isset("show-goto-functions"))
634637
{
635638
show_goto_functions(goto_model, ui_message_handler.get_ui());
636-
return 0;
639+
return CPROVER_EXIT_SUCCESS;
637640
}
638641

639642
status() << config.object_bits_info() << eom;
@@ -642,24 +645,24 @@ int cbmc_parse_optionst::get_goto_program(
642645
catch(const char *e)
643646
{
644647
error() << e << eom;
645-
return 6;
648+
return CPROVER_EXIT_EXCEPTION;
646649
}
647650

648651
catch(const std::string e)
649652
{
650653
error() << e << eom;
651-
return 6;
654+
return CPROVER_EXIT_EXCEPTION;
652655
}
653656

654657
catch(int)
655658
{
656-
return 6;
659+
return CPROVER_EXIT_EXCEPTION;
657660
}
658661

659662
catch(std::bad_alloc)
660663
{
661664
error() << "Out of memory" << eom;
662-
return 6;
665+
return CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY;
663666
}
664667

665668
return -1; // no error, continue
@@ -862,19 +865,19 @@ int cbmc_parse_optionst::do_bmc(bmct &bmc)
862865
{
863866
bmc.set_ui(ui_message_handler.get_ui());
864867

865-
int result=6;
868+
int result = CPROVER_EXIT_INTERNAL_ERROR;
866869

867870
// do actual BMC
868871
switch(bmc.run(goto_model.goto_functions))
869872
{
870873
case safety_checkert::resultt::SAFE:
871-
result=0;
874+
result = CPROVER_EXIT_VERIFICATION_SAFE;
872875
break;
873876
case safety_checkert::resultt::UNSAFE:
874-
result=10;
877+
result = CPROVER_EXIT_VERIFICATION_UNSAFE;
875878
break;
876879
case safety_checkert::resultt::ERROR:
877-
result=6;
880+
result = CPROVER_EXIT_INTERNAL_ERROR;
878881
break;
879882
}
880883

0 commit comments

Comments
 (0)