Skip to content

Commit 1824418

Browse files
authored
Merge pull request diffblue#7612 from qinheping/different_solver_in_synthesizer
Enable solver options in goto-synthesizer
2 parents a855f50 + a7f190f commit 1824418

File tree

8 files changed

+165
-41
lines changed

8 files changed

+165
-41
lines changed

doc/man/goto-synthesizer.1

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,98 @@ specify the output destination of the loop-contracts JSON
2929
.TP
3030
\fB\-\-object\-bits\fR n
3131
number of bits used for object addresses
32+
.TP
33+
\fB\-\-sat\-solver\fR solver
34+
use specified SAT solver
35+
.TP
36+
\fB\-\-external\-sat\-solver\fR cmd
37+
command to invoke SAT solver process
38+
.TP
39+
\fB\-\-no\-sat\-preprocessor\fR
40+
disable the SAT solver's simplifier
41+
.TP
42+
\fB\-\-dimacs\fR
43+
generate CNF in DIMACS format
44+
.TP
45+
\fB\-\-beautify\fR
46+
beautify the counterexample
47+
(greedy heuristic)
48+
.TP
49+
\fB\-\-smt1\fR
50+
use default SMT1 solver (obsolete)
51+
.TP
52+
\fB\-\-smt2\fR
53+
use default SMT2 solver (Z3)
54+
.TP
55+
\fB\-\-bitwuzla\fR
56+
use Bitwuzla
57+
.TP
58+
\fB\-\-boolector\fR
59+
use Boolector
60+
.TP
61+
\fB\-\-cprover\-smt2\fR
62+
use CPROVER SMT2 solver
63+
.TP
64+
\fB\-\-cvc3\fR
65+
use CVC3
66+
.TP
67+
\fB\-\-cvc4\fR
68+
use CVC4
69+
.TP
70+
\fB\-\-cvc5\fR
71+
use CVC5
72+
.TP
73+
\fB\-\-mathsat\fR
74+
use MathSAT
75+
.TP
76+
\fB\-\-yices\fR
77+
use Yices
78+
.TP
79+
\fB\-\-z3\fR
80+
use Z3
81+
.TP
82+
\fB\-\-fpa\fR
83+
use theory of floating\-point arithmetic
84+
.TP
85+
\fB\-\-refine\fR
86+
use refinement procedure (experimental)
87+
.TP
88+
\fB\-\-refine\-arrays\fR
89+
use refinement for arrays only
90+
.TP
91+
\fB\-\-refine\-arithmetic\fR
92+
refinement of arithmetic expressions only
93+
.TP
94+
\fB\-\-max\-node\-refinement\fR
95+
maximum refinement iterations for
96+
arithmetic expressions
97+
.TP
98+
\fB\-\-incremental\-smt2\-solver\fR \fIcmd\fR
99+
Use the incremental SMT backend where \fIcmd\fR is the command to invoke the SMT
100+
solver of choice.
101+
.br
102+
Example invocations:
103+
.br
104+
--incremental-smt2-solver 'z3 -smt2 -in' (use the Z3 solver).
105+
.br
106+
--incremental-smt2-solver 'cvc5 --lang=smtlib2.6 --incremental' (use the CVC5 solver).
107+
.sp
108+
Note that:
109+
.br
110+
The solver name must be in the "PATH" or be an executable with full path.
111+
.br
112+
The SMT solver should accept incremental SMTlib v2.6 formatted input from the stdin.
113+
.br
114+
The SMT solver should support the QF_AUFBV logic.
115+
.TP
116+
\fB\-\-outfile\fR filename
117+
output formula to given file
118+
.TP
119+
\fB\-\-dump\-smt\-formula\fR filename
120+
output smt incremental formula to the given file
121+
.TP
122+
\fB\-\-write\-solver\-stats\-to\fR json\-file
123+
collect the solver query complexity
32124
.SS "User-interface options:"
33125
.TP
34126
\fB\-\-xml\-ui\fR
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--pointer-check _ --sat-solver cadical --verbosity 10
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
Solving with CaDiCaL|The specified solver, 'cadical', is not available. The default solver will be used instead.
7+
^\[main.pointer\_dereference.\d+\] .* SUCCESS$
8+
^VERIFICATION SUCCESSFUL$
9+
--
10+
--
11+
Check if solver options can be correctly parsed.

src/goto-synthesizer/cegis_verifier.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -81,32 +81,8 @@ get_checked_pointer_from_null_pointer_check(const exprt &violation)
8181
UNREACHABLE;
8282
}
8383

84-
optionst cegis_verifiert::get_options()
84+
void cegis_verifiert::preprocess_goto_model()
8585
{
86-
optionst options;
87-
88-
// Default options
89-
// These options are the same as we run CBMC without any set flag.
90-
options.set_option("built-in-assertions", true);
91-
options.set_option("propagation", true);
92-
options.set_option("simple-slice", true);
93-
options.set_option("simplify", true);
94-
options.set_option("show-goto-symex-steps", false);
95-
options.set_option("show-points-to-sets", false);
96-
options.set_option("show-array-constraints", false);
97-
options.set_option("built-in-assertions", true);
98-
options.set_option("assertions", true);
99-
options.set_option("assumptions", true);
100-
options.set_option("arrays-uf", "auto");
101-
options.set_option("depth", UINT32_MAX);
102-
options.set_option("exploration-strategy", "lifo");
103-
options.set_option("symex-cache-dereferences", false);
104-
options.set_option("rewrite-union", true);
105-
options.set_option("self-loops-to-assumptions", true);
106-
107-
// Generating trace for counterexamples.
108-
options.set_option("trace", true);
109-
11086
// Preprocess `goto_model`. Copied from `cbmc_parse_options.cpp`.
11187
remove_asm(goto_model);
11288
link_to_library(
@@ -119,7 +95,6 @@ optionst cegis_verifiert::get_options()
11995

12096
remove_skip(goto_model);
12197
label_properties(goto_model);
122-
return options;
12398
}
12499

125100
cext::violation_typet
@@ -203,7 +178,6 @@ std::list<loop_idt> cegis_verifiert::get_cause_loop_id(
203178
std::list<loop_idt> result;
204179

205180
// build the dependence graph
206-
const namespacet ns(goto_model.symbol_table);
207181
dependence_grapht dependence_graph(ns);
208182
dependence_graph(goto_model);
209183

@@ -382,8 +356,6 @@ cext cegis_verifiert::build_cex(
382356
const goto_tracet &goto_trace,
383357
const source_locationt &loop_entry_loc)
384358
{
385-
const namespacet ns(goto_model.symbol_table);
386-
387359
// Valuations of havoced variables right after havoc instructions.
388360
std::unordered_map<exprt, mp_integer, irep_hash> object_sizes;
389361
std::unordered_map<exprt, mp_integer, irep_hash> havoced_values;
@@ -588,8 +560,6 @@ optionalt<cext> cegis_verifiert::verify()
588560
// 3. construct the formatted counterexample from the violated property and
589561
// its trace.
590562

591-
const namespacet ns(goto_model.symbol_table);
592-
593563
// Store the original functions. We will restore them after the verification.
594564
for(const auto &fun_entry : goto_model.goto_functions.function_map)
595565
{
@@ -618,7 +588,7 @@ optionalt<cext> cegis_verifiert::verify()
618588
// Get the checker same as CBMC api without any flag.
619589
// TODO: replace the checker with CBMC api once it is implemented.
620590
ui_message_handlert ui_message_handler(log.get_message_handler());
621-
const auto options = get_options();
591+
preprocess_goto_model();
622592
std::unique_ptr<
623593
all_properties_verifier_with_trace_storaget<multi_path_symex_checkert>>
624594
checker = util_make_unique<

src/goto-synthesizer/cegis_verifier.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ class cegis_verifiert
103103
const invariant_mapt &invariant_candidates,
104104
const std::map<loop_idt, std::set<exprt>> &assigns_map,
105105
goto_modelt &goto_model,
106+
const optionst &options,
106107
messaget &log)
107108
: invariant_candidates(invariant_candidates),
108109
assigns_map(assigns_map),
109110
goto_model(goto_model),
110-
log(log)
111+
options(options),
112+
log(log),
113+
ns(goto_model.symbol_table)
111114
{
112115
}
113116

@@ -120,11 +123,6 @@ class cegis_verifiert
120123
irep_idt target_violation_id;
121124

122125
protected:
123-
// Get the options same as using CBMC api without any flag, and
124-
// preprocess `goto_model`.
125-
// TODO: replace the checker with CBMC api once it is implemented.
126-
optionst get_options();
127-
128126
// Compute the cause loops of `violation`.
129127
// We say a loop is the cause loop if the violated predicate is dependent
130128
// upon the write set of the loop.
@@ -168,10 +166,15 @@ class cegis_verifiert
168166
const goto_functiont &function,
169167
unsigned location_number_of_target);
170168

169+
/// Preprocess the goto model to prepare for verification.
170+
void preprocess_goto_model();
171+
171172
const invariant_mapt &invariant_candidates;
172173
const std::map<loop_idt, std::set<exprt>> &assigns_map;
173174
goto_modelt &goto_model;
175+
const optionst &options;
174176
messaget log;
177+
const namespacet ns;
175178

176179
/// Map from function names to original functions. It is used to
177180
/// restore functions with annotated loops to original functions.

src/goto-synthesizer/enumerative_loop_contracts_synthesizer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ exprt enumerative_loop_contracts_synthesizert::synthesize_strengthening_clause(
334334

335335
// The verifier we use to check current invariant candidates.
336336
cegis_verifiert verifier(
337-
combined_invariant, assigns_map, goto_model, log);
337+
combined_invariant, assigns_map, goto_model, options, log);
338338

339339
// A good strengthening clause if
340340
// 1. all checks pass, or
@@ -367,7 +367,8 @@ invariant_mapt enumerative_loop_contracts_synthesizert::synthesize_all()
367367
in_invariant_clause_map, pos_invariant_clause_map, neg_guards);
368368

369369
// The verifier we use to check current invariant candidates.
370-
cegis_verifiert verifier(combined_invariant, assigns_map, goto_model, log);
370+
cegis_verifiert verifier(
371+
combined_invariant, assigns_map, goto_model, options, log);
371372

372373
// Set of symbols the violation may be dependent on.
373374
// We enumerate strengthening clauses built from symbols from the set.

src/goto-synthesizer/enumerative_loop_contracts_synthesizer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Author: Qinheping Hu
1414
// NOLINTNEXTLINE(whitespace/line_length)
1515
#define CPROVER_GOTO_SYNTHESIZER_ENUMERATIVE_LOOP_CONTRACTS_SYNTHESIZER_H
1616

17+
#include <util/options.h>
18+
1719
#include "loop_contracts_synthesizer_base.h"
1820

1921
class messaget;
@@ -30,8 +32,10 @@ class enumerative_loop_contracts_synthesizert
3032
public:
3133
enumerative_loop_contracts_synthesizert(
3234
goto_modelt &goto_model,
35+
const optionst &options,
3336
messaget &log)
3437
: loop_contracts_synthesizer_baset(goto_model, log),
38+
options(options),
3539
ns(goto_model.symbol_table)
3640
{
3741
}
@@ -46,6 +50,7 @@ class enumerative_loop_contracts_synthesizert
4650
return assigns_map;
4751
}
4852

53+
const optionst &options;
4954
namespacet ns;
5055

5156
private:

src/goto-synthesizer/goto_synthesizer_parse_options.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ int goto_synthesizer_parse_optionst::doit()
6060
configure_gcc(gcc_version);
6161
}
6262

63+
// Get options and preprocess `goto_model`.
64+
const auto &options = get_options();
65+
6366
// Synthesize loop invariants and annotate them into `goto_model`
64-
enumerative_loop_contracts_synthesizert synthesizer(goto_model, log);
67+
enumerative_loop_contracts_synthesizert synthesizer(goto_model, options, log);
6568
const auto &invariant_map = synthesizer.synthesize_all();
6669
const auto &assigns_map = synthesizer.get_assigns_map();
6770

@@ -176,6 +179,37 @@ int goto_synthesizer_parse_optionst::get_goto_program()
176179
return CPROVER_EXIT_SUCCESS;
177180
}
178181

182+
optionst goto_synthesizer_parse_optionst::get_options()
183+
{
184+
optionst options;
185+
186+
// Default options
187+
// These options are the same as we run CBMC without any set flag.
188+
options.set_option("built-in-assertions", true);
189+
options.set_option("propagation", true);
190+
options.set_option("simple-slice", true);
191+
options.set_option("simplify", true);
192+
options.set_option("show-goto-symex-steps", false);
193+
options.set_option("show-points-to-sets", false);
194+
options.set_option("show-array-constraints", false);
195+
options.set_option("built-in-assertions", true);
196+
options.set_option("assertions", true);
197+
options.set_option("assumptions", true);
198+
options.set_option("arrays-uf", "auto");
199+
options.set_option("depth", UINT32_MAX);
200+
options.set_option("exploration-strategy", "lifo");
201+
options.set_option("symex-cache-dereferences", false);
202+
options.set_option("rewrite-union", true);
203+
options.set_option("self-loops-to-assumptions", true);
204+
205+
// Generating trace for counterexamples.
206+
options.set_option("trace", true);
207+
208+
parse_solver_options(cmdline, options);
209+
210+
return options;
211+
}
212+
179213
/// display command line help
180214
void goto_synthesizer_parse_optionst::help()
181215
{
@@ -197,6 +231,7 @@ void goto_synthesizer_parse_optionst::help()
197231
"\n"
198232
"Backend options:\n"
199233
HELP_CONFIG_BACKEND
234+
HELP_SOLVER
200235
"\n"
201236
"Other options:\n"
202237
" --version show version and exit\n"

src/goto-synthesizer/goto_synthesizer_parse_options.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ Author: Qinheping Hu
1010
#define CPROVER_GOTO_SYNTHESIZER_GOTO_SYNTHESIZER_PARSE_OPTIONS_H
1111

1212
#include <util/config.h>
13+
#include <util/options.h>
1314
#include <util/parse_options.h>
1415

1516
#include <goto-programs/goto_model.h>
1617

18+
#include <goto-checker/solver_factory.h>
1719
#include <goto-instrument/contracts/contracts.h>
1820

1921
#include "dump_loop_contracts.h"
@@ -23,6 +25,7 @@ Author: Qinheping Hu
2325
OPT_DUMP_LOOP_CONTRACTS \
2426
"(" FLAG_LOOP_CONTRACTS_NO_UNWIND ")" \
2527
OPT_CONFIG_BACKEND \
28+
OPT_SOLVER \
2629
"(verbosity):(version)(xml-ui)(json-ui)" \
2730
// empty last line
2831

@@ -48,6 +51,10 @@ class goto_synthesizer_parse_optionst : public parse_options_baset
4851

4952
int get_goto_program();
5053

54+
// Get the options same as using CBMC api without any flags and set any
55+
// options specified in the command line.
56+
optionst get_options();
57+
5158
goto_modelt goto_model;
5259
};
5360

0 commit comments

Comments
 (0)