From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 72CDC384F025; Thu, 9 Jun 2022 21:26:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72CDC384F025 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/azanella/clang] benchtest: Fix clang issues on benchmarks build X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/azanella/clang X-Git-Oldrev: 33c24f2a7fb49505e5176c76d211889fd029a5b2 X-Git-Newrev: e5462edbf3cf839c7b603f621ac479bc8703252f Message-Id: <20220609212627.72CDC384F025@sourceware.org> Date: Thu, 9 Jun 2022 21:26:27 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jun 2022 21:26:27 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e5462edbf3cf839c7b603f621ac479bc8703252f commit e5462edbf3cf839c7b603f621ac479bc8703252f Author: Adhemerval Zanella Date: Mon Apr 4 09:35:29 2022 -0300 benchtest: Fix clang issues on benchmarks build Diff: --- benchtests/bench-malloc-thread.c | 6 ++++++ benchtests/bench-pthread-locks.c | 14 +++++++++++--- benchtests/bench-pthread-mutex-locks.c | 14 +++++++++++--- benchtests/bench-strchr.c | 9 ++++++++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/benchtests/bench-malloc-thread.c b/benchtests/bench-malloc-thread.c index 81228392ef..04a9c631e7 100644 --- a/benchtests/bench-malloc-thread.c +++ b/benchtests/bench-malloc-thread.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "bench-timing.h" #include "json-lib.h" @@ -63,7 +64,12 @@ get_block_size (unsigned int rand_data) float min_pow = powf (dist_min, exponent + 1); float max_pow = powf (dist_max, exponent + 1); + /* clang warns that converting from int to float (upper_bound) changes value + from 2147483647 to 2147483648. It does not matter in tests below. */ + DIAG_PUSH_NEEDS_COMMENT_CLANG; + DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wimplicit-const-int-float-conversion"); float r = (float) rand_data / RAND_MAX; + DIAG_POP_NEEDS_COMMENT_CLANG; return (unsigned int) powf ((max_pow - min_pow) * r + min_pow, 1 / (exponent + 1)); diff --git a/benchtests/bench-pthread-locks.c b/benchtests/bench-pthread-locks.c index d7419f511c..e57c122120 100644 --- a/benchtests/bench-pthread-locks.c +++ b/benchtests/bench-pthread-locks.c @@ -61,8 +61,12 @@ typedef timing_t (*test_t)(long, int); total time each test iteration takes, so as to not swamp the useful timings. */ -#pragma GCC push_options -#pragma GCC optimize(1) +#ifdef __clang__ +# pragma clang optimize off +#else +# pragma GCC push_options +# pragma GCC optimize(1) +#endif static int __attribute__((noinline)) fibonacci (int i) @@ -81,7 +85,11 @@ do_filler (void) memcpy (buf1, buf2, f); } -#pragma GCC pop_options +#ifdef __clang__ +# pragma clang optimize on +#else +# pragma GCC pop_options +#endif static timing_t test_mutex (long iters, int filler) diff --git a/benchtests/bench-pthread-mutex-locks.c b/benchtests/bench-pthread-mutex-locks.c index 1685b9dd1f..00b2ed32b0 100644 --- a/benchtests/bench-pthread-mutex-locks.c +++ b/benchtests/bench-pthread-mutex-locks.c @@ -37,8 +37,12 @@ static pthread_barrier_t barrier; #define START_ITERS 1000 -#pragma GCC push_options -#pragma GCC optimize(1) +#ifdef __clang__ +# pragma clang optimize off +#else +# pragma GCC push_options +# pragma GCC optimize(1) +#endif static int __attribute__ ((noinline)) fibonacci (int i) { @@ -64,7 +68,11 @@ do_filler_shared (void) memcpy (buf1, buf2, f); } -#pragma GCC pop_options +#ifdef __clang__ +# pragma clang optimize on +#else +# pragma GCC pop_options +#endif #define UNIT_WORK_CRT do_filler_shared () #define UNIT_WORK_NON_CRT do_filler () diff --git a/benchtests/bench-strchr.c b/benchtests/bench-strchr.c index 54c5c283ae..a417131e2c 100644 --- a/benchtests/bench-strchr.c +++ b/benchtests/bench-strchr.c @@ -16,6 +16,8 @@ License along with the GNU C Library; if not, see . */ +#include + #define TEST_MAIN #ifndef WIDE # ifdef USE_FOR_STRCHRNUL @@ -98,7 +100,7 @@ do_one_rand_plus_branch_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, const CHAR *c) { size_t i, iters = INNER_LOOP_ITERS_LARGE; - int must_execute = 0; + volatile int must_execute = 0; timing_t start, stop, cur; TIMING_NOW (start); for (i = 0; i < iters; ++i) @@ -163,7 +165,12 @@ do_rand_test (json_ctx_t *json_ctx, size_t align, size_t pos, size_t len, buf[align + len] = 0; buf[align + pos] = 1; + /* clang warns that converting from int to float (upper_bound) changes value + from 2147483647 to 2147483648. It does not matter in tests below. */ + DIAG_PUSH_NEEDS_COMMENT_CLANG; + DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wimplicit-const-int-float-conversion"); perc_zero_int = perc_zero * RAND_MAX; + DIAG_POP_NEEDS_COMMENT_CLANG; for (i = 0; i < NUM_SEARCH_CHARS; ++i) { if (rand () > perc_zero_int)