Skip to content

Commit 1daae6f

Browse files
romainbrenguiertautschnig
authored andcommitted
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 37cd025 commit 1daae6f

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

src/cbmc/cbmc_parse_options.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Author: Daniel Kroening, [email protected]
2626
#include <ansi-c/c_preprocess.h>
2727

2828
#include <goto-programs/goto_convert_functions.h>
29+
#include <goto-programs/string_refine_preprocess.h>
2930
#include <goto-programs/remove_function_pointers.h>
3031
#include <goto-programs/remove_virtual_functions.h>
3132
#include <goto-programs/remove_instanceof.h>
@@ -289,6 +290,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
289290
options.set_option("refine-arithmetic", true);
290291
}
291292

293+
if(cmdline.isset("string-refine"))
294+
{
295+
options.set_option("string-refine", true);
296+
}
297+
292298
if(cmdline.isset("max-node-refinement"))
293299
options.set_option(
294300
"max-node-refinement",
@@ -814,6 +820,14 @@ bool cbmc_parse_optionst::process_goto_program(
814820
status() << "Partial Inlining" << eom;
815821
goto_partial_inline(goto_functions, ns, ui_message_handler);
816822

823+
824+
if(cmdline.isset("string-refine"))
825+
{
826+
status() << "Preprocessing for string refinement" << eom;
827+
string_refine_preprocesst(
828+
symbol_table, goto_functions, ui_message_handler);
829+
}
830+
817831
// remove returns, gcc vectors, complex
818832
remove_returns(symbol_table, goto_functions);
819833
remove_vector(symbol_table, goto_functions);
@@ -1073,6 +1087,10 @@ void cbmc_parse_optionst::help()
10731087
" --yices use Yices\n"
10741088
" --z3 use Z3\n"
10751089
" --refine use refinement procedure (experimental)\n"
1090+
" --refine-strings use string refinement (experimental)\n"
1091+
" --string-non-empty add constraint that strings are non empty (experimental)\n" // NOLINT(*)
1092+
" --string-printable add constraint that strings are printable (experimental)\n" // NOLINT(*)
1093+
" --string-max-length add constraint on the length of strings (experimental)\n" // NOLINT(*)
10761094
" --outfile filename output formula to given file\n"
10771095
" --arrays-uf-never never turn arrays into uninterpreted functions\n" // NOLINT(*)
10781096
" --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
@@ -41,6 +41,7 @@ class optionst;
4141
"(no-sat-preprocessor)" \
4242
"(no-pretty-names)(beautify)" \
4343
"(dimacs)(refine)(max-node-refinement):(refine-arrays)(refine-arithmetic)"\
44+
"(string-refine)" \
4445
"(aig)(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \
4546
"(little-endian)(big-endian)" \
4647
"(show-goto-functions)(show-loops)" \

src/cbmc/cbmc_solvers.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Author: Daniel Kroening, [email protected]
1919

2020
#include <solvers/sat/satcheck.h>
2121
#include <solvers/refinement/bv_refinement.h>
22+
#include <solvers/refinement/string_refinement.h>
2223
#include <solvers/smt1/smt1_dec.h>
2324
#include <solvers/smt2/smt2_dec.h>
2425
#include <solvers/cvc/cvc_dec.h>
@@ -160,6 +161,21 @@ cbmc_solverst::solvert* cbmc_solverst::get_bv_refinement()
160161
return new solvert(bv_refinement, prop);
161162
}
162163

164+
/// the string refinement adds to the bit vector refinement specifications for
165+
/// functions from the Java string library
166+
/// \return a solver for cbmc
167+
cbmc_solverst::solvert* cbmc_solverst::get_string_refinement()
168+
{
169+
propt *prop;
170+
prop=new satcheck_no_simplifiert();
171+
prop->set_message_handler(get_message_handler());
172+
173+
string_refinementt *string_refinement=new string_refinementt(
174+
ns, *prop, MAX_NB_REFINEMENT);
175+
string_refinement->set_ui(ui);
176+
return new solvert(string_refinement, prop);
177+
}
178+
163179
cbmc_solverst::solvert* cbmc_solverst::get_smt1(smt1_dect::solvert solver)
164180
{
165181
no_beautification();

src/cbmc/cbmc_solvers.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,17 @@ class cbmc_solverst:public messaget
108108
solvert *solver;
109109

110110
if(options.get_bool_option("dimacs"))
111-
solver = get_dimacs();
111+
solver=get_dimacs();
112112
else if(options.get_bool_option("refine"))
113-
solver = get_bv_refinement();
113+
solver=get_bv_refinement();
114+
else if(options.get_bool_option("string-refine"))
115+
solver=get_string_refinement();
114116
else if(options.get_bool_option("smt1"))
115-
solver = get_smt1(get_smt1_solver_type());
117+
solver=get_smt1(get_smt1_solver_type());
116118
else if(options.get_bool_option("smt2"))
117-
solver = get_smt2(get_smt2_solver_type());
119+
solver=get_smt2(get_smt2_solver_type());
118120
else
119-
solver = get_default();
121+
solver=get_default();
120122

121123
return std::unique_ptr<solvert>(solver);
122124
}
@@ -138,6 +140,7 @@ class cbmc_solverst:public messaget
138140
solvert *get_default();
139141
solvert *get_dimacs();
140142
solvert *get_bv_refinement();
143+
solvert *get_string_refinement();
141144
solvert *get_smt1(smt1_dect::solvert solver);
142145
solvert *get_smt2(smt2_dect::solvert solver);
143146

0 commit comments

Comments
 (0)