Skip to content

Commit 8427503

Browse files
Convert assert calls to INVARIANTs
1 parent 98657d8 commit 8427503

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

src/cbmc/bmc_cover.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ bool bmc_covert::operator()()
221221
{
222222
if(it->is_assert())
223223
{
224-
assert(it->source.pc->is_assert());
224+
PRECONDITION(it->source.pc->is_assert());
225225
const and_exprt c(
226226
literal_exprt(it->guard_literal), literal_exprt(!it->cond_literal));
227227
literalt l_c=solver.convert(c);
@@ -241,7 +241,9 @@ bool bmc_covert::operator()()
241241
cover_goals.add(l);
242242
}
243243

244-
assert(cover_goals.size()==goal_map.size());
244+
INVARIANT(
245+
cover_goals.size() == goal_map.size(), "we add coverage for each goal");
246+
245247

246248
status() << "Running " << solver.decision_procedure_text() << eom;
247249

src/cbmc/cbmc_solvers.cpp

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

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

src/cbmc/cbmc_solvers.h

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

7171
prop_convt &prop_conv() const
7272
{
73-
assert(prop_conv_ptr!=nullptr);
73+
PRECONDITION(prop_conv_ptr!=nullptr);
7474
return *prop_conv_ptr;
7575
}
7676

7777
propt &prop() const
7878
{
79-
assert(prop_ptr!=nullptr);
79+
PRECONDITION(prop_ptr!=nullptr);
8080
return *prop_ptr;
8181
}
8282

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: 15 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+
DATA_INVARIANT(
149+
end_function->is_end_function(),
150+
"Last instruction in a function body is end function");
149151
file_name=end_function->source_location.get_file();
150-
assert(!file_name.empty());
152+
DATA_INVARIANT(!file_name.empty(), "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,15 @@ 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+
DATA_INVARIANT(
266+
c_entry->second.size() == 1 || is_branch,
267+
"Instructions other than branch instructions have exactly 1 successor");
264268

265269
for(const auto &cov : c_entry->second)
266270
{
267-
assert(cov.second.num_executions>0);
271+
DATA_INVARIANT(
272+
cov.second.num_executions > 0,
273+
"coverage entries can only exist with only one execution");
268274

269275
if(entry.first->second.hits==0)
270276
++lines_covered;
@@ -275,7 +281,9 @@ void goto_program_coverage_recordt::compute_coverage_lines(
275281
if(is_branch)
276282
{
277283
auto cond_entry=entry.first->second.conditions.find(it);
278-
assert(cond_entry!=entry.first->second.conditions.end());
284+
INVARIANT(
285+
cond_entry != entry.first->second.conditions.end(),
286+
"Branch should have condition");
279287

280288
if(it->get_target()==cov.second.succ)
281289
{
@@ -439,7 +447,7 @@ bool symex_coveraget::generate_report(
439447
const goto_functionst &goto_functions,
440448
const std::string &path) const
441449
{
442-
assert(!path.empty());
450+
PRECONDITION(!path.empty());
443451

444452
if(path=="-")
445453
return output_report(goto_functions, std::cout);

0 commit comments

Comments
 (0)