Skip to content

Commit dc9d8e9

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 8ed138f commit dc9d8e9

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>
@@ -268,6 +269,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
268269
options.set_option("refine-arithmetic", true);
269270
}
270271

272+
if(cmdline.isset("string-refine"))
273+
{
274+
options.set_option("string-refine", true);
275+
}
276+
271277
if(cmdline.isset("max-node-refinement"))
272278
options.set_option(
273279
"max-node-refinement",
@@ -808,6 +814,14 @@ bool cbmc_parse_optionst::process_goto_program(
808814
status() << "Partial Inlining" << eom;
809815
goto_partial_inline(goto_functions, ns, ui_message_handler);
810816

817+
818+
if(cmdline.isset("string-refine"))
819+
{
820+
status() << "Preprocessing for string refinement" << eom;
821+
string_refine_preprocesst(
822+
symbol_table, goto_functions, ui_message_handler);
823+
}
824+
811825
// remove returns, gcc vectors, complex
812826
remove_returns(symbol_table, goto_functions);
813827
remove_vector(symbol_table, goto_functions);
@@ -1068,6 +1082,10 @@ void cbmc_parse_optionst::help()
10681082
" --yices use Yices\n"
10691083
" --z3 use Z3\n"
10701084
" --refine use refinement procedure (experimental)\n"
1085+
" --refine-strings use string refinement (experimental)\n"
1086+
" --string-non-empty add constraint that strings are non empty (experimental)\n" // NOLINT(*)
1087+
" --string-printable add constraint that strings are printable (experimental)\n" // NOLINT(*)
1088+
" --string-max-length add constraint on the length of strings (experimental)\n" // NOLINT(*)
10711089
" --outfile filename output formula to given file\n"
10721090
" --arrays-uf-never never turn arrays into uninterpreted functions\n" // NOLINT(*)
10731091
" --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
@@ -42,6 +42,7 @@ class optionst;
4242
"(no-sat-preprocessor)" \
4343
"(no-pretty-names)(beautify)" \
4444
"(dimacs)(refine)(max-node-refinement):(refine-arrays)(refine-arithmetic)"\
45+
"(string-refine)" \
4546
"(aig)(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \
4647
"(little-endian)(big-endian)" \
4748
"(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
@@ -109,15 +109,17 @@ class cbmc_solverst:public messaget
109109
solvert *solver;
110110

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

122124
return std::unique_ptr<solvert>(solver);
123125
}
@@ -139,6 +141,7 @@ class cbmc_solverst:public messaget
139141
solvert *get_default();
140142
solvert *get_dimacs();
141143
solvert *get_bv_refinement();
144+
solvert *get_string_refinement();
142145
solvert *get_smt1(smt1_dect::solvert solver);
143146
solvert *get_smt2(smt2_dect::solvert solver);
144147

0 commit comments

Comments
 (0)