qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] tests/qht-bench: Fix Clang 'int-conversion' warning


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v2] tests/qht-bench: Fix Clang 'int-conversion' warning
Date: Mon, 4 May 2020 16:43:19 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

Wrong subject =) v3 coming...

On 5/4/20 4:41 PM, Philippe Mathieu-Daudé wrote:
When building with Clang 10 on Fedora 32, we get:

   tests/qht-bench.c:287:29: error: implicit conversion from 'unsigned long' to 
'double' changes value from 18446744073709551615 to 18446744073709551616 
[-Werror,-Wimplicit-int-float-conversion]
           *threshold = rate * UINT64_MAX;
                             ~ ^~~~~~~~~~
   /usr/include/stdint.h:130:23: note: expanded from macro 'UINT64_MAX'
   # define UINT64_MAX             (__UINT64_C(18446744073709551615))
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   /usr/include/stdint.h:107:25: note: expanded from macro '__UINT64_C'
   #  define __UINT64_C(c) c ## UL
                           ^~~~~~~
   <scratch space>:14:1: note: expanded from here
   18446744073709551615UL
   ^~~~~~~~~~~~~~~~~~~~~~

Fix by using nextafter() from <math.h>:

   double nextafter( double from, double to );

       Returns the next representable value of 'from'
       in the direction of 'to'.

Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
Since v1: nextafterf() -> nextafter()

Cc: Emilio G. Cota <address@hidden>
Cc: Alex Bennée <address@hidden>
Cc: Richard Henderson <address@hidden>
Cc: Alexander Bulekov <address@hidden>
---
  tests/qht-bench.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/qht-bench.c b/tests/qht-bench.c
index e3b512f26f..54ce1e8188 100644
--- a/tests/qht-bench.c
+++ b/tests/qht-bench.c
@@ -10,6 +10,7 @@
  #include "qemu/qht.h"
  #include "qemu/rcu.h"
  #include "qemu/xxhash.h"
+#include <math.h>
struct thread_stats {
      size_t rd;
@@ -284,7 +285,7 @@ static void do_threshold(double rate, uint64_t *threshold)
      if (rate == 1.0) {
          *threshold = UINT64_MAX;
      } else {
-        *threshold = rate * UINT64_MAX;
+        *threshold = rate * nextafter(0x1p64, 0.0);
      }
  }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]