Skip to content

Commit c7328e2

Browse files
romainbrenguierJoel Allred
authored and
Joel Allred
committed
Adding the string refinement option to the CBMC solvers
We add the option `--string-refine` which can be used to activate the string solver, in order to deal precisely with string functions.
1 parent 0558291 commit c7328e2

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

src/cbmc/cbmc_parse_options.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include <ansi-c/c_preprocess.h>
2121

2222
#include <goto-programs/goto_convert_functions.h>
23+
#include <goto-programs/string_refine_preprocess.h>
2324
#include <goto-programs/remove_function_pointers.h>
2425
#include <goto-programs/remove_virtual_functions.h>
2526
#include <goto-programs/remove_instanceof.h>
@@ -310,6 +311,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
310311
options.set_option("refine-arithmetic", true);
311312
}
312313

314+
if(cmdline.isset("string-refine"))
315+
{
316+
options.set_option("string-refine", true);
317+
}
318+
313319
if(cmdline.isset("max-node-refinement"))
314320
options.set_option(
315321
"max-node-refinement",
@@ -904,6 +910,14 @@ bool cbmc_parse_optionst::process_goto_program(
904910
status() << "Partial Inlining" << eom;
905911
goto_partial_inline(goto_functions, ns, ui_message_handler);
906912

913+
914+
if(cmdline.isset("string-refine"))
915+
{
916+
status() << "Preprocessing for string refinement" << eom;
917+
string_refine_preprocesst(
918+
symbol_table, goto_functions, ui_message_handler);
919+
}
920+
907921
// remove returns, gcc vectors, complex
908922
remove_returns(symbol_table, goto_functions);
909923
remove_vector(symbol_table, goto_functions);
@@ -1191,6 +1205,7 @@ void cbmc_parse_optionst::help()
11911205
" --yices use Yices\n"
11921206
" --z3 use Z3\n"
11931207
" --refine use refinement procedure (experimental)\n"
1208+
" --string-refine use string refinement (experimental)\n"
11941209
" --outfile filename output formula to given file\n"
11951210
" --arrays-uf-never never turn arrays into uninterpreted functions\n" // NOLINT(*)
11961211
" --arrays-uf-always always turn arrays into uninterpreted functions\n" // NOLINT(*)

src/cbmc/cbmc_parse_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class optionst;
3737
"(no-sat-preprocessor)" \
3838
"(no-pretty-names)(beautify)" \
3939
"(dimacs)(refine)(max-node-refinement):(refine-arrays)(refine-arithmetic)"\
40+
"(string-refine)" \
4041
"(aig)(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \
4142
"(little-endian)(big-endian)" \
4243
"(show-goto-functions)(show-loops)" \

src/cbmc/cbmc_solvers.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <solvers/sat/satcheck.h>
1616
#include <solvers/refinement/bv_refinement.h>
17+
#include <solvers/refinement/string_refinement.h>
1718
#include <solvers/smt1/smt1_dec.h>
1819
#include <solvers/smt2/smt2_dec.h>
1920
#include <solvers/cvc/cvc_dec.h>
@@ -213,6 +214,29 @@ cbmc_solverst::solvert* cbmc_solverst::get_bv_refinement()
213214

214215
/*******************************************************************\
215216
217+
Function: cbmc_solverst::get_string_refinement
218+
219+
Outputs: a solver for cbmc
220+
221+
Purpose: the string refinement adds to the bit vector refinement
222+
specifications for functions from the Java string library
223+
224+
\*******************************************************************/
225+
226+
cbmc_solverst::solvert* cbmc_solverst::get_string_refinement()
227+
{
228+
propt *prop;
229+
prop=new satcheck_no_simplifiert();
230+
prop->set_message_handler(get_message_handler());
231+
232+
string_refinementt *string_refinement=new string_refinementt(
233+
ns, *prop, MAX_NB_REFINEMENT);
234+
string_refinement->set_ui(ui);
235+
return new solvert(string_refinement, prop);
236+
}
237+
238+
/*******************************************************************\
239+
216240
Function: cbmc_solverst::get_smt1
217241
218242
Inputs:

src/cbmc/cbmc_solvers.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,17 @@ class cbmc_solverst:public messaget
111111
solvert *solver;
112112

113113
if(options.get_bool_option("dimacs"))
114-
solver = get_dimacs();
114+
solver=get_dimacs();
115115
else if(options.get_bool_option("refine"))
116-
solver = get_bv_refinement();
116+
solver=get_bv_refinement();
117+
else if(options.get_bool_option("string-refine"))
118+
solver=get_string_refinement();
117119
else if(options.get_bool_option("smt1"))
118-
solver = get_smt1(get_smt1_solver_type());
120+
solver=get_smt1(get_smt1_solver_type());
119121
else if(options.get_bool_option("smt2"))
120-
solver = get_smt2(get_smt2_solver_type());
122+
solver=get_smt2(get_smt2_solver_type());
121123
else
122-
solver = get_default();
124+
solver=get_default();
123125

124126
return std::unique_ptr<solvert>(solver);
125127
}
@@ -141,6 +143,7 @@ class cbmc_solverst:public messaget
141143
solvert *get_default();
142144
solvert *get_dimacs();
143145
solvert *get_bv_refinement();
146+
solvert *get_string_refinement();
144147
solvert *get_smt1(smt1_dect::solvert solver);
145148
solvert *get_smt2(smt2_dect::solvert solver);
146149

0 commit comments

Comments
 (0)