Skip to content

Commit 260e03d

Browse files
committed
symex --max-search-time limit and cleanup
All symex limits use value -1 as marking "not set". Use size_t for counting statistics.
1 parent acdc797 commit 260e03d

File tree

4 files changed

+43
-31
lines changed

4 files changed

+43
-31
lines changed

src/symex/path_search.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,19 @@ bool path_searcht::drop_state(const statet &state)
281281
}
282282

283283
// depth limit
284-
if(depth_limit_set && state.get_depth()>depth_limit)
284+
if(depth_limit>=0 && state.get_depth()>depth_limit)
285285
return true;
286286

287287
// context bound
288-
if(context_bound_set && state.get_no_thread_interleavings()>context_bound)
288+
if(context_bound>=0 && state.get_no_thread_interleavings()>context_bound)
289289
return true;
290290

291291
// branch bound
292-
if(branch_bound_set && state.get_no_branches()>branch_bound)
292+
if(branch_bound>=0 && state.get_no_branches()>branch_bound)
293293
return true;
294294

295295
// unwinding limit -- loops
296-
if(unwind_limit_set && state.get_instruction()->is_backwards_goto())
296+
if(unwind_limit>=0 && pc->is_backwards_goto())
297297
{
298298
bool stop=false;
299299

@@ -319,7 +319,7 @@ bool path_searcht::drop_state(const statet &state)
319319
}
320320

321321
// unwinding limit -- recursion
322-
if(unwind_limit_set && state.get_instruction()->is_function_call())
322+
if(unwind_limit>=0 && pc->is_function_call())
323323
{
324324
bool stop=false;
325325

@@ -346,6 +346,11 @@ bool path_searcht::drop_state(const statet &state)
346346
return true;
347347
}
348348

349+
// search time limit (--max-search-time)
350+
if(time_limit>=0 &&
351+
current_time().get_t()>start_time.get_t()+time_limit*1000)
352+
return true;
353+
349354
if(pc->is_assume() &&
350355
simplify_expr(pc->guard, ns).is_false())
351356
{

src/symex/path_search.h

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,55 @@ class path_searcht:public safety_checkert
2626
safety_checkert(_ns),
2727
show_vcc(false),
2828
eager_infeasibility(false),
29-
depth_limit_set(false), // no limit
30-
context_bound_set(false),
31-
unwind_limit_set(false),
32-
branch_bound_set(false),
29+
depth_limit(-1), // no limit
30+
context_bound(-1),
31+
branch_bound(-1),
32+
unwind_limit(-1),
33+
time_limit(-1),
3334
search_heuristic(search_heuristict::DFS)
3435
{
3536
}
3637

3738
virtual resultt operator()(
3839
const goto_functionst &goto_functions);
3940

40-
void set_depth_limit(unsigned limit)
41+
void set_depth_limit(int limit)
4142
{
42-
depth_limit_set=true;
4343
depth_limit=limit;
4444
}
4545

46-
void set_context_bound(unsigned limit)
46+
void set_context_bound(int limit)
4747
{
48-
context_bound_set=true;
4948
context_bound=limit;
5049
}
5150

52-
void set_branch_bound(unsigned limit)
51+
void set_branch_bound(int limit)
5352
{
54-
branch_bound_set=true;
5553
branch_bound=limit;
5654
}
5755

58-
void set_unwind_limit(unsigned limit)
56+
void set_unwind_limit(int limit)
5957
{
60-
unwind_limit_set=true;
6158
unwind_limit=limit;
6259
}
6360

61+
void set_time_limit(int limit)
62+
{
63+
time_limit=limit;
64+
}
65+
6466
bool show_vcc;
6567
bool eager_infeasibility;
6668

6769
// statistics
68-
unsigned number_of_dropped_states;
69-
unsigned number_of_paths;
70-
unsigned number_of_steps;
71-
unsigned number_of_feasible_paths;
72-
unsigned number_of_infeasible_paths;
73-
unsigned number_of_VCCs;
74-
unsigned number_of_VCCs_after_simplification;
75-
unsigned number_of_failed_properties;
70+
std::size_t number_of_dropped_states;
71+
std::size_t number_of_paths;
72+
std::size_t number_of_steps;
73+
std::size_t number_of_feasible_paths;
74+
std::size_t number_of_infeasible_paths;
75+
std::size_t number_of_VCCs;
76+
std::size_t number_of_VCCs_after_simplification;
77+
std::size_t number_of_failed_properties;
7678
std::size_t number_of_locs;
7779
absolute_timet start_time;
7880
time_periodt sat_time;
@@ -130,11 +132,11 @@ class path_searcht:public safety_checkert
130132
void initialize_property_map(
131133
const goto_functionst &goto_functions);
132134

133-
unsigned depth_limit;
134-
unsigned context_bound;
135-
unsigned branch_bound;
136-
unsigned unwind_limit;
137-
bool depth_limit_set, context_bound_set, unwind_limit_set, branch_bound_set;
135+
int depth_limit;
136+
int context_bound;
137+
int branch_bound;
138+
int unwind_limit;
139+
int time_limit;
138140

139141
enum class search_heuristict { DFS, BFS, LOCS } search_heuristic;
140142

src/symex/symex_parse_options.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ int symex_parse_optionst::doit()
186186
path_search.set_unwind_limit(
187187
unsafe_string2unsigned(cmdline.get_value("unwind")));
188188

189+
if(cmdline.isset("max-search-time"))
190+
path_search.set_time_limit(
191+
safe_string2unsigned(cmdline.get_value("max-search-time")));
192+
189193
if(cmdline.isset("dfs"))
190194
path_search.set_dfs();
191195

@@ -607,6 +611,7 @@ void symex_parse_optionst::help()
607611
" --depth nr limit search depth\n"
608612
" --context-bound nr limit number of context switches\n"
609613
" --branch-bound nr limit number of branches taken\n"
614+
" --max-search-time s limit search to approximately s seconds\n"
610615
"\n"
611616
"Other options:\n"
612617
" --version show version and exit\n"

src/symex/symex_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class optionst;
3030
#define SYMEX_OPTIONS \
3131
"(function):" \
3232
"D:I:" \
33-
"(depth):(context-bound):(branch-bound):(unwind):" \
33+
"(depth):(context-bound):(branch-bound):(unwind):(max-search-time):" \
3434
OPT_GOTO_CHECK \
3535
"(no-assertions)(no-assumptions)" \
3636
"(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \

0 commit comments

Comments
 (0)