Skip to content

Commit c04c4ab

Browse files
author
kroening
committed
include unreached assertions among coverage goals
git-svn-id: svn+ssh://svn.cprover.org/srv/svn/cbmc/trunk@1058 6afb6bc1-c8e4-404c-8f48-9ae832c5b171
1 parent 35b430a commit c04c4ab

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/cbmc/bmc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ bool bmct::run(const goto_functionst &goto_functions)
414414

415415
if(options.get_bool_option("cover-assertions"))
416416
{
417-
cover_assertions();
417+
cover_assertions(goto_functions);
418418
return false;
419419
}
420420

src/cbmc/bmc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class bmct:public messaget
103103
const prop_convt &prop_conv);
104104

105105
// vacuity checks
106-
void cover_assertions();
106+
void cover_assertions(const goto_functionst &goto_functions);
107107
};
108108

109109
#endif

src/cbmc/cover.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void cover_goalst::constraint()
123123
g_it=goals.begin();
124124
g_it!=goals.end();
125125
g_it++)
126-
if(!g_it->covered)
126+
if(!g_it->covered && !g_it->condition.is_false())
127127
bv.push_back(g_it->condition);
128128

129129
prop.lcnf(bv);
@@ -185,7 +185,7 @@ Function: bmct::cover_assertions
185185
186186
\*******************************************************************/
187187

188-
void bmct::cover_assertions()
188+
void bmct::cover_assertions(const goto_functionst &goto_functions)
189189
{
190190
// with simplifier: need to freeze goal variables
191191
// to prevent them from being eliminated
@@ -212,19 +212,27 @@ void bmct::cover_assertions()
212212
equation.convert_decls(prop_conv);
213213
equation.convert_assumptions(prop_conv);
214214

215-
// collect goals in `goal_map'
216-
literalt assumption_literal=const_literal(true);
217-
215+
// collect _all_ goals in `goal_map'
218216
typedef std::map<goto_programt::const_targett, bvt> goal_mapt;
219217
goal_mapt goal_map;
218+
219+
forall_goto_functions(f_it, goto_functions)
220+
forall_goto_program_instructions(i_it, f_it->second.body)
221+
if(i_it->is_assert())
222+
goal_map[i_it]=bvt();
223+
224+
// get the conditions for these goals from formula
225+
226+
literalt assumption_literal=const_literal(true);
220227

221228
for(symex_target_equationt::SSA_stepst::iterator
222229
it=equation.SSA_steps.begin();
223230
it!=equation.SSA_steps.end();
224231
it++)
232+
{
225233
if(it->is_assert())
226234
{
227-
// we just want reachability, i.e., the guard,
235+
// we just want reachability, i.e., the guard of the instruction,
228236
// not the assertion itself
229237
literalt l=
230238
prop_conv.prop.land(assumption_literal, it->guard_literal);
@@ -234,8 +242,9 @@ void bmct::cover_assertions()
234242
else if(it->is_assume())
235243
assumption_literal=
236244
prop_conv.prop.land(assumption_literal, it->cond_literal);
245+
}
237246

238-
// compute
247+
// try to cover those
239248
cover_goalst cover_goals(prop_conv);
240249
cover_goals.set_message_handler(get_message_handler());
241250
cover_goals.set_verbosity(get_verbosity());
@@ -245,6 +254,7 @@ void bmct::cover_assertions()
245254
it!=goal_map.end();
246255
it++)
247256
{
257+
// the following is FALSE if the bv is empty
248258
literalt condition=prop_conv.prop.lor(it->second);
249259
cover_goals.add(condition, it->first->location.as_string());
250260
}

src/cbmc/parseoptions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,12 @@ bool cbmc_parseoptionst::process_goto_program(
651651

652652
// add loop ids
653653
goto_functions.compute_loop_numbers();
654+
655+
// if we aim to cover, replace
656+
// all assertions by false to prevent simplification
657+
658+
if(cmdline.isset("cover-assertions"))
659+
make_assertions_false(goto_functions);
654660

655661
// show it?
656662
if(cmdline.isset("show-loops"))

0 commit comments

Comments
 (0)