CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cover_instrument_branch.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Coverage Instrumentation
4
5Author: Daniel Kroening
6
7\*******************************************************************/
8
11
12#include "cover_basic_blocks.h"
13#include "cover_filter.h"
14#include "cover_instrument.h"
15
17 const irep_idt &function_id,
18 goto_programt &goto_program,
21 const assertion_factoryt &make_assertion) const
22{
24 i_it->turn_into_skip();
25
26 const bool is_function_entry_point =
27 i_it == goto_program.instructions.begin();
28 const bool is_conditional_goto =
29 i_it->is_goto() && !i_it->condition().is_true();
31 return;
32
33 if(!goal_filters(i_it->source_location()))
34 return;
35
37 {
38 // we want branch coverage to imply 'entry point of function'
39 // coverage
40 std::string comment = "entry point";
41
42 source_locationt source_location = i_it->source_location();
43 initialize_source_location(source_location, comment, function_id);
44 goto_program.insert_before(
45 i_it, make_assertion(false_exprt(), source_location));
46 }
47
49 {
50 std::string b =
51 std::to_string(basic_blocks.block_of(i_it) + 1); // start with 1
52 std::string true_comment = "block " + b + " branch true";
53 std::string false_comment = "block " + b + " branch false";
54
55 exprt guard = i_it->condition();
56 source_locationt source_location = i_it->source_location();
57
58 goto_program.insert_before_swap(i_it);
59 initialize_source_location(source_location, true_comment, function_id);
60 *i_it = make_assertion(not_exprt(guard), source_location);
61
62 goto_program.insert_before_swap(i_it);
63 initialize_source_location(source_location, false_comment, function_id);
64 *i_it = make_assertion(guard, source_location);
65
66 std::advance(i_it, 2);
67 }
68}
static exprt guard(const exprt::operandst &guards, exprt cond)
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
void instrument(const irep_idt &function_id, goto_programt &, goto_programt::targett &, const cover_blocks_baset &, const assertion_factoryt &) const override
Override this method to implement an instrumenter.
const goal_filterst & goal_filters
bool is_non_cover_assertion(goto_programt::const_targett t) const
void initialize_source_location(source_locationt &source_location, const std::string &comment, const irep_idt &function_id) const
std::function< goto_programt::instructiont(const exprt &, const source_locationt &)> assertion_factoryt
The type of function used to make goto_program assertions.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:56
The Boolean constant false.
Definition std_expr.h:3199
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
instructionst::iterator targett
targett insert_before(const_targett target)
Insertion before the instruction pointed-to by the given instruction iterator target.
Boolean negation.
Definition std_expr.h:2454
Basic blocks detection for Coverage Instrumentation.
Filters for the Coverage Instrumentation.
Coverage Instrumentation.
static std::string comment(const rw_set_baset::entryt &entry, bool write)