Skip to content

Commit 2470950

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 11c14c9 commit 2470950

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
@@ -24,6 +24,7 @@ Author: Daniel Kroening, [email protected]
2424
#include <ansi-c/c_preprocess.h>
2525

2626
#include <goto-programs/goto_convert_functions.h>
27+
#include <goto-programs/string_refine_preprocess.h>
2728
#include <goto-programs/remove_function_pointers.h>
2829
#include <goto-programs/remove_virtual_functions.h>
2930
#include <goto-programs/remove_instanceof.h>
@@ -288,6 +289,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
288289
options.set_option("refine-arithmetic", true);
289290
}
290291

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

822+
823+
if(cmdline.isset("string-refine"))
824+
{
825+
status() << "Preprocessing for string refinement" << eom;
826+
string_refine_preprocesst(
827+
symbol_table, goto_functions, ui_message_handler);
828+
}
829+
816830
// remove returns, gcc vectors, complex
817831
remove_returns(symbol_table, goto_functions);
818832
remove_vector(symbol_table, goto_functions);
@@ -1072,6 +1086,10 @@ void cbmc_parse_optionst::help()
10721086
" --yices use Yices\n"
10731087
" --z3 use Z3\n"
10741088
" --refine use refinement procedure (experimental)\n"
1089+
" --refine-strings use string refinement (experimental)\n"
1090+
" --string-non-empty add constraint that strings are non empty (experimental)\n" // NOLINT(*)
1091+
" --string-printable add constraint that strings are printable (experimental)\n" // NOLINT(*)
1092+
" --string-max-length add constraint on the length of strings (experimental)\n" // NOLINT(*)
10751093
" --outfile filename output formula to given file\n"
10761094
" --arrays-uf-never never turn arrays into uninterpreted functions\n" // NOLINT(*)
10771095
" --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
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717

1818
#include <solvers/sat/satcheck.h>
1919
#include <solvers/refinement/bv_refinement.h>
20+
#include <solvers/refinement/string_refinement.h>
2021
#include <solvers/smt1/smt1_dec.h>
2122
#include <solvers/smt2/smt2_dec.h>
2223
#include <solvers/cvc/cvc_dec.h>
@@ -159,6 +160,21 @@ cbmc_solverst::solvert* cbmc_solverst::get_bv_refinement()
159160
return new solvert(bv_refinement, prop);
160161
}
161162

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