Skip to content

Make location coverage reported include all lines of a multi-line statement #5635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/goto-instrument/cover_basic_blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ cover_basic_blockst::cover_basic_blockst(const goto_programt &goto_program)

block_map[it] = current_block;

// update lines belonging to block
const irep_idt &line = it->source_location.get_line();
if(!line.empty())
{
block_info.lines.insert(unsafe_string2unsigned(id2string(line)));
block_info.source_lines.insert(it->source_location);
}
add_block_lines(block_info, *it);
Copy link
Contributor

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue Nov 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really unfortunate. Constructors generally shouldn’t be as complicated as this one is to begin with!

(Not that this is this PRs fault)


// set representative program location to instrument
if(
Expand Down Expand Up @@ -155,6 +149,18 @@ void cover_basic_blockst::output(std::ostream &out) const
<< '\n';
}

void cover_basic_blockst::add_block_lines(
cover_basic_blockst::block_infot &block,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ should imho be called block_info.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, it would be better to rename block_infot to blockt. This is on the basis that you wouldn't bother creating instances of a struct that didn't contain information. Therefore the word info is redundant in the context of the name. It doesn't really convey any useful meaning to the reader.

const goto_programt::instructiont &instruction)
{
const irep_idt &line = instruction.source_location.get_line();
if(!line.empty())
{
block.lines.insert(unsafe_string2unsigned(id2string(line)));
block.source_lines.insert(instruction.source_location);
}
}

void cover_basic_blockst::update_covered_lines(block_infot &block_info)
{
if(block_info.source_location.is_nil())
Expand Down
5 changes: 5 additions & 0 deletions src/goto-instrument/cover_basic_blocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class cover_basic_blockst final : public cover_blocks_baset
/// map block numbers to block information
std::vector<block_infot> block_infos;

/// Adds the lines which \param instruction spans to \param block.
static void add_block_lines(
cover_basic_blockst::block_infot &block,
const goto_programt::instructiont &instruction);

/// create list of covered lines as CSV string and set as property of source
/// location of basic block, compress to ranges if applicable
static void update_covered_lines(block_infot &block_info);
Expand Down