Skip to content

Commit a0e5063

Browse files
Enable goto check and cover options in goto-diff
to be able to compare properties. The java options are added to be able to use --java-throw-runtime-exceptions.
1 parent a0c45f4 commit a0e5063

File tree

4 files changed

+95
-44
lines changed

4 files changed

+95
-44
lines changed

src/goto-diff/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ target_link_libraries(goto-diff-lib
1313
linking
1414
big-int
1515
pointer-analysis
16+
goto-instrument-lib
1617
goto-programs
1718
assembler
1819
analyses

src/goto-diff/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
1515
../goto-programs/goto-programs$(LIBEXT) \
1616
../assembler/assembler$(LIBEXT) \
1717
../pointer-analysis/pointer-analysis$(LIBEXT) \
18+
../goto-instrument/cover$(OBJEXT) \
19+
../goto-instrument/cover_basic_blocks$(OBJEXT) \
20+
../goto-instrument/cover_filter$(OBJEXT) \
21+
../goto-instrument/cover_instrument_branch$(OBJEXT) \
22+
../goto-instrument/cover_instrument_condition$(OBJEXT) \
23+
../goto-instrument/cover_instrument_decision$(OBJEXT) \
24+
../goto-instrument/cover_instrument_location$(OBJEXT) \
25+
../goto-instrument/cover_instrument_mcdc$(OBJEXT) \
26+
../goto-instrument/cover_instrument_other$(OBJEXT) \
27+
../goto-instrument/cover_util$(OBJEXT) \
28+
../goto-symex/adjust_float_expressions$(OBJEXT) \
29+
../goto-symex/rewrite_union$(OBJEXT) \
1830
../analyses/analyses$(LIBEXT) \
1931
../langapi/langapi$(LIBEXT) \
2032
../xmllang/xmllang$(LIBEXT) \

src/goto-diff/goto_diff_parse_options.cpp

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,23 @@ Author: Peter Schrammel
2020
#include <util/config.h>
2121
#include <util/options.h>
2222
#include <util/make_unique.h>
23+
#include <util/exit_codes.h>
2324

2425
#include <langapi/language.h>
2526

2627
#include <goto-programs/goto_convert_functions.h>
28+
#include <goto-programs/instrument_preconditions.h>
29+
#include <goto-programs/mm_io.h>
2730
#include <goto-programs/remove_function_pointers.h>
31+
#include <goto-programs/remove_virtual_functions.h>
32+
#include <goto-programs/remove_instanceof.h>
2833
#include <goto-programs/remove_returns.h>
34+
#include <goto-programs/remove_exceptions.h>
2935
#include <goto-programs/remove_vector.h>
3036
#include <goto-programs/remove_complex.h>
3137
#include <goto-programs/remove_asm.h>
3238
#include <goto-programs/remove_unused_functions.h>
39+
#include <goto-programs/remove_skip.h>
3340
#include <goto-programs/goto_inline.h>
3441
#include <goto-programs/show_properties.h>
3542
#include <goto-programs/set_properties.h>
@@ -39,6 +46,11 @@ Author: Peter Schrammel
3946
#include <goto-programs/loop_ids.h>
4047
#include <goto-programs/link_to_library.h>
4148

49+
#include <goto-symex/rewrite_union.h>
50+
#include <goto-symex/adjust_float_expressions.h>
51+
52+
#include <goto-instrument/cover.h>
53+
4254
#include <pointer-analysis/add_failed_symbols.h>
4355

4456
#include <langapi/mode.h>
@@ -99,7 +111,7 @@ void goto_diff_parse_optionst::get_command_line_options(optionst &options)
99111
options.set_option("show-vcc", true);
100112

101113
if(cmdline.isset("cover"))
102-
options.set_option("cover", cmdline.get_value("cover"));
114+
parse_cover_options(cmdline, options);
103115

104116
if(cmdline.isset("mm"))
105117
options.set_option("mm", cmdline.get_value("mm"));
@@ -122,22 +134,8 @@ void goto_diff_parse_optionst::get_command_line_options(optionst &options)
122134
if(cmdline.isset("cpp11"))
123135
config.cpp.set_cpp11();
124136

125-
if(cmdline.isset("no-simplify"))
126-
options.set_option("simplify", false);
127-
else
128-
options.set_option("simplify", true);
129-
130-
if(cmdline.isset("all-claims") || // will go away
131-
cmdline.isset("all-properties")) // use this one
132-
options.set_option("all-properties", true);
133-
else
134-
options.set_option("all-properties", false);
135-
136-
if(cmdline.isset("unwind"))
137-
options.set_option("unwind", cmdline.get_value("unwind"));
138-
139-
if(cmdline.isset("depth"))
140-
options.set_option("depth", cmdline.get_value("depth"));
137+
// all checks supported by goto_check
138+
PARSE_OPTIONS_GOTO_CHECK(cmdline, options);
141139

142140
if(cmdline.isset("debug-level"))
143141
options.set_option("debug-level", cmdline.get_value("debug-level"));
@@ -308,10 +306,6 @@ int goto_diff_parse_optionst::doit()
308306
cmdline.isset("forward-impact") ||
309307
cmdline.isset("backward-impact"))
310308
{
311-
// Workaround to avoid deps not propagating between return and end_func
312-
remove_returns(goto_model1);
313-
remove_returns(goto_model2);
314-
315309
impact_modet impact_mode=
316310
cmdline.isset("forward-impact") ?
317311
impact_modet::FORWARD :
@@ -393,6 +387,9 @@ int goto_diff_parse_optionst::get_goto_program(
393387
goto_model.goto_functions,
394388
ui_message_handler);
395389

390+
if(process_goto_program(options, goto_model))
391+
return 6;
392+
396393
// if we had a second argument then we will handle it next
397394
if(arg2!="")
398395
cmdline.args[0]=arg2;
@@ -405,46 +402,72 @@ bool goto_diff_parse_optionst::process_goto_program(
405402
const optionst &options,
406403
goto_modelt &goto_model)
407404
{
408-
symbol_tablet &symbol_table = goto_model.symbol_table;
409-
goto_functionst &goto_functions = goto_model.goto_functions;
410-
411405
try
412406
{
413-
namespacet ns(symbol_table);
414-
415407
// Remove inline assembler; this needs to happen before
416408
// adding the library.
417409
remove_asm(goto_model);
418410

419411
// add the library
420-
link_to_library(symbol_table, goto_functions, ui_message_handler);
412+
link_to_library(goto_model, get_message_handler());
421413

422414
// remove function pointers
423-
status() << "Function Pointer Removal" << eom;
415+
status() << "Removal of function pointers and virtual functions" << eom;
424416
remove_function_pointers(
425-
get_message_handler(),
426-
symbol_table,
427-
goto_functions,
428-
cmdline.isset("pointer-check"));
417+
get_message_handler(), goto_model, cmdline.isset("pointer-check"));
418+
419+
// Java virtual functions -> explicit dispatch tables:
420+
remove_virtual_functions(goto_model);
421+
// remove catch and throw
422+
remove_exceptions(goto_model);
423+
// Java instanceof -> clsid comparison:
424+
remove_instanceof(goto_model);
429425

430-
// do partial inlining
431-
status() << "Partial Inlining" << eom;
432-
goto_partial_inline(goto_functions, ns, ui_message_handler);
426+
mm_io(goto_model);
427+
428+
// instrument library preconditions
429+
instrument_preconditions(goto_model);
433430

434431
// remove returns, gcc vectors, complex
435-
remove_returns(symbol_table, goto_functions);
436-
remove_vector(symbol_table, goto_functions);
437-
remove_complex(symbol_table, goto_functions);
432+
remove_returns(goto_model);
433+
remove_vector(goto_model);
434+
remove_complex(goto_model);
435+
rewrite_union(goto_model);
436+
437+
// add generic checks
438+
status() << "Generic Property Instrumentation" << eom;
439+
goto_check(options, goto_model);
438440

439-
// add failed symbols
440-
// needs to be done before pointer analysis
441-
add_failed_symbols(symbol_table);
441+
// checks don't know about adjusted float expressions
442+
adjust_float_expressions(goto_model);
442443

443444
// recalculate numbers, etc.
444-
goto_functions.update();
445+
goto_model.goto_functions.update();
445446

446447
// add loop ids
447-
goto_functions.compute_loop_numbers();
448+
goto_model.goto_functions.compute_loop_numbers();
449+
450+
// remove skips such that trivial GOTOs are deleted and not considered
451+
// for coverage annotation:
452+
remove_skip(goto_model);
453+
454+
// instrument cover goals
455+
if(cmdline.isset("cover"))
456+
{
457+
if(instrument_cover_goals(options, goto_model, get_message_handler()))
458+
return true;
459+
}
460+
461+
// label the assertions
462+
// This must be done after adding assertions and
463+
// before using the argument of the "property" option.
464+
// Do not re-label after using the property slicer because
465+
// this would cause the property identifiers to change.
466+
label_properties(goto_model);
467+
468+
// remove any skips introduced since coverage instrumentation
469+
remove_skip(goto_model);
470+
goto_model.goto_functions.update();
448471
}
449472

450473
catch(const char *e)
@@ -459,14 +482,16 @@ bool goto_diff_parse_optionst::process_goto_program(
459482
return true;
460483
}
461484

462-
catch(int)
485+
catch(int e)
463486
{
487+
error() << "Numeric exception: " << e << eom;
464488
return true;
465489
}
466490

467491
catch(const std::bad_alloc &)
468492
{
469493
error() << "Out of memory" << eom;
494+
exit(CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY);
470495
return true;
471496
}
472497

@@ -476,6 +501,7 @@ bool goto_diff_parse_optionst::process_goto_program(
476501
/// display command line help
477502
void goto_diff_parse_optionst::help()
478503
{
504+
// clang-format off
479505
std::cout <<
480506
"\n"
481507
// NOLINTNEXTLINE(whitespace/line_length)
@@ -498,9 +524,15 @@ void goto_diff_parse_optionst::help()
498524
" --backward-impact output unified diff with forward&backward/forward/backward dependencies\n"
499525
" --compact-output output dependencies in compact mode\n"
500526
"\n"
527+
"Program instrumentation options:\n"
528+
HELP_GOTO_CHECK
529+
" --cover CC create test-suite with coverage criterion CC\n" // NOLINT(*)
530+
"Java Bytecode frontend options:\n"
531+
JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP
501532
"Other options:\n"
502533
" --version show version and exit\n"
503534
" --json-ui use JSON-formatted output\n"
504535
HELP_TIMESTAMP
505536
"\n";
537+
// clang-format on
506538
}

src/goto-diff/goto_diff_parse_options.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Author: Peter Schrammel
1212
#ifndef CPROVER_GOTO_DIFF_GOTO_DIFF_PARSE_OPTIONS_H
1313
#define CPROVER_GOTO_DIFF_GOTO_DIFF_PARSE_OPTIONS_H
1414

15+
#include <analyses/goto_check.h>
16+
1517
#include <util/ui_message.h>
1618
#include <util/parse_options.h>
1719
#include <util/timestamper.h>
@@ -24,13 +26,17 @@ Author: Peter Schrammel
2426
class goto_modelt;
2527
class optionst;
2628

29+
// clang-format off
2730
#define GOTO_DIFF_OPTIONS \
2831
"(json-ui)" \
2932
OPT_SHOW_GOTO_FUNCTIONS \
33+
OPT_GOTO_CHECK \
34+
"(cover):" \
3035
"(verbosity):(version)" \
3136
OPT_TIMESTAMP \
3237
"u(unified)(change-impact)(forward-impact)(backward-impact)" \
3338
"(compact-output)"
39+
// clang-format on
3440

3541
class goto_diff_parse_optionst:
3642
public parse_options_baset,

0 commit comments

Comments
 (0)