Skip to content

Commit 671f8f5

Browse files
committed
Enfold assume in an assert(false) to allow for easier debugging.
This allows for easier debugging by allowing `assume(false)`s that end up emptying the search state space to be identified on a more granular basis.
1 parent e32a83f commit 671f8f5

File tree

9 files changed

+87
-2
lines changed

9 files changed

+87
-2
lines changed

jbmc/src/jdiff/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ OBJ += ../$(CPROVER_DIR)/src/ansi-c/ansi-c$(LIBEXT) \
1818
../$(CPROVER_DIR)/src/goto-instrument/cover$(OBJEXT) \
1919
../$(CPROVER_DIR)/src/goto-instrument/cover_basic_blocks$(OBJEXT) \
2020
../$(CPROVER_DIR)/src/goto-instrument/cover_filter$(OBJEXT) \
21+
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_assume$(OBJEXT) \
2122
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_branch$(OBJEXT) \
2223
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_condition$(OBJEXT) \
2324
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_decision$(OBJEXT) \

src/cbmc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
2626
../goto-instrument/cover$(OBJEXT) \
2727
../goto-instrument/cover_basic_blocks$(OBJEXT) \
2828
../goto-instrument/cover_filter$(OBJEXT) \
29+
../goto-instrument/cover_instrument_assume$(OBJEXT) \
2930
../goto-instrument/cover_instrument_branch$(OBJEXT) \
3031
../goto-instrument/cover_instrument_condition$(OBJEXT) \
3132
../goto-instrument/cover_instrument_decision$(OBJEXT) \

src/goto-checker/properties.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Author: Daniel Kroening, Peter Schrammel
1212
#ifndef CPROVER_GOTO_CHECKER_PROPERTIES_H
1313
#define CPROVER_GOTO_CHECKER_PROPERTIES_H
1414

15-
#include <unordered_map>
15+
#include <map>
1616

1717
#include <goto-programs/goto_program.h>
1818

@@ -73,7 +73,7 @@ struct property_infot
7373
};
7474

7575
/// A map of property IDs to property infos
76-
typedef std::unordered_map<irep_idt, property_infot> propertiest;
76+
typedef std::map<irep_idt, property_infot> propertiest;
7777

7878
/// Returns the properties in the goto model
7979
propertiest initialize_properties(const abstract_goto_modelt &);

src/goto-diff/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
1818
../goto-instrument/cover$(OBJEXT) \
1919
../goto-instrument/cover_basic_blocks$(OBJEXT) \
2020
../goto-instrument/cover_filter$(OBJEXT) \
21+
../goto-instrument/cover_instrument_assume$(OBJEXT) \
2122
../goto-instrument/cover_instrument_branch$(OBJEXT) \
2223
../goto-instrument/cover_instrument_condition$(OBJEXT) \
2324
../goto-instrument/cover_instrument_decision$(OBJEXT) \

src/goto-instrument/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SRC = accelerate/accelerate.cpp \
2424
cover.cpp \
2525
cover_basic_blocks.cpp \
2626
cover_filter.cpp \
27+
cover_instrument_assume.cpp \
2728
cover_instrument_branch.cpp \
2829
cover_instrument_condition.cpp \
2930
cover_instrument_decision.cpp \

src/goto-instrument/cover.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ void cover_instrumenterst::add_from_criterion(
9999
case coverage_criteriont::COVER:
100100
instrumenters.push_back(
101101
util_make_unique<cover_cover_instrumentert>(symbol_table, goal_filters));
102+
break;
103+
case coverage_criteriont::ASSUME:
104+
instrumenters.push_back(
105+
util_make_unique<cover_assume_instrumentert>(symbol_table, goal_filters));
102106
}
103107
}
104108

@@ -126,6 +130,8 @@ parse_coverage_criterion(const std::string &criterion_string)
126130
c = coverage_criteriont::MCDC;
127131
else if(criterion_string == "cover")
128132
c = coverage_criteriont::COVER;
133+
else if(criterion_string == "assume")
134+
c = coverage_criteriont::ASSUME;
129135
else
130136
{
131137
std::stringstream s;
@@ -201,6 +207,9 @@ cover_configt get_cover_config(
201207

202208
if(c == coverage_criteriont::ASSERTION)
203209
cover_config.keep_assertions = true;
210+
// Make sure that existing assertions don't get replaced by assumes
211+
else if(c == coverage_criteriont::ASSUME)
212+
cover_config.keep_assertions = true;
204213

205214
instrumenters.add_from_criterion(c, symbol_table, *goal_filters);
206215
}

src/goto-instrument/cover.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class optionst;
4141

4242
enum class coverage_criteriont
4343
{
44+
ASSUME,
4445
LOCATION,
4546
BRANCH,
4647
DECISION,

src/goto-instrument/cover_instrument.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,24 @@ void cover_instrument_end_of_function(
290290
goto_programt &goto_program,
291291
const cover_instrumenter_baset::assertion_factoryt &);
292292

293+
// assume-instructions instrumenter.
294+
class cover_assume_instrumentert : public cover_instrumenter_baset
295+
{
296+
public:
297+
cover_assume_instrumentert(
298+
const symbol_tablet &_symbol_table,
299+
const goal_filterst &_goal_filters)
300+
: cover_instrumenter_baset(_symbol_table, _goal_filters, "location")
301+
{
302+
}
303+
304+
protected:
305+
void instrument(
306+
const irep_idt &,
307+
goto_programt &,
308+
goto_programt::targett &,
309+
const cover_blocks_baset &,
310+
const assertion_factoryt &) const override;
311+
};
312+
293313
#endif // CPROVER_GOTO_INSTRUMENT_COVER_INSTRUMENT_H
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/// \file cover_instrument_assume.cpp
2+
/// Author: Diffblue Ltd.
3+
/// Coverage Instrumentation for ASSUME instructions.
4+
5+
#include "cover_instrument.h"
6+
7+
#include "ansi-c/expr2c.h"
8+
#include "goto-programs/goto_program.h"
9+
#include "util/std_expr.h"
10+
#include <util/namespace.h>
11+
12+
/// Instrument program to check coverage of assume statements.
13+
/// \param goto_program The goto-program (function under instrumentation).
14+
/// \param i_it The current instruction (instruction under instrumentation).
15+
/// \param make_assertion The assertion generator function.
16+
void cover_assume_instrumentert::instrument(
17+
const irep_idt &function_id,
18+
goto_programt &goto_program,
19+
goto_programt::targett &i_it,
20+
const cover_blocks_baset &,
21+
const assertion_factoryt &make_assertion) const
22+
{
23+
namespacet ns{symbol_tablet()};
24+
if(i_it->is_assume())
25+
{
26+
const auto location = i_it->source_location;
27+
const auto assume_condition = expr2c(i_it->get_condition(), ns);
28+
const auto comment_before =
29+
"assert(false) before assume(" + assume_condition + ")";
30+
const auto comment_after =
31+
"assert(false) after assume(" + assume_condition + ")";
32+
33+
const auto assert_before = make_assertion(false_exprt{}, location);
34+
goto_programt::targett t = goto_program.insert_before(i_it, assert_before);
35+
initialize_source_location(t, comment_before, function_id);
36+
37+
const auto assert_after = make_assertion(false_exprt{}, location);
38+
t = goto_program.insert_after(i_it, assert_after);
39+
initialize_source_location(t, comment_after, function_id);
40+
}
41+
// Otherwise, skip existing assertions.
42+
else if(i_it->is_assert())
43+
{
44+
const auto location = i_it->source_location;
45+
// Filter based on if assertion was added by us as part of instrumentation.
46+
if(location.get_property_class() != "coverage")
47+
{
48+
i_it->turn_into_skip();
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)