gcov-tool: fix merge operation for summary

Message ID a5fb462b-da1c-e310-6b4a-3d8bc3ffccbe@suse.cz
State New
Headers show
Series
  • gcov-tool: fix merge operation for summary
Related show

Commit Message

Martin Liška June 25, 2020, 9:26 a.m.
Hi.

The patch is about broken summary merge when gcov-tool is used.

I've just tested the patch and I'm going to push it to master.
Martin

libgcc/ChangeLog:

	* libgcov-driver.c (merge_summary): Remove function as its name
	is misleading and doing something different.
	(dump_one_gcov): Add ATTRIBUTE_UNUSED for 2 args. Take read summary
	in gcov-tool.
	* libgcov-util.c (curr_object_summary): Remove.
	(read_gcda_file): Remove unused curr_object_summary.
	(gcov_merge): Merge summaries.
	* libgcov.h: Add summary argument for gcov_info struct.
---
  libgcc/libgcov-driver.c | 26 +++++++++++---------------
  libgcc/libgcov-util.c   | 11 ++++++-----
  libgcc/libgcov.h        |  1 +
  3 files changed, 18 insertions(+), 20 deletions(-)

-- 
2.27.0

Patch

diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index cbfcae96d19..871b87b867b 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -442,19 +442,6 @@  write_one_data (const struct gcov_info *gi_ptr,
    gcov_write_unsigned (0);
  }
  
-/* Helper function for merging summary.  */
-
-static void
-merge_summary (int run_counted, struct gcov_summary *summary,
-	      gcov_type run_max)
-{
-  if (!run_counted)
-    {
-      summary->runs++;
-      summary->sum_max += run_max;
-    }
-}
-
  /* Dump the coverage counts for one gcov_info object. We merge with existing
     counts when possible, to avoid growing the .da files ad infinitum. We use
     this program's checksum to make sure we only accumulate whole program
@@ -464,7 +451,8 @@  merge_summary (int run_counted, struct gcov_summary *summary,
  
  static void
  dump_one_gcov (struct gcov_info *gi_ptr, struct gcov_filename *gf,
-	       unsigned run_counted, gcov_type run_max)
+	       unsigned run_counted ATTRIBUTE_UNUSED,
+	       gcov_type run_max ATTRIBUTE_UNUSED)
  {
    struct gcov_summary summary = {};
    int error;
@@ -492,7 +480,15 @@  dump_one_gcov (struct gcov_info *gi_ptr, struct gcov_filename *gf,
  
    gcov_rewrite ();
  
-  merge_summary (run_counted, &summary, run_max);
+#if !IN_GCOV_TOOL
+  if (!run_counted)
+    {
+      summary.runs++;
+      summary.sum_max += run_max;
+    }
+#else
+  summary = gi_ptr->summary;
+#endif
  
    write_one_data (gi_ptr, &summary);
    /* fall through */
diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c
index 224c190ee63..09e34f0a33a 100644
--- a/libgcc/libgcov-util.c
+++ b/libgcc/libgcov-util.c
@@ -80,8 +80,6 @@  static int k_ctrs_mask[GCOV_COUNTERS];
  static struct gcov_ctr_info k_ctrs[GCOV_COUNTERS];
  /* Number of kind of counters that have been seen.  */
  static int k_ctrs_types;
-/* The object summary being processed.  */
-static struct gcov_summary *curr_object_summary;
  
  /* Merge functions for counters.  */
  #define DEF_GCOV_COUNTER(COUNTER, NAME, FN_TYPE) __gcov_merge ## FN_TYPE,
@@ -225,8 +223,7 @@  tag_counters (unsigned tag, unsigned length)
  static void
  tag_summary (unsigned tag ATTRIBUTE_UNUSED, unsigned length ATTRIBUTE_UNUSED)
  {
-  curr_object_summary = (gcov_summary *) xcalloc (sizeof (gcov_summary), 1);
-  gcov_read_summary (curr_object_summary);
+  gcov_read_summary (&curr_gcov_info->summary);
  }
  
  /* This function is called at the end of reading a gcda file.
@@ -300,7 +297,6 @@  read_gcda_file (const char *filename)
    obstack_init (&fn_info);
    num_fn_info = 0;
    curr_fn_info = 0;
-  curr_object_summary = NULL;
    {
      size_t len = strlen (filename) + 1;
      char *str_dup = (char*) xmalloc (len);
@@ -584,6 +580,11 @@  gcov_merge (struct gcov_info *info1, struct gcov_info *info2, int w)
    int has_mismatch = 0;
  
    gcc_assert (info2->n_functions == n_functions);
+
+  /* Merge summary.  */
+  info1->summary.runs += info2->summary.runs;
+  info1->summary.sum_max += info2->summary.sum_max;
+
    for (f_ix = 0; f_ix < n_functions; f_ix++)
      {
        unsigned t_ix;
diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h
index ffa9a690af4..81e18950a50 100644
--- a/libgcc/libgcov.h
+++ b/libgcc/libgcov.h
@@ -217,6 +217,7 @@  struct gcov_info
                                                    to function information  */
  #else
    struct gcov_fn_info **functions;
+  struct gcov_summary summary;
  #endif /* !IN_GCOV_TOOL */
  };