libgcov: fix TOPN type casting

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.
This commit is contained in:
Martin Liska 2020-06-08 20:07:08 +02:00
parent 009668e31f
commit 862b9b225f
No known key found for this signature in database
GPG Key ID: 4DC182DC0FA73785
2 changed files with 29 additions and 24 deletions

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

View 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)