Skip to content

Commit 45df6d8

Browse files
Merge pull request #4 from hannes-steffenhagen-diffblue/fix-convert-asserts-to-invariants
Convert assert calls to INVARIANTs
2 parents 6fd77f4 + 0c88f17 commit 45df6d8

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

src/cbmc/bmc_cover.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ bool bmc_covert::operator()()
227227
{
228228
if(it->is_assert())
229229
{
230-
assert(it->source.pc->is_assert());
230+
PRECONDITION(it->source.pc->is_assert());
231231
const and_exprt c(
232232
literal_exprt(it->guard_literal), literal_exprt(!it->cond_literal));
233233
literalt l_c=solver.convert(c);
@@ -247,7 +247,8 @@ bool bmc_covert::operator()()
247247
cover_goals.add(l);
248248
}
249249

250-
assert(cover_goals.size()==goal_map.size());
250+
INVARIANT(cover_goals.size()==goal_map.size(),
251+
"We add coverage for each goal");
251252

252253
status() << "Running " << solver.decision_procedure_text() << eom;
253254

src/cbmc/cbmc_solvers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Author: Daniel Kroening, [email protected]
3434
/// \return An smt2_dect::solvert giving the solver to use.
3535
smt2_dect::solvert cbmc_solverst::get_smt2_solver_type() const
3636
{
37-
assert(options.get_bool_option("smt2"));
37+
// we shouldn't get here if this option isn't set
38+
PRECONDITION(options.get_bool_option("smt2"));
3839

3940
smt2_dect::solvert s=smt2_dect::solvert::GENERIC;
4041

src/cbmc/cbmc_solvers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ class cbmc_solverst:public messaget
7171

7272
prop_convt &prop_conv() const
7373
{
74-
assert(prop_conv_ptr!=nullptr);
74+
PRECONDITION(prop_conv_ptr!=nullptr);
7575
return *prop_conv_ptr;
7676
}
7777

7878
propt &prop() const
7979
{
80-
assert(prop_ptr!=nullptr);
80+
PRECONDITION(prop_ptr!=nullptr);
8181
return *prop_ptr;
8282
}
8383

src/cbmc/fault_localization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fault_localizationt::get_failed_property()
8181
bool fault_localizationt::check(const lpointst &lpoints,
8282
const lpoints_valuet &value)
8383
{
84-
assert(value.size()==lpoints.size());
84+
PRECONDITION(value.size()==lpoints.size());
8585
bvt assumptions;
8686
lpoints_valuet::const_iterator v_it=value.begin();
8787
for(const auto &l : lpoints)
@@ -142,7 +142,7 @@ void fault_localizationt::run(irep_idt goal_id)
142142
{
143143
// find failed property
144144
failed=get_failed_property();
145-
assert(failed!=bmc.equation.SSA_steps.end());
145+
PRECONDITION(failed!=bmc.equation.SSA_steps.end());
146146

147147
if(goal_id==ID_nil)
148148
goal_id=failed->source.pc->source_location.get_property_id();

src/cbmc/symex_coverage.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,17 @@ goto_program_coverage_recordt::goto_program_coverage_recordt(
139139
const symex_coveraget::coveraget &coverage):
140140
coverage_recordt("method")
141141
{
142-
assert(gf_it->second.body_available());
142+
PRECONDITION(gf_it->second.body_available());
143143

144144
// identify the file name, inlined functions aren't properly
145145
// accounted for
146146
goto_programt::const_targett end_function=
147147
--gf_it->second.body.instructions.end();
148-
assert(end_function->is_end_function());
148+
INVARIANT(end_function->is_end_function(),
149+
"Last instruction in a function body is end function");
149150
file_name=end_function->source_location.get_file();
150-
assert(!file_name.empty());
151+
INVARIANT(!file_name.empty(),
152+
"Should have a valid source location");
151153

152154
// compute the maximum coverage of individual source-code lines
153155
coverage_lines_mapt coverage_lines_map;
@@ -260,11 +262,14 @@ void goto_program_coverage_recordt::compute_coverage_lines(
260262
for(const auto &cov : c_entry->second)
261263
std::cerr << cov.second.succ->location_number << '\n';
262264
}
263-
assert(c_entry->second.size()==1 || is_branch);
265+
INVARIANT(c_entry->second.size()==1 || is_branch,
266+
"Instructions other than branch instructions have exactly 1 successor");
264267

265268
for(const auto &cov : c_entry->second)
266269
{
267-
assert(cov.second.num_executions>0);
270+
INVARIANT(cov.second.num_executions>0,
271+
// FIXME I don't know what this means
272+
"Number of executions most be positive");
268273

269274
if(entry.first->second.hits==0)
270275
++lines_covered;
@@ -275,7 +280,8 @@ void goto_program_coverage_recordt::compute_coverage_lines(
275280
if(is_branch)
276281
{
277282
auto cond_entry=entry.first->second.conditions.find(it);
278-
assert(cond_entry!=entry.first->second.conditions.end());
283+
INVARIANT(cond_entry!=entry.first->second.conditions.end(),
284+
"Branch should have condition");
279285

280286
if(it->get_target()==cov.second.succ)
281287
{
@@ -439,7 +445,7 @@ bool symex_coveraget::generate_report(
439445
const goto_functionst &goto_functions,
440446
const std::string &path) const
441447
{
442-
assert(!path.empty());
448+
PRECONDITION(!path.empty());
443449

444450
if(path=="-")
445451
return output_report(goto_functions, std::cout);

0 commit comments

Comments
 (0)