cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
cover_instrument_branch.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Coverage Instrumentation
4
5
Author: Daniel Kroening
6
7
\*******************************************************************/
8
11
12
#include "
cover_basic_blocks.h
"
13
#include "
cover_filter.h
"
14
#include "
cover_instrument.h
"
15
16
void
cover_branch_instrumentert::instrument
(
17
const
irep_idt
&function_id,
18
goto_programt
&goto_program,
19
goto_programt::targett
&i_it,
20
const
cover_blocks_baset
&basic_blocks,
21
const
assertion_factoryt
&make_assertion)
const
22
{
23
if
(
is_non_cover_assertion
(i_it))
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 = i_it->is_goto() && i_it->condition() !=
true
;
29
if
(!is_function_entry_point && !is_conditional_goto)
30
return
;
31
32
if
(!
goal_filters
(i_it->source_location()))
33
return
;
34
35
if
(is_function_entry_point)
36
{
37
// we want branch coverage to imply 'entry point of function'
38
// coverage
39
std::string
comment
=
"entry point"
;
40
41
source_locationt
source_location = i_it->source_location();
42
initialize_source_location
(source_location,
comment
, function_id);
43
goto_program.
insert_before
(
44
i_it, make_assertion(
false_exprt
(), source_location));
45
}
46
47
if
(is_conditional_goto)
48
{
49
std::string b =
50
std::to_string(basic_blocks.
block_of
(i_it) + 1);
// start with 1
51
std::string true_comment =
"block "
+ b +
" branch true"
;
52
std::string false_comment =
"block "
+ b +
" branch false"
;
53
54
exprt
guard
= i_it->condition();
55
source_locationt
source_location = i_it->source_location();
56
57
goto_program.
insert_before_swap
(i_it);
58
initialize_source_location
(source_location, true_comment, function_id);
59
*i_it = make_assertion(
not_exprt
(
guard
), source_location);
60
61
goto_program.
insert_before_swap
(i_it);
62
initialize_source_location
(source_location, false_comment, function_id);
63
*i_it = make_assertion(
guard
, source_location);
64
65
std::advance(i_it, 2);
66
}
67
}
guard
static exprt guard(const exprt::operandst &guards, exprt cond)
Definition
c_safety_checks.cpp:69
cover_blocks_baset
Definition
cover_basic_blocks.h:22
cover_blocks_baset::block_of
virtual std::size_t block_of(goto_programt::const_targett t) const =0
cover_branch_instrumentert::instrument
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.
Definition
cover_instrument_branch.cpp:16
cover_instrumenter_baset::goal_filters
const goal_filterst & goal_filters
Definition
cover_instrument.h:73
cover_instrumenter_baset::is_non_cover_assertion
bool is_non_cover_assertion(goto_programt::const_targett t) const
Definition
cover_instrument.h:94
cover_instrumenter_baset::initialize_source_location
void initialize_source_location(source_locationt &source_location, const std::string &comment, const irep_idt &function_id) const
Definition
cover_instrument.h:83
cover_instrumenter_baset::assertion_factoryt
std::function< goto_programt::instructiont(const exprt &, const source_locationt &)> assertion_factoryt
The type of function used to make goto_program assertions.
Definition
cover_instrument.h:41
exprt
Base class for all expressions.
Definition
expr.h:57
false_exprt
The Boolean constant false.
Definition
std_expr.h:3125
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition
goto_program.h:72
goto_programt::instructions
instructionst instructions
The list of instructions in the goto program.
Definition
goto_program.h:621
goto_programt::insert_before_swap
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
Definition
goto_program.h:642
goto_programt::targett
instructionst::iterator targett
Definition
goto_program.h:613
goto_programt::insert_before
targett insert_before(const_targett target)
Insertion before the instruction pointed-to by the given instruction iterator target.
Definition
goto_program.h:691
not_exprt
Boolean negation.
Definition
std_expr.h:2378
source_locationt
Definition
source_location.h:20
cover_basic_blocks.h
Basic blocks detection for Coverage Instrumentation.
cover_filter.h
Filters for the Coverage Instrumentation.
cover_instrument.h
Coverage Instrumentation.
comment
static std::string comment(const rw_set_baset::entryt &entry, bool write)
Definition
race_check.cpp:108
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
goto-instrument
cover_instrument_branch.cpp
Generated by
1.17.0