From ace43807e322dbdb075e507d9a84e676d4c34c64 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Sat, 14 Nov 2020 13:51:09 +0100 Subject: [PATCH 1/2] gcov: Add and use gcov_are_all_counters_zero() libgcc/ libgcov.h (gcov_are_all_counters_zero): New. libgcov-driver.c (write_one_data): Use gcov_are_all_counters_zero(). --- libgcc/libgcov-driver.c | 12 ++---------- libgcc/libgcov.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index e53e4dc392a..ba308438474 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -428,16 +428,8 @@ write_one_data (const struct gcov_info *gi_ptr, write_top_counters (ci_ptr, t_ix, n_counts); else { - /* Do not stream when all counters are zero. */ - int all_zeros = 1; - for (unsigned i = 0; i < n_counts; i++) - if (ci_ptr->values[i] != 0) - { - all_zeros = 0; - break; - } - - if (all_zeros) + if (gcov_are_all_counters_zero (ci_ptr)) + /* Do not stream when all counters are zero. */ gcov_write_tag_length (GCOV_TAG_FOR_COUNTER (t_ix), GCOV_TAG_COUNTER_LENGTH (-n_counts)); else diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h index e70cf63b414..915a1b1530d 100644 --- a/libgcc/libgcov.h +++ b/libgcc/libgcov.h @@ -304,6 +304,18 @@ extern void __gcov_average_profiler_atomic (gcov_type *, gcov_type); extern void __gcov_ior_profiler (gcov_type *, gcov_type); extern void __gcov_ior_profiler_atomic (gcov_type *, gcov_type); +/* Return 1, if all counter values are zero, otherwise 0. */ + +static inline int +gcov_are_all_counters_zero (const struct gcov_ctr_info *ci_ptr) +{ + for (unsigned i = 0; i < ci_ptr->num; i++) + if (ci_ptr->values[i] != 0) + return 0; + + return 1; +} + #ifndef inhibit_libc /* The wrappers around some library functions.. */ extern pid_t __gcov_fork (void) ATTRIBUTE_HIDDEN; -- 2.26.2