From: Eric Blake <eblake@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
Bug 1881004 <1881004@bugs.launchpad.net>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Bug 1881004] [NEW] fpu/softfloat.c: error: bitwise negation of a boolean expression
Date: Wed, 27 May 2020 16:54:31 -0500 [thread overview]
Message-ID: <ee41069e-5e6f-d4f5-22ed-795deb4b7ba5@redhat.com> (raw)
In-Reply-To: <CAFEAcA_NTEUoWfqpG9uhPY0pE697F-_MDLNexq75k0tYdEuuYg@mail.gmail.com>
On 5/27/20 4:40 PM, Peter Maydell wrote:
> On Wed, 27 May 2020 at 20:21, Philippe Mathieu-Daudé
> <1881004@bugs.launchpad.net> wrote:
>>
>> Public bug reported:
>>
>> Last time I built QEMU was on commit d5c75ec500d96f1d93447f990cd5a4ef5ba27fae,
>> I just pulled to fea8f3ed739536fca027cf56af7f5576f37ef9cd and now 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 );
>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> !
>
>
> "(x & y)" is not a boolean expression, so we should report this to clang
> as a bug (I assume what they actually are trying to complain about is
> bitwise AND with a boolean expression).
We have:
uint64_t &= ~ ( ( ( int8_t ^ int ) == int ) & bool )
which is
uint64_t &= ~ ( bool & bool )
which is then
uint64_t &= ~ ( int )
resulting in one of:
uint64_t &= 0xffffffffffffffff
uint64_t &= 0xfffffffffffffffe
It is a very odd way of stating that 'if this condition is true, mask
out the least-significant-bit'. In general, 'bool & bool' is used where
the side-effect-skipping 'bool && bool' is inappropriate; I'm a bit
surprised that clang is not questioning whether we meant '&&' instead of
'&' (the two operators give the same effect in this case).
You are right that clang is fishy for calling it logical negation of a
bool, when it is really logical negation of an int, but we are also
fishy in that we are using bitwise AND of two bools as an int in the
first place.
Regardless of whether clang changes, would it be better to write the
code as:
if (((roundBits ^ 0x40) == 0) && roundNearestEven) {
absZ &= ~1;
}
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
WARNING: multiple messages have this Message-ID (diff)
From: Eric Blake <1881004@bugs.launchpad.net>
To: qemu-devel@nongnu.org
Subject: Re: [Bug 1881004] [NEW] fpu/softfloat.c: error: bitwise negation of a boolean expression
Date: Wed, 27 May 2020 21:54:31 -0000 [thread overview]
Message-ID: <ee41069e-5e6f-d4f5-22ed-795deb4b7ba5@redhat.com> (raw)
Message-ID: <20200527215431.8JLaqOO5Judtqv0LYi9fCz-JZQM9rEI-PmzfzFrzqNI@z> (raw)
In-Reply-To: CAFEAcA_NTEUoWfqpG9uhPY0pE697F-_MDLNexq75k0tYdEuuYg@mail.gmail.com
On 5/27/20 4:40 PM, Peter Maydell wrote:
> On Wed, 27 May 2020 at 20:21, Philippe Mathieu-Daudé
> <1881004@bugs.launchpad.net> wrote:
>>
>> Public bug reported:
>>
>> Last time I built QEMU was on commit d5c75ec500d96f1d93447f990cd5a4ef5ba27fae,
>> I just pulled to fea8f3ed739536fca027cf56af7f5576f37ef9cd and now 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 );
>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> !
>
>
> "(x & y)" is not a boolean expression, so we should report this to clang
> as a bug (I assume what they actually are trying to complain about is
> bitwise AND with a boolean expression).
We have:
uint64_t &= ~ ( ( ( int8_t ^ int ) == int ) & bool )
which is
uint64_t &= ~ ( bool & bool )
which is then
uint64_t &= ~ ( int )
resulting in one of:
uint64_t &= 0xffffffffffffffff
uint64_t &= 0xfffffffffffffffe
It is a very odd way of stating that 'if this condition is true, mask
out the least-significant-bit'. In general, 'bool & bool' is used where
the side-effect-skipping 'bool && bool' is inappropriate; I'm a bit
surprised that clang is not questioning whether we meant '&&' instead of
'&' (the two operators give the same effect in this case).
You are right that clang is fishy for calling it logical negation of a
bool, when it is really logical negation of an int, but we are also
fishy in that we are using bitwise AND of two bools as an int in the
first place.
Regardless of whether clang changes, would it be better to write the
code as:
if (((roundBits ^ 0x40) == 0) && roundNearestEven) {
absZ &= ~1;
}
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
--
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1881004
Title:
fpu/softfloat.c: error: bitwise negation of a boolean expression
Status in QEMU:
New
Bug description:
Last time I built QEMU was on commit d5c75ec500d96f1d93447f990cd5a4ef5ba27fae,
I just pulled to fea8f3ed739536fca027cf56af7f5576f37ef9cd and now 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:3483: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:3606:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
zSig &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
fpu/softfloat.c:3760:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
zSig &= ~ ( ( ( roundBits ^ 0x200 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
fpu/softfloat.c:3987:21: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
~ ( ( (uint64_t) ( zSig1<<1 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
fpu/softfloat.c:4003:22: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
zSig0 &= ~ ( ( (uint64_t) ( zSig1<<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 );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
8 errors generated.
$ clang -v
clang version 10.0.0-4ubuntu1
Target: aarch64-unknown-linux-gnu
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1881004/+subscriptions
next prev parent reply other threads:[~2020-05-27 21:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-27 19:13 [Bug 1881004] [NEW] fpu/softfloat.c: error: bitwise negation of a boolean expression Philippe Mathieu-Daudé
2020-05-27 21:40 ` Peter Maydell
2020-05-27 21:40 ` Peter Maydell
2020-05-27 21:54 ` Eric Blake [this message]
2020-05-27 21:54 ` Eric Blake
2020-05-28 6:20 ` Thomas Huth
2020-05-28 9:28 ` [Bug 1881004] " Philippe Mathieu-Daudé
2020-06-08 7:17 ` Philippe Mathieu-Daudé
2020-07-20 16:27 ` Peter Maydell
2020-08-20 15:09 ` Thomas Huth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ee41069e-5e6f-d4f5-22ed-795deb4b7ba5@redhat.com \
--to=eblake@redhat.com \
--cc=1881004@bugs.launchpad.net \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.