Skip to contentSkip to conversation

tests/qht-bench: Fix Clang 'int-conversion' warning

PATCH Superseded Philippe Mathieu-Daudé 1 participant 2 messages May 4, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/qht-bench: Fix Clang 'int-conversion' warning

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>:

float nextafterf( float from, float to );

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

---
Cc: Emilio G. Cota <[email protected]>
Cc: Alex Bennée <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Alexander Bulekov <[email protected]>

---
 tests/qht-bench.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qht-bench.c +2 -1
index e3b512f26f..f93f8e0fe2 100644
@@ -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 * nextafterf(0x1p64, 0.0);
     }
 }
 
Signature · 1 line
2.21.3
#1 lore raw
Quoted 45 lines · Philippe Mathieu-Daudé

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>:

float nextafterf( float from, float to );

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

---
Cc: Emilio G. Cota <[email protected]>
Cc: Alex Bennée <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Alexander Bulekov <[email protected]>

---
  tests/qht-bench.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
tests/qht-bench.c +1 -0
index e3b512f26f..f93f8e0fe2 100644
@@ -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;

tests/qht-bench.c static void do_threshold(double rate, uint64_t *threshold) · line 288

Quoted 5 lines
tests/qht-bench.c +1 -1
@@ -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 * nextafterf(0x1p64, 0.0);

NAck since of double type. Will send v2.

Quoted 4 lines
tests/qht-bench.c +0 -0
      }
  }