Vs clang-10 and gcc-9 warnings
v4 cover Vs clang-10 and gcc-9 warnings
Three of these patches are for cleaning up warnings vs clang-10.
All of the patches from v3 are reviewed. The final patch is new, fixing a problem in "make check" (which I was clearly lax in not seeing before).
r~
Philippe Mathieu-Daudé (1):
fpu/softfloat: Silence 'bitwise negation of boolean expression'
warning
Richard Henderson (4):
configure: Clean up warning flag lists
configure: Disable -Wtautological-type-limit-compare
configure: Add -Wno-psabi
qht: Fix threshold rate calculation
Wei Wang (1):
migration: fix xbzrle encoding rate calculation
configure | 44 +++++++++++++++++++++++++++++++++---------- fpu/softfloat.c | 33 +++++++++++++++++++++++--------- migration/ram.c | 4 +--- tests/qht-bench.c | 3 ++- tests/plugin/Makefile | 2 +- 5 files changed, 62 insertions(+), 24 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 1/6 fpu/softfloat: Silence 'bitwise negation of boolean expression' warning
From: Philippe Mathieu-Daudé <[email protected]>
When building with clang version 10.0.0-4ubuntu1, we get:
CC lm32-softmmu/fpu/softfloat.o
fpu/softfloat.c:3365:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
absZ &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fpu/softfloat.c:3423:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
absZ0 &= ~ ( ( (uint64_t) ( absZ1<<1 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
fpu/softfloat.c:4273:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
zSig1 &= ~ ( ( zSig2 + zSig2 == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Fix by rewriting the fishy bitwise AND of two bools as an int.
Message-Id: <[email protected]>
--- fpu/softfloat.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)
fpu/softfloat.c +24 -9
@@ -3362,7 +3362,9 @@ static int32_t roundAndPackInt32(bool zSign, uint64_t absZ, } roundBits = absZ &0x7F ; absZ = ( absZ + roundIncrement )>>7 ; - absZ &= ~ ( ( ( roundBits ^0x40 ) ==0 ) & roundNearestEven ); +if (!(roundBits ^0x40 ) && roundNearestEven) { + absZ &= ~1 ; + } z = absZ;if ( zSign ) z = - z;if ( ( absZ>>32 ) || ( z && ( ( z <0 ) ^ zSign ) ) ) {
@@ -3420,7 +3422,9 @@ static int64_t roundAndPackInt64(bool zSign, uint64_t absZ0, uint64_t absZ1,if ( increment ) { ++absZ0;if ( absZ0 ==0 ) goto overflow; - absZ0 &= ~ ( ( (uint64_t ) ( absZ1<<1 ) ==0 ) & roundNearestEven ); +if (!(absZ1 <<1 ) && roundNearestEven) { + absZ0 &= ~1 ; + } } z = absZ0;if ( zSign ) z = - z;
@@ -3480,7 +3484,9 @@ static int64_t roundAndPackUint64(bool zSign, uint64_t absZ0,float_raise (float_flag_invalid, status);return UINT64_MAX ; } - absZ0 &= ~(((uint64_t )(absZ1<<1 ) ==0 ) & roundNearestEven); +if (!(absZ1 <<1 ) && roundNearestEven) { + absZ0 &= ~1 ; + } }if (zSign && absZ0) {
@@ -3603,7 +3609,9 @@ static float32 roundAndPackFloat32(bool zSign, int zExp, uint32_t zSig, status->float_exception_flags |= float_flag_inexact; } zSig = ( zSig + roundIncrement )>>7 ; - zSig &= ~ ( ( ( roundBits ^0x40 ) ==0 ) & roundNearestEven ); +if (!(roundBits ^0x40 ) && roundNearestEven) { + zSig &= ~1 ; + }if ( zSig ==0 ) zExp =0 ;return packFloat32 ( zSign, zExp, zSig );
@@ -3757,7 +3765,9 @@ static float64 roundAndPackFloat64(bool zSign, int zExp, uint64_t zSig, status->float_exception_flags |= float_flag_inexact; } zSig = ( zSig + roundIncrement )>>10 ; - zSig &= ~ ( ( ( roundBits ^0x200 ) ==0 ) & roundNearestEven ); +if (!(roundBits ^0x200 ) && roundNearestEven) { + zSig &= ~1 ; + }if ( zSig ==0 ) zExp =0 ;return packFloat64 ( zSign, zExp, zSig );
@@ -3983,8 +3993,9 @@ floatx80 roundAndPackFloatx80(int8_t roundingPrecision, bool zSign, }if ( increment ) { ++zSig0; - zSig0 &= - ~ ( ( (uint64_t ) ( zSig1<<1 ) ==0 ) & roundNearestEven ); +if (!(zSig1 <<1 ) && roundNearestEven) { + zSig0 &= ~1 ; + }if ( (int64_t ) zSig0 <0 ) zExp =1 ; }return packFloatx80 ( zSign, zExp, zSig0 );
@@ -4000,7 +4011,9 @@ floatx80 roundAndPackFloatx80(int8_t roundingPrecision, bool zSign, zSig0 =UINT64_C (0x8000000000000000 ); }else { - zSig0 &= ~ ( ( (uint64_t ) ( zSig1<<1 ) ==0 ) & roundNearestEven ); +if (!(zSig1 <<1 ) && roundNearestEven) { + zSig0 &= ~1 ; + } } }else {
@@ -4270,7 +4283,9 @@ static float128 roundAndPackFloat128(bool zSign, int32_t zExp, }if ( increment ) {add128 ( zSig0, zSig1,0 ,1 , &zSig0, &zSig1 ); - zSig1 &= ~ ( ( zSig2 + zSig2 ==0 ) & roundNearestEven ); +if ((zSig2 + zSig2 ==0 ) && roundNearestEven) { + zSig1 &= ~1 ; + } }else {if ( ( zSig0 | zSig1 ) ==0 ) zExp =0 ;
Signature · 1 line
2.25.1
PATCH v4 2/6 migration: fix xbzrle encoding rate calculation
In reply to Richard HendersonFrom: Wei Wang <[email protected]>
It's reported an error of implicit conversion from "unsigned long" to "double" when compiling with Clang 10. Simply make the encoding rate 0 when the encoded_size is 0.
--- migration/ram.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
migration/ram.c +1 -3
@@ -913,10 +913,8 @@ static void migration_update_rates(RAMState *rs, int64_t end_time) unencoded_size = (xbzrle_counters.pages - rs->xbzrle_pages_prev) *TARGET_PAGE_SIZE ; encoded_size = xbzrle_counters.bytes - rs->xbzrle_bytes_prev; -if (xbzrle_counters.pages == rs->xbzrle_pages_prev) { +if (xbzrle_counters.pages == rs->xbzrle_pages_prev || !encoded_size) { xbzrle_counters.encoding_rate =0 ; - }else if (!encoded_size) { - xbzrle_counters.encoding_rate =UINT64_MAX ; }else { xbzrle_counters.encoding_rate = unencoded_size / encoded_size; }
Signature · 1 line
2.25.1
PATCH v4 3/6 configure: Clean up warning flag lists
In reply to Richard HendersonUse a helper function to tidy the assembly of gcc_flags. Separate flags that disable warnings from those that enable, and sort the disable warnings to the end.
--- configure | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-)
configure +32 -10
@@ -97,6 +97,11 @@ do_cxx() { do_compiler "$cxx" "$@" } +# Append $2 to the variable named $1, with space separation +add_to() { + eval $1=\${$1:+\"\$$1 \"}\$2 +} + update_cxxflags() { # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those # options which some versions of GCC's C++ compiler complain about
@@ -2024,16 +2029,33 @@ if ! compile_prog "" "" ; then error_exit "You need at least GCC v4.8 or Clang v3.4 (or XCode Clang v5.1)" fi -gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits" -gcc_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $gcc_flags" -gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags" -gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags" -gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags" -gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags" -# Note that we do not add -Werror to gcc_flags here, because that would -# enable it for all configure tests. If a configure test failed due -# to -Werror this would just silently disable some features, -# so it's too error prone. +# Accumulate -Wfoo and -Wno-bar separately. +# We will list all of the enable flags first, and the disable flags second. +# Note that we do not add -Werror, because that would enable it for all +# configure tests. If a configure test failed due to -Werror this would +# just silently disable some features, so it's too error prone. + +warn_flags= +add_to warn_flags -Wold-style-declaration +add_to warn_flags -Wold-style-definition +add_to warn_flags -Wtype-limits +add_to warn_flags -Wformat-security +add_to warn_flags -Wformat-y2k +add_to warn_flags -Winit-self +add_to warn_flags -Wignored-qualifiers +add_to warn_flags -Wempty-body +add_to warn_flags -Wnested-externs +add_to warn_flags -Wendif-labels +add_to warn_flags -Wexpansion-to-defined + +nowarn_flags= +add_to nowarn_flags -Wno-initializer-overrides +add_to nowarn_flags -Wno-missing-include-dirs +add_to nowarn_flags -Wno-shift-negative-value +add_to nowarn_flags -Wno-string-plus-int +add_to nowarn_flags -Wno-typedef-redefinition + +gcc_flags="$warn_flags $nowarn_flags" cc_has_warning_flag() { write_c_skeleton;
Signature · 1 line
2.25.1
PATCH v4 4/6 configure: Disable -Wtautological-type-limit-compare
In reply to Richard HendersonClang 10 enables this by default with -Wtype-limit.
All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.
--- configure | 1 + 1 file changed, 1 insertion(+)
configure +1 -0
@@ -2054,6 +2054,7 @@ add_to nowarn_flags -Wno-missing-include-dirs add_to nowarn_flags -Wno-shift-negative-value add_to nowarn_flags -Wno-string-plus-int add_to nowarn_flags -Wno-typedef-redefinition +add_to nowarn_flags -Wno-tautological-type-limit-compare gcc_flags="$warn_flags $nowarn_flags"
Signature · 1 line
2.25.1
PATCH v4 5/6 configure: Add -Wno-psabi
In reply to Richard HendersonOn aarch64, gcc 9.3 is generating
qemu/exec.c: In function ‘address_space_translate_iommu’:qemu/exec.c:431:28: note: parameter passing for argument of type \
‘MemTxAttrs’ {aka ‘struct MemTxAttrs’} changed in GCC 9.1
and many other repetitions. This structure, and the functions amongst which it is passed, are not part of a QEMU public API. Therefore we do not care how the compiler passes the argument, so long as the compiler is self-consistent.
The only portion of QEMU which does have a public api, and so must have a stable abi, is "qemu/plugin.h". We test this by forcing -Wpsabi in tests/plugin/Makefile.
--- configure | 1 + tests/plugin/Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
configure +1 -0
@@ -2055,6 +2055,7 @@ add_to nowarn_flags -Wno-shift-negative-value add_to nowarn_flags -Wno-string-plus-int add_to nowarn_flags -Wno-typedef-redefinition add_to nowarn_flags -Wno-tautological-type-limit-compare +add_to nowarn_flags -Wno-psabi gcc_flags="$warn_flags $nowarn_flags"
tests/plugin/Makefile +1 -1
@@ -17,7 +17,7 @@ NAMES += lockstep SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) -QEMU_CFLAGS += -fPIC +QEMU_CFLAGS += -fPIC -Wpsabi QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu all: $(SONAMES)
Signature · 1 line
2.25.1
PATCH v4 6/6 qht: Fix threshold rate calculation
In reply to Richard Hendersontests/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;
~ ^~~~~~~~~~Fix this by splitting the 64-bit constant into two halves, each of which is individually perfectly representable, the sum of which produces the correct arithmetic result.
---
Question: Should we really be scaling by UINT64_MAX?
The comparisons against info->r mean that 1.0 is exceedingly unlikely to hit. Or if that is supposed to be the point, why is is the test
r >= threshold
not
r > threshold
where, if threshold == UINT64_MAX, there is zero chance of the test being true for 1.0.
--- tests/qht-bench.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qht-bench.c +2 -1
@@ -284,7 +284,8 @@ static void do_threshold(double rate, uint64_t *threshold)if (rate ==1.0 ) { *threshold =UINT64_MAX ; }else { - *threshold = rate *UINT64_MAX ; + *threshold = (rate *0xffff000000000000ull ) + + (rate *0x0000ffffffffffffull ); } }
Signature · 1 line
2.25.1
Re: [PATCH v4 6/6] qht: Fix threshold rate calculation
tests/qht-bench.c static void do_threshold(double rate, uint64_t *threshold) · line 288
Quoted 3 lines · Richard Henderson
tests/qht-bench.c +2
-1- *threshold = rate *UINT64_MAX ; + *threshold = (rate *0xffff000000000000ull ) + + (rate *0x0000ffffffffffffull );
Well, while this does silence the warning, it produces the exact same results as before, since the intermediate double result still only has 53 bits of precision.
We're probably be better off with the nextafter(0x1p64, 0.0) form that we've used elsewhere.
r~
Re: [PATCH v4 6/6] qht: Fix threshold rate calculation
Quoted 6 lines · Richard Henderson
tests/qht-bench.c static void do_threshold(double rate, uint64_t *threshold) · line 288
Quoted 3 lines · Richard Henderson
tests/qht-bench.c +2
-1- *threshold = rate *UINT64_MAX ; + *threshold = (rate *0xffff000000000000ull ) + + (rate *0x0000ffffffffffffull );
Quoted 6 lines
Well, while this does silence the warning, it produces the exact same results as before, since the intermediate double result still only has 53 bits of precision.
We're probably be better off with the
nextafter(0x1p64, 0.0)form that we've used elsewhere.
Yeah, the code does look a bit odd. I'm going to apply this one to master as well just to suppress all the patchew nagmails, but we should figure out the correct thing to do here.
thanks
-- PMM
Quoted 6 lines · Richard Henderson
Three of these patches are for cleaning up warnings vs clang-10.
All of the patches from v3 are reviewed. The final patch is new, fixing a problem in "make check" (which I was clearly lax in not seeing before).
I've applied patches 1-5 to master in the hope that they might make patchew's asan builder happier, though it might still fail on the issue patch 6 is trying to address.
thanks
-- PMM