* Should templates with multiple instantiations contribute to summaries in gcov?
@ 2022-08-03 16:03 Jørgen Kvalsvik
2022-08-22 19:25 ` [PATCH] gcov: fix file and function summary information Martin Liška
0 siblings, 1 reply; 4+ messages in thread
From: Jørgen Kvalsvik @ 2022-08-03 16:03 UTC (permalink / raw)
To: gcc
I have this program:
#include <cstdio>
template<class T>
T add (T x, T y) {
if (x > y)
return x + y;
else
return x;
}
template<class T>
T sub (T x, T y) {
if (x > y)
return x - y;
else
return x;
}
int main() {
int i1 = 10;
int i2 = 12;
double d1 = 10.0;
double d2 = 12.0;
auto x = add(i1, i2);
auto y = add(d1, d2);
auto z = sub(i2, i1);
printf ("%d %f %d\n", x, y, z);
}
add() is instantiated for int, double, and sub() is only instantiated
for int.
$ gcc -v
gcc version 12.0.1 20220426 (experimental) (GCC)
$ gcc --coverage demo.cc -o demo && ./demo
$ gcov -mfb demo
Function 'int sub<int>(int, int)'
Lines executed:75.00% of 4
Function 'double add<double>(double, double)'
No executable lines
Function 'int add<int>(int, int)'
No executable lines
Function 'main'
Lines executed:100.00% of 10
File 'demo.cc'
Lines executed:88.89% of 18
Branches executed:100.00% of 2
Taken at least once:50.00% of 2
Calls executed:100.00% of 4
Creating 'demo.cc.gcov'
Lines executed:88.89% of 18
So it reports lines and branches accurately for templates with a single
instantiation, but nothing when there are multiple. When you look at the
.gcov file however the branches are reported for all the instantiations:
double add<double>(double, double):
function double add<double>(double, double) called 1 returned 100%
blocks executed 75%
1: 4:T add (T x, T y) {
1: 5: if (x > y)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
#####: 6: return x + y;
-: 7: else
1: 8: return x;
-: 9:}
Skimming gcov.cc I found accumulate_line_info. By applying this patch
the file summary includes all instantiations:
diff --git a/gcc/gcov.cc b/gcc/gcov.cc
index 04bbc774eec..c0ee9d1cd3f 100644
--- a/gcc/gcov.cc
+++ b/gcc/gcov.cc
@@ -2952,7 +2952,7 @@ accumulate_line_counts (source_info *src)
it2 != fn->lines.end (); it2++)
{
line_info *line = &(*it2);
- accumulate_line_info (line, src, false);
+ accumulate_line_info (line, src, true);
}
}
File 'demo.cc'
Lines executed:84.62% of 26
Branches executed:100.00% of 6
Taken at least once:50.00% of 6
Calls executed:100.00% of 4
Creating 'demo.cc.gcov'
It doesn't fix the function summaries however:
Function 'int add<int>(int, int)'
No executable lines
Looking through the changelog it looks like this was introduced to work
with destructors/C++ clones
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48463
Is there a non-obvious downside to look into groups in order to have
templates count towards file- and function summaries? Any subtle
interactions at play? Is this a bug?
Thanks,
Jørgen
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] gcov: fix file and function summary information
2022-08-03 16:03 Should templates with multiple instantiations contribute to summaries in gcov? Jørgen Kvalsvik
@ 2022-08-22 19:25 ` Martin Liška
2022-08-24 7:12 ` Jørgen Kvalsvik
0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2022-08-22 19:25 UTC (permalink / raw)
To: gcc-patches; +Cc: Jørgen Kvalsvik, GCC Development
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Jorgen: Can you please test it before I'll install it?
Thanks,
Martin
gcc/ChangeLog:
* gcov.cc (add_line_counts): Add group functions to coverage
summary.
(accumulate_line_counts): Similarly for files.
Co-Authored-By: Jørgen Kvalsvik <j@lambda.is>
---
gcc/gcov.cc | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/gcc/gcov.cc b/gcc/gcov.cc
index 27be5ff0911..9cf1071166f 100644
--- a/gcc/gcov.cc
+++ b/gcc/gcov.cc
@@ -2694,6 +2694,13 @@ add_line_counts (coverage_info *coverage, function_info *fn)
{
gcc_assert (lines[j] - fn->start_line < fn->lines.size ());
line = &(fn->lines[lines[j] - fn->start_line]);
+ if (coverage)
+ {
+ if (!line->exists)
+ coverage->lines++;
+ if (!line->count && block->count)
+ coverage->lines_executed++;
+ }
line->exists = 1;
if (!block->exceptional)
{
@@ -2815,7 +2822,7 @@ accumulate_line_counts (source_info *src)
it2 != fn->lines.end (); it2++)
{
line_info *line = &(*it2);
- accumulate_line_info (line, src, false);
+ accumulate_line_info (line, src, true);
}
}
--
2.37.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gcov: fix file and function summary information
2022-08-22 19:25 ` [PATCH] gcov: fix file and function summary information Martin Liška
@ 2022-08-24 7:12 ` Jørgen Kvalsvik
2022-08-24 7:31 ` Martin Liška
0 siblings, 1 reply; 4+ messages in thread
From: Jørgen Kvalsvik @ 2022-08-24 7:12 UTC (permalink / raw)
To: Martin Liška, gcc-patches; +Cc: GCC Development
On 22/08/2022 21:25, Martin Liška wrote:
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Jorgen: Can you please test it before I'll install it?
>
> Thanks,
> Martin
>
> gcc/ChangeLog:
>
> * gcov.cc (add_line_counts): Add group functions to coverage
> summary.
> (accumulate_line_counts): Similarly for files.
>
> Co-Authored-By: Jørgen Kvalsvik <j@lambda.is>
> ---
> gcc/gcov.cc | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/gcov.cc b/gcc/gcov.cc
> index 27be5ff0911..9cf1071166f 100644
> --- a/gcc/gcov.cc
> +++ b/gcc/gcov.cc
> @@ -2694,6 +2694,13 @@ add_line_counts (coverage_info *coverage, function_info *fn)
> {
> gcc_assert (lines[j] - fn->start_line < fn->lines.size ());
> line = &(fn->lines[lines[j] - fn->start_line]);
> + if (coverage)
> + {
> + if (!line->exists)
> + coverage->lines++;
> + if (!line->count && block->count)
> + coverage->lines_executed++;
> + }
> line->exists = 1;
> if (!block->exceptional)
> {
> @@ -2815,7 +2822,7 @@ accumulate_line_counts (source_info *src)
> it2 != fn->lines.end (); it2++)
> {
> line_info *line = &(*it2);
> - accumulate_line_info (line, src, false);
> + accumulate_line_info (line, src, true);
> }
> }
>
I tested it and get the file summary as expected:
File 'demo.cc'
Lines executed:84.62% of 26
Branches executed:100.00% of 6
Taken at least once:50.00% of 6
Calls executed:100.00% of 4
Creating 'demo.cc.gcov'
Thanks,
Jørgen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gcov: fix file and function summary information
2022-08-24 7:12 ` Jørgen Kvalsvik
@ 2022-08-24 7:31 ` Martin Liška
0 siblings, 0 replies; 4+ messages in thread
From: Martin Liška @ 2022-08-24 7:31 UTC (permalink / raw)
To: Jørgen Kvalsvik, gcc-patches; +Cc: GCC Development
On 8/24/22 09:12, Jørgen Kvalsvik wrote:
> I tested it and get the file summary as expected:
>
> File 'demo.cc'
> Lines executed:84.62% of 26
> Branches executed:100.00% of 6
> Taken at least once:50.00% of 6
> Calls executed:100.00% of 4
> Creating 'demo.cc.gcov'
>
> Thanks,
> Jørgen
Great, I've just pushed that as revision r13-2166-g42301c02e458cd.
Cheers,
Martin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-24 7:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03 16:03 Should templates with multiple instantiations contribute to summaries in gcov? Jørgen Kvalsvik
2022-08-22 19:25 ` [PATCH] gcov: fix file and function summary information Martin Liška
2022-08-24 7:12 ` Jørgen Kvalsvik
2022-08-24 7:31 ` Martin Liška
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).