From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Patch Tracking <patches@linaro.org>,
QEMU Developers <qemu-devel@nongnu.org>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] hw/audio/fmopl.c: Avoid clang warning about shifting negative number
Date: Tue, 17 Nov 2015 11:42:02 +0100 [thread overview]
Message-ID: <564B047A.9030506@redhat.com> (raw)
In-Reply-To: <CAFEAcA_Wvyz6cD3fqTAk8Od4YemyHfZ9SqZO_aB_bzj--5_vFw@mail.gmail.com>
On 17/11/2015 11:17, Peter Maydell wrote:
> If clang is
> warning about it they obviously don't want to guarantee that they
> aren't ever going to rely on this UB for optimisation.
My interpretation is just that clang's diagnostics are not that much
better than GCC anymore, and they feel the need to pump their release
notes with oh so many new -W flags.
Just look at the 3.5 release notes:
New warning -Wabsolute-value: Clang warns about incorrect or useless
usage of the absolute functions (abs, fabsf, etc).
#include <stdlib.h>
void foo() {
unsigned int i=0;
abs(i);
}
returns warning: taking the absolute value of unsigned type
‘unsigned int’ has no effect [-Wabsolute-value]
Wow, haven't you wanted that since kindergarten? :-D
There's no reason not to put this under the existing -Wunused-value,
other than politics.
> I agree that the rephrasing isn't great; if you have a
> preferred non-UB way to write it I'm open to suggestions.
I don't think there's a good way to express it. I guess -0x8000u would
look mildly better, but it is more dangerous so I think overall it's
even worse.
The point is that left shifting of a negative number _is not overflow_
unless that number is less than ("has fewer leading ones than") INT_MIN
>> n. It makes no sense to forbid anything else, if at the same time
you allow signed right shift to be arithmetic shift.
I'm all okay with compilers treating shifts of negative numbers as
undefined behavior if a 0 is shifted into the sign bit.
Paolo
prev parent reply other threads:[~2015-11-17 10:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-16 15:16 [Qemu-devel] [PATCH] hw/audio/fmopl.c: Avoid clang warning about shifting negative number Peter Maydell
2015-11-17 9:45 ` Paolo Bonzini
2015-11-17 10:17 ` Peter Maydell
2015-11-17 10:42 ` Paolo Bonzini [this message]
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=564B047A.9030506@redhat.com \
--to=pbonzini@redhat.com \
--cc=kraxel@redhat.com \
--cc=patches@linaro.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).