Hi,
as explained in
https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00105.html
we don't (necessarily) want to report non-executed blocks in Ada.
The couple of attached patches prevent this from happening by detecting
whether we are dealing with an Ada file; the first variant is optimal, the
second variant is slightly more general in case other languages need it too.
Tested on x86_64-suse-linux, OK for the mainline (and which one)?
2017-11-03 Eric Botcazou <ebotca...@adacore.com>
* gcov.c (output_line_beginning): Document HAS_UNEXECUTED_BLOCK.
(output_lines): Always pass false for HAS_UNEXECUTED_BLOCK to
above function if this is for an Ada file.
--
Eric Botcazou
Index: gcov.c
===================================================================
--- gcov.c (revision 254348)
+++ gcov.c (working copy)
@@ -2477,10 +2477,11 @@ pad_count_string (string &s)
}
/* Print GCOV line beginning to F stream. If EXISTS is set to true, the
- line exists in source file. UNEXCEPTIONAL indicated that it's not in
- an exceptional statement. The output is printed for LINE_NUM of given
- COUNT of executions. EXCEPTIONAL_STRING and UNEXCEPTIONAL_STRING are
- used to indicate non-executed blocks. */
+ line exists in source file. UNEXCEPTIONAL indicates that it's not in
+ an exceptional statement. HAS_UNEXECUTED_BLOCK indicates that it has
+ at least one non-executed block. The output is printed for LINE_NUM of
+ given COUNT of executions. EXCEPTIONAL_STRING and UNEXCEPTIONAL_STRING
+ are used to indicate non-executed blocks. */
static void
output_line_beginning (FILE *f, bool exists, bool unexceptional,
@@ -2552,6 +2553,7 @@ output_lines (FILE *gcov_file, const sou
const line_info *line; /* current line info ptr. */
const char *retval = ""; /* status of source file reading. */
function_t *fn = NULL;
+ bool is_ada_file = false;
fprintf (gcov_file, DEFAULT_LINE_START "Source:%s\n", src->coverage.name);
if (!multiple_files)
@@ -2575,6 +2577,17 @@ output_lines (FILE *gcov_file, const sou
if (flag_branches)
fn = src->functions;
+ /* Detect whether we are dealing with an Ada file. If this is the case,
+ then we don't report non-executed blocks for lines because statements
+ can easily give rise to non-executed blocks in Ada, e.g. for checks. */
+ const char *const last_dot = strrchr (src->name, '.');
+ if (last_dot
+ && last_dot[1] == 'a'
+ && last_dot[2] == 'd'
+ && (last_dot[3] == 'a' || last_dot[3] == 'b' || last_dot[3] == 's')
+ && last_dot[4] == '\0')
+ is_ada_file = true;
+
for (line_num = 1, line = &src->lines[line_num];
line_num < src->lines.size (); line_num++, line++)
{
@@ -2610,7 +2623,8 @@ output_lines (FILE *gcov_file, const sou
There are 16 spaces of indentation added before the source
line so that tabs won't be messed up. */
output_line_beginning (gcov_file, line->exists, line->unexceptional,
- line->has_unexecuted_block, line->count, line_num,
+ line->has_unexecuted_block && !is_ada_file,
+ line->count, line_num,
"=====", "#####");
fprintf (gcov_file, ":%s\n", retval ? retval : "/*EOF*/");
Index: gcov.c
===================================================================
--- gcov.c (revision 254348)
+++ gcov.c (working copy)
@@ -2477,10 +2477,11 @@ pad_count_string (string &s)
}
/* Print GCOV line beginning to F stream. If EXISTS is set to true, the
- line exists in source file. UNEXCEPTIONAL indicated that it's not in
- an exceptional statement. The output is printed for LINE_NUM of given
- COUNT of executions. EXCEPTIONAL_STRING and UNEXCEPTIONAL_STRING are
- used to indicate non-executed blocks. */
+ line exists in source file. UNEXCEPTIONAL indicates that it's not in
+ an exceptional statement. HAS_UNEXECUTED_BLOCK indicates that it has
+ at least one non-executed block. The output is printed for LINE_NUM of
+ given COUNT of executions. EXCEPTIONAL_STRING and UNEXCEPTIONAL_STRING
+ are used to indicate non-executed blocks. */
static void
output_line_beginning (FILE *f, bool exists, bool unexceptional,
@@ -2552,6 +2553,7 @@ output_lines (FILE *gcov_file, const sou
const line_info *line; /* current line info ptr. */
const char *retval = ""; /* status of source file reading. */
function_t *fn = NULL;
+ bool is_ada_file = false;
fprintf (gcov_file, DEFAULT_LINE_START "Source:%s\n", src->coverage.name);
if (!multiple_files)
@@ -2575,6 +2577,23 @@ output_lines (FILE *gcov_file, const sou
if (flag_branches)
fn = src->functions;
+ /* Detect whether we are dealing with an Ada file. If this is the case,
+ then we don't report non-executed blocks for lines because statements
+ can easily give rise to non-executed blocks in Ada, e.g. for checks. */
+ const char *const last_dot = strrchr (src->name, '.');
+ if (last_dot)
+ {
+ const char *const ada_suffixes[] = { "ada", "adb", "ads" };
+ const char *const end = src->name + strlen (src->name);
+ for (unsigned int i = 0; i < ARRAY_SIZE (ada_suffixes); i++)
+ if (last_dot + 1 + strlen (ada_suffixes[i]) == end
+ && strcmp (last_dot + 1, ada_suffixes[i]) == 0)
+ {
+ is_ada_file = true;
+ break;
+ }
+ }
+
for (line_num = 1, line = &src->lines[line_num];
line_num < src->lines.size (); line_num++, line++)
{
@@ -2610,7 +2629,8 @@ output_lines (FILE *gcov_file, const sou
There are 16 spaces of indentation added before the source
line so that tabs won't be messed up. */
output_line_beginning (gcov_file, line->exists, line->unexceptional,
- line->has_unexecuted_block, line->count, line_num,
+ line->has_unexecuted_block && !is_ada_file,
+ line->count, line_num,
"=====", "#####");
fprintf (gcov_file, ":%s\n", retval ? retval : "/*EOF*/");