@@ -19,6 +19,22 @@ Author: Peter Schrammel
19
19
// / location of basic block, compress to ranges if applicable
20
20
static void update_covered_lines (cover_basic_blockst::block_infot &block_info);
21
21
22
+ // / If this block is a continuation of a previous block through unconditional
23
+ // / forward gotos, return this blocks number.
24
+ static optionalt<unsigned > continuation_of_block (
25
+ const goto_programt::const_targett &instruction,
26
+ std::map<goto_programt::const_targett, unsigned > &block_map)
27
+ {
28
+ if (instruction->incoming_edges .size () != 1 )
29
+ return {};
30
+
31
+ const goto_programt::targett in_t = *instruction->incoming_edges .cbegin ();
32
+ if (in_t ->is_goto () && !in_t ->is_backwards_goto () && in_t ->guard .is_true ())
33
+ return block_map[in_t ];
34
+
35
+ return {};
36
+ }
37
+
22
38
cover_basic_blockst::cover_basic_blockst (const goto_programt &_goto_program)
23
39
{
24
40
bool next_is_target = true ;
@@ -29,25 +45,13 @@ cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
29
45
// Is it a potential beginning of a block?
30
46
if (next_is_target || it->is_target ())
31
47
{
32
- // We keep the block number if this potential block
33
- // is a continuation of a previous block through
34
- // unconditional forward gotos; otherwise we increase the
35
- // block number.
36
- bool increase_block_nr = true ;
37
- if (it->incoming_edges .size () == 1 )
48
+ if (auto block_number = continuation_of_block (it, block_map))
38
49
{
39
- goto_programt::targett in_t = *it->incoming_edges .begin ();
40
- if (
41
- in_t ->is_goto () && !in_t ->is_backwards_goto () &&
42
- in_t ->guard .is_true ())
43
- {
44
- current_block = block_map[in_t ];
45
- increase_block_nr = false ;
46
- }
50
+ current_block = *block_number;
47
51
}
48
- if (increase_block_nr)
52
+ else
49
53
{
50
- block_infos.push_back ( block_infot () );
54
+ block_infos.emplace_back ( );
51
55
block_infos.back ().representative_inst = it;
52
56
block_infos.back ().source_location = source_locationt::nil ();
53
57
current_block = block_infos.size () - 1 ;
0 commit comments