Skip to content

Location coverage reporting should ignore globals #6981

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 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions regression/cbmc-cover/location2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <string.h>

#define BUFLEN 100

static void *(*const volatile memset_func)(void *, int, size_t) = memset;

int main()
{
char buffer[BUFLEN];
memset_func(&buffer, 0, BUFLEN);
}
14 changes: 14 additions & 0 deletions regression/cbmc-cover/location2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CORE
main.c
--cover location
^EXIT=0$
^SIGNAL=0$
^\[main.coverage.1\] file main.c line 9 function main block 1 \(lines main.c:main:9,10\): SATISFIED$
^\[main.coverage.2\] file main.c line 11 function main block 2 \(lines main.c:main:11\): SATISFIED$
^\*\* 2 of 2 covered \(100.0%\)
--
^warning: ignoring
main.c::5
--
Expressions outside a function should not end up listed as part of source code
blocks.
7 changes: 5 additions & 2 deletions src/goto-instrument/cover_basic_blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ void cover_basic_blockst::add_block_lines(
}
};
add_location(instruction.source_location());
instruction.get_code().visit_pre(
[&](const exprt &expr) { add_location(expr.source_location()); });
instruction.get_code().visit_pre([&](const exprt &expr) {
const auto &location = expr.source_location();
if(!location.get_function().empty())
add_location(location);
});
}

cover_basic_blocks_javat::cover_basic_blocks_javat(
Expand Down