Skip to content

Commit 8dc7ef2

Browse files
author
Enrico Steffinlongo
authored
Merge pull request #7697 from NlightNFotis/extract_core_goto
Add capability to export goto-program in symex-ready-goto form to CBMC.
2 parents cfcfcf6 + 1e26b7f commit 8dc7ef2

File tree

10 files changed

+114
-36
lines changed

10 files changed

+114
-36
lines changed

doc/ADR/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ where taken at the time they were, so that future maintainers
66
can more easily identify constraints that shaped the architecture
77
of the system and the surrounding infrastructure.
88

9-
## Core goto form
10-
\subpage core-goto
9+
## Symex ready goto form
10+
\subpage symex-ready-goto
1111

1212
## Release & Packaging
1313

doc/ADR/core_goto.md renamed to doc/ADR/symex_ready_goto.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
\page core-goto Core goto definition
1+
\page symex-ready-goto Symex ready goto definition
22

33
During the analysis of a program CBMC transforms the input program in an intermediate language
44
called extended goto. Then the tool performs a series of simplifications on the obtained goto
55
program until the program is given to the solver.
66

7-
We say that a program is in the **core goto form** when all the extended goto features have
7+
We say that a program is in the **symex ready goto form** when all the extended goto features have
88
been simplified.
99

10-
More specifically, a program that is in **core goto form** is one that can be passed to **symex** by
10+
More specifically, a program that is in **symex ready goto form** is one that can be passed to **symex** by
1111
using any solver deriving from `goto_verifiert` without requiring any lowering step.
1212

1313
At the time of writing, verifiers extending `goto_verifiert` are:

doc/architectural/goto-program-transformations.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
\section required-transforms Core Transformation Passes
66

77
This section lists the transformation passes that must have been applied for the
8-
goto model to be in core goto format.
8+
goto model to be in symex ready goto format.
99

1010
Note that the passes are listed below in the order they are currently called in
1111
CBMC. While all dependencies on the ordering are not fully documented, the
@@ -184,11 +184,11 @@ nondet-transform if it is being used.</em>
184184

185185
This transformation removes skip instructions. Note that this transformation is
186186
called in many places and may be called as part of other transformations. This
187-
instance here is part of the mandatory transformation to reach core goto format.
188-
If there is a use case where it is desirable to preserve a "no operation"
189-
instruction, a `LOCATION` type instruction may be used in place of a `SKIP`
190-
instruction. The `LOCATION` instruction has the same semantics as the `SKIP`
191-
instruction, but is not removed by the remove skip instructions pass.
187+
instance here is part of the mandatory transformation to reach symex ready goto
188+
format. If there is a use case where it is desirable to preserve a "no
189+
operation" instruction, a `LOCATION` type instruction may be used in place of a
190+
`SKIP` instruction. The `LOCATION` instruction has the same semantics as the
191+
`SKIP` instruction, but is not removed by the remove skip instructions pass.
192192

193193
The implementation of this pass is called via \ref remove_skip(goto_modelt &)
194194

@@ -215,7 +215,7 @@ coverage-transform if it is being used.</em>
215215

216216
The sections lists the optional transformation passes that are optional and will
217217
modify a goto model. Note that these are documented here for consistency, but
218-
not required for core goto format.
218+
not required for symex ready goto format.
219219

220220
Note for each optional pass there is a listed predeceesor pass. This is the pass
221221
currently called before the listed pass in CBMC. While the ordering may not be

doc/man/cbmc.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ give a stack trace only
525525
\fB\-\-flush\fR
526526
flush every line of output
527527
.TP
528+
\fB\-\-export\-symex\-ready\-goto\fR filename
529+
export the symex ready version of the goto-model into the given filename
530+
.TP
528531
\fB\-\-verbosity\fR #
529532
verbosity level
530533
.TP

regression/cbmc/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
22
set(gcc_only -X gcc-only)
33
set(gcc_only_string "-X;gcc-only;")
4+
set(exclude_win_broken_tests -X winbug)
5+
# We add the string at the end of the exclusion list, so it must not
6+
# have the `;` at the end or it bugs out.
7+
set(exclude_win_broken_tests_string "-X;winbug")
48
else()
59
set(gcc_only "")
610
set(gcc_only_string "")
11+
set(exclude_win_broken_tests "")
12+
set(exclude_win_broken_tests_string "")
713
endif()
814

915
add_test_pl_tests(
10-
"$<TARGET_FILE:cbmc> --validate-goto-model --validate-ssa-equation" -X smt-backend ${gcc_only}
16+
"$<TARGET_FILE:cbmc> --validate-goto-model --validate-ssa-equation" -X smt-backend ${gcc_only} ${exclude_win_broken_tests}
1117
)
1218

1319
add_test_pl_profile(
1420
"cbmc-paths-lifo"
1521
"$<TARGET_FILE:cbmc> --paths lifo"
16-
"-C;-X;thorough-paths;-X;smt-backend;-X;paths-lifo-expected-failure;${gcc_only_string}-s;paths-lifo"
22+
"-C;-X;thorough-paths;-X;smt-backend;-X;paths-lifo-expected-failure;${gcc_only_string}-s;paths-lifo;${exclude_win_broken_tests_string}"
1723
"CORE"
1824
)
1925

2026
add_test_pl_profile(
2127
"cbmc-cprover-smt2"
2228
"$<TARGET_FILE:cbmc> --cprover-smt2"
23-
"-C;-X;broken-smt-backend;-X;thorough-smt-backend;-X;broken-cprover-smt-backend;-X;thorough-cprover-smt-backend;${gcc_only_string}-s;cprover-smt2"
29+
"-C;-X;broken-smt-backend;-X;thorough-smt-backend;-X;broken-cprover-smt-backend;-X;thorough-cprover-smt-backend;${gcc_only_string}-s;cprover-smt2;${exclude_win_broken_tests_string}"
2430
"CORE"
2531
)
2632

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE winbug
2+
test.c
3+
--export-symex-ready-goto ""
4+
^ERROR: Please provide a filename to write the goto-binary to.$
5+
^EXIT=6$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Ensure that --export-symex-ready-goto exported.symex-ready.goto terminates
10+
with error when incorrectly used.
11+
12+
The reason why we use `winbug` is that it fails on certain windows system
13+
probably due to different interpretation of "". Not a bug, but we're using
14+
that label to remain consistent with other parts of the codebase, and not
15+
to unnecessarily introduce new ones for simple use cases.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE
2+
test.c
3+
--export-symex-ready-goto exported.symex.ready.goto
4+
^Parsing test.c$
5+
^Converting$
6+
^Type-checking test$
7+
^Generating GOTO Program$
8+
^Removal of function pointers and virtual functions$
9+
^Generic Property Instrumentation$
10+
Exported goto-program in symex-ready-goto form at exported.symex.ready.goto
11+
^EXIT=0$
12+
^SIGNAL=0$
13+
--
14+
--
15+
Ensure that --export-symex-ready-goto exported.symex.ready.goto terminates successfully and logs this.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int main(int argc, char **argv)
2+
{
3+
int arr[] = {0, 1, 2, 3, 4};
4+
__CPROVER_assert(arr[0] == 1, "expected failure: 0 != 1");
5+
return 0;
6+
}

src/cbmc/cbmc_parse_options.cpp

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,24 @@ Author: Daniel Kroening, [email protected]
2626
# include <util/unicode.h>
2727
#endif
2828

29-
#include <langapi/language.h>
29+
#include <goto-programs/initialize_goto_model.h>
30+
#include <goto-programs/link_to_library.h>
31+
#include <goto-programs/loop_ids.h>
32+
#include <goto-programs/process_goto_program.h>
33+
#include <goto-programs/read_goto_binary.h>
34+
#include <goto-programs/remove_skip.h>
35+
#include <goto-programs/remove_unused_functions.h>
36+
#include <goto-programs/set_properties.h>
37+
#include <goto-programs/show_goto_functions.h>
38+
#include <goto-programs/show_properties.h>
39+
#include <goto-programs/show_symbol_table.h>
40+
#include <goto-programs/write_goto_binary.h>
3041

3142
#include <ansi-c/c_preprocess.h>
3243
#include <ansi-c/cprover_library.h>
3344
#include <ansi-c/gcc_version.h>
34-
3545
#include <assembler/remove_asm.h>
36-
3746
#include <cpp/cprover_library.h>
38-
3947
#include <goto-checker/all_properties_verifier.h>
4048
#include <goto-checker/all_properties_verifier_with_fault_localization.h>
4149
#include <goto-checker/all_properties_verifier_with_trace_storage.h>
@@ -49,29 +57,14 @@ Author: Daniel Kroening, [email protected]
4957
#include <goto-checker/single_path_symex_only_checker.h>
5058
#include <goto-checker/stop_on_fail_verifier.h>
5159
#include <goto-checker/stop_on_fail_verifier_with_fault_localization.h>
52-
53-
#include <goto-programs/initialize_goto_model.h>
54-
#include <goto-programs/link_to_library.h>
55-
#include <goto-programs/loop_ids.h>
56-
#include <goto-programs/process_goto_program.h>
57-
#include <goto-programs/read_goto_binary.h>
58-
#include <goto-programs/remove_skip.h>
59-
#include <goto-programs/remove_unused_functions.h>
60-
#include <goto-programs/set_properties.h>
61-
#include <goto-programs/show_goto_functions.h>
62-
#include <goto-programs/show_properties.h>
63-
#include <goto-programs/show_symbol_table.h>
64-
6560
#include <goto-instrument/cover.h>
6661
#include <goto-instrument/full_slicer.h>
6762
#include <goto-instrument/nondet_static.h>
6863
#include <goto-instrument/reachability_slicer.h>
69-
7064
#include <goto-symex/path_storage.h>
71-
72-
#include <pointer-analysis/add_failed_symbols.h>
73-
65+
#include <langapi/language.h>
7466
#include <langapi/mode.h>
67+
#include <pointer-analysis/add_failed_symbols.h>
7568

7669
#include "c_test_input_generator.h"
7770

@@ -252,6 +245,19 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
252245
options.set_option("trace", true);
253246
}
254247

248+
if(cmdline.isset("export-symex-ready-goto"))
249+
{
250+
options.set_option(
251+
"export-symex-ready-goto", cmdline.get_value("export-symex-ready-goto"));
252+
if(options.get_option("export-symex-ready-goto").empty())
253+
{
254+
log.error()
255+
<< "ERROR: Please provide a filename to write the goto-binary to."
256+
<< messaget::eom;
257+
exit(CPROVER_EXIT_INTERNAL_ERROR);
258+
}
259+
}
260+
255261
if(cmdline.isset("localize-faults"))
256262
options.set_option("localize-faults", true);
257263

@@ -553,6 +559,31 @@ int cbmc_parse_optionst::doit()
553559
if(set_properties())
554560
return CPROVER_EXIT_SET_PROPERTIES_FAILED;
555561

562+
// At this point, our goto-model should be in symex-ready-goto form (all of
563+
// the transformations have been run and the program is ready to be given
564+
// to the solver).
565+
if(options.is_set("export-symex-ready-goto"))
566+
{
567+
auto symex_ready_goto_filename =
568+
options.get_option("export-symex-ready-goto");
569+
570+
bool success = !write_goto_binary(
571+
symex_ready_goto_filename, goto_model, ui_message_handler);
572+
573+
if(!success)
574+
{
575+
log.error() << "ERROR: Unable to export goto-program in file "
576+
<< symex_ready_goto_filename << messaget::eom;
577+
return CPROVER_EXIT_INTERNAL_ERROR;
578+
}
579+
else
580+
{
581+
log.status() << "Exported goto-program in symex-ready-goto form at "
582+
<< symex_ready_goto_filename << messaget::eom;
583+
return CPROVER_EXIT_SUCCESS;
584+
}
585+
}
586+
556587
if(
557588
options.get_bool_option("program-only") ||
558589
options.get_bool_option("show-vcc") ||
@@ -937,6 +968,7 @@ void cbmc_parse_optionst::help()
937968
" --show-symbol-table show loaded symbol table\n"
938969
HELP_SHOW_GOTO_FUNCTIONS
939970
HELP_VALIDATE
971+
" --export-symex-ready-goto f serialise goto-program in symex-ready-goto form in f\n" // NOLINT(*)
940972
"\n"
941973
"Program instrumentation options:\n"
942974
HELP_GOTO_CHECK

src/cbmc/cbmc_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class optionst;
5959
"(verbosity):(no-library)" \
6060
"(nondet-static)" \
6161
"(version)" \
62+
"(export-symex-ready-goto):" \
6263
OPT_COVER \
6364
"(symex-coverage-report):" \
6465
"(mm):" \

0 commit comments

Comments
 (0)