]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgcov: fix TOPN type casting
authorMartin Liska <mliska@suse.cz>
Mon, 8 Jun 2020 18:07:08 +0000 (20:07 +0200)
committerMartin Liska <mliska@suse.cz>
Tue, 9 Jun 2020 11:07:41 +0000 (13:07 +0200)
The patch fixes tree-prof.exp tests on solaris11 and i686-linux-gnu,
problem was that sizeof of a pointer is different from sizeof gcov_type.

I'm going to install it if there are no objections.
Thanks,
Martin

libgcc/ChangeLog:

PR gcov-profile/95494
* libgcov-driver.c (write_top_counters): Cast first to
intptr_t as sizeof(*) != sizeof(gcov_type).
* libgcov.h (gcov_counter_set_if_null): Remove.
(gcov_topn_add_value): Cast first to intptr_t and update
linked list directly.

libgcc/libgcov-driver.c
libgcc/libgcov.h

index 8348d9f33ecd95fbd730dada0a3c8aba47c34de1..cbfcae96d19de66c7902ba30c5c94400a150a708 100644 (file)
@@ -352,8 +352,8 @@ write_top_counters (const struct gcov_ctr_info *ci_ptr,
       gcov_type pair_count = ci_ptr->values[GCOV_TOPN_MEM_COUNTERS * i + 1];
       gcov_write_counter (ci_ptr->values[GCOV_TOPN_MEM_COUNTERS * i]);
       gcov_write_counter (pair_count);
-      for (struct gcov_kvp *node
-          = (struct gcov_kvp *)ci_ptr->values[GCOV_TOPN_MEM_COUNTERS * i + 2];
+      gcov_type start = ci_ptr->values[GCOV_TOPN_MEM_COUNTERS * i + 2];
+      for (struct gcov_kvp *node = (struct gcov_kvp *)(intptr_t)start;
           node != NULL; node = node->next)
        {
          gcov_write_counter (node->value);
index 1456100815da0beb1e55f25be3aa9a0132c5a519..5d237a4c73048bbb2b4a327659e5f767128cc4b4 100644 (file)
@@ -401,24 +401,6 @@ gcov_counter_add (gcov_type *counter, gcov_type value,
     *counter += value;
 }
 
-/* Set NODE to memory location COUNTER and make it with atomic operation
-   if USE_ATOMIC is true.  */
-
-static inline int
-gcov_counter_set_if_null (gcov_type *counter, struct gcov_kvp *node,
-                         int use_atomic ATTRIBUTE_UNUSED)
-{
-#if GCOV_SUPPORTS_ATOMIC
-  if (use_atomic)
-    return !__sync_val_compare_and_swap (counter, NULL, (intptr_t)node);
-  else
-#endif
-    {
-      *counter = (intptr_t)node;
-      return 1;
-    }
-}
-
 /* Add key value pair VALUE:COUNT to a top N COUNTERS.  When INCREMENT_TOTAL
    is true, add COUNT to total of the TOP counter.  If USE_ATOMIC is true,
    do it in atomic way.  */
@@ -432,7 +414,7 @@ gcov_topn_add_value (gcov_type *counters, gcov_type value, gcov_type count,
 
   struct gcov_kvp *prev_node = NULL;
   struct gcov_kvp *minimal_node = NULL;
-  struct gcov_kvp *current_node  = (struct gcov_kvp *)counters[2];
+  struct gcov_kvp *current_node  = (struct gcov_kvp *)(intptr_t)counters[2];
 
   while (current_node)
     {
@@ -467,10 +449,33 @@ gcov_topn_add_value (gcov_type *counters, gcov_type value, gcov_type count,
 
       int success = 0;
       if (!counters[2])
-       success = gcov_counter_set_if_null (&counters[2], new_node, use_atomic);
+       {
+#if GCOV_SUPPORTS_ATOMIC
+         if (use_atomic)
+           {
+             struct gcov_kvp **ptr = (struct gcov_kvp **)(intptr_t)&counters[2];
+             success = !__sync_val_compare_and_swap (ptr, 0, new_node);
+           }
+         else
+#endif
+           {
+             counters[2] = (intptr_t)new_node;
+             success = 1;
+           }
+       }
       else if (prev_node && !prev_node->next)
-       success = gcov_counter_set_if_null ((gcov_type *)&prev_node->next,
-                                           new_node, use_atomic);
+       {
+#if GCOV_SUPPORTS_ATOMIC
+         if (use_atomic)
+           success = !__sync_val_compare_and_swap (&prev_node->next, 0,
+                                                   new_node);
+         else
+#endif
+           {
+             prev_node->next = new_node;
+             success = 1;
+           }
+       }
 
       /* Increment number of nodes.  */
       if (success)