Skip to content

Commit fffc77e

Browse files
committed
Location coverage reporting should ignore globals
We iterate over instructions in non-built-in functions, and it is therefore reasonable to expect that all source locations have functions that they belong to. If symbols declared at global scope are part of expressions then this shouldn't yield calling them out in location coverage. (That's just where they were declared, it doesn't even strictly imply their assignments were covered.) Fixes: #6978
1 parent 8bf2503 commit fffc77e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <string.h>
2+
3+
#define BUFLEN 100
4+
5+
static void *(*const volatile memset_func)(void *, int, size_t) = memset;
6+
7+
int main()
8+
{
9+
char buffer[BUFLEN];
10+
memset_func(&buffer, 0, BUFLEN);
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
main.c
3+
--cover location
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.coverage.1\] file main.c line 9 function main block 1 \(lines main.c:main:9,10\): SATISFIED$
7+
^\[main.coverage.2\] file main.c line 11 function main block 2 \(lines main.c:main:11\): SATISFIED$
8+
^\*\* 2 of 2 covered \(100.0%\)
9+
--
10+
^warning: ignoring
11+
main.c::5
12+
--
13+
Expressions outside a function should not end up listed as part of source code
14+
blocks.

src/goto-instrument/cover_basic_blocks.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ void cover_basic_blockst::add_block_lines(
163163
}
164164
};
165165
add_location(instruction.source_location());
166-
instruction.get_code().visit_pre(
167-
[&](const exprt &expr) { add_location(expr.source_location()); });
166+
instruction.get_code().visit_pre([&](const exprt &expr) {
167+
const auto &location = expr.source_location();
168+
if(!location.get_function().empty())
169+
add_location(location);
170+
});
168171
}
169172

170173
cover_basic_blocks_javat::cover_basic_blocks_javat(

0 commit comments

Comments
 (0)