gcov: fix file and function summary information

Message ID 643928f9-d0e0-e099-6846-d3548f14b455@suse.cz
State Committed
Commit 42301c02e458cdce646ffaf7ea1df502ab2e8ddc
Headers
Series gcov: fix file and function summary information |

Commit Message

Martin Liška Aug. 22, 2022, 7:25 p.m. UTC
  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(-)
  

Comments

Jørgen Kvalsvik Aug. 24, 2022, 7:12 a.m. UTC | #1
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
  
Martin Liška Aug. 24, 2022, 7:31 a.m. UTC | #2
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
  

Patch

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);
 	  }
     }