From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values
Date: Wed, 25 Nov 2015 22:05:51 +0100 [thread overview]
Message-ID: <565622AF.5090405@redhat.com> (raw)
In-Reply-To: <CAFEAcA-0DHaavD5i2agfCrTMJDZbydtK22uYegHNr9ESeBsopw@mail.gmail.com>
On 25/11/2015 20:54, Peter Maydell wrote:
> > > Your latest patch at https://gcc.gnu.org/ml/gcc-patches/2015-11/msg03055.html
> > > doesn't seem to touch the documentation of -fwrapv at all, so I
> > > don't think it is sufficient to allow users of the compiler
> > > to say "-fwrapv means signed behaviour for shifts".
> >
> > GCC *always* does signed behavior for shifts, even without -fwrapv.
> > I'll commit tomorrow the patch that promises that for the future.
> >
> > GCC does not need -fwrapv at all.
>
> Yes it does, because without -fwrapv it still wants to warn
> about them. We need to tell the compiler that we really do
> want a C dialect where they have specific behaviour and so no
> warnings are ever correct. By default (as documented, even
> with your patch) GCC just promises that it won't actually
> do undefined behaviour for signed negative shifts. (It doesn't
> even actually say what impdef semantics it does provide,
It says it above the text I changed:
GCC supports only two's complement integer types, and all bit
patterns are ordinary values.
[...]
Bitwise operators act on the representation of the value including
both the sign and value bits, where the sign bit is considered
immediately above the highest-value value bit.
> and in practice the impdef semantics include "warn about
> this", which we don't want.)
No, it doesn't warn with the commonly used options. Only with
-pedantic, which is documented as
Issue all the warnings demanded by strict ISO C and ISO C++;
reject all programs that use forbidden extensions, and some
other programs that do not follow ISO C and ISO C++.
So the combination of -fwrapv and -pedantic is not particularly
interesting. Even then the warning is "initializer element is not
a constant expression"; nothing to do with overflow. For example:
#define INT_MIN ((int)-0x80000000)
int y = INT_MIN - 1;
int z = -1 << 2;
int w = INT_MIN << 1;
int u = 1 << 31;
$ gcc f.c -std=c11 -Wall -pedantic
f.c:2:1: warning: overflow in constant expression [-Woverflow]
f.c:3:9: warning: initializer element is not a constant expression [-Wpedantic]
f.c:4:9: warning: initializer element is not a constant expression [-Wpedantic]
f.c:5:9: warning: initializer element is not a constant expression [-Wpedantic]
The first warning is activated by -Wall, the others aren't.
Paolo
next prev parent reply other threads:[~2015-11-25 21:06 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-25 17:19 [Qemu-devel] [PULL 0/9] Misc patches for QEMU 2.5-rc2 (2015-11-25) Paolo Bonzini
2015-11-25 17:19 ` [Qemu-devel] [PULL 1/9] MAINTAINERS: Update TCG CPU cores section Paolo Bonzini
2015-11-25 17:19 ` [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values Paolo Bonzini
2015-11-25 17:44 ` Peter Maydell
2015-11-25 17:50 ` Paolo Bonzini
2015-11-25 19:18 ` Peter Maydell
2015-11-25 19:30 ` Paolo Bonzini
2015-11-25 19:54 ` Peter Maydell
2015-11-25 21:05 ` Paolo Bonzini [this message]
2015-11-25 21:22 ` Peter Maydell
2015-11-25 17:19 ` [Qemu-devel] [PULL 3/9] call bdrv_drain_all() even if the vm is stopped Paolo Bonzini
2015-11-25 17:19 ` [Qemu-devel] [PULL 4/9] Revert "exec: silence hugetlbfs warning under qtest" Paolo Bonzini
2015-11-25 17:19 ` [Qemu-devel] [PULL 5/9] exec: remove warning about mempath and hugetlbfs Paolo Bonzini
2015-11-25 17:19 ` [Qemu-devel] [PULL 6/9] target-sparc: fix 32-bit truncation in fpackfix Paolo Bonzini
2015-11-25 17:19 ` [Qemu-devel] [PULL 7/9] target-i386: kvm: Abort if MCE bank count is not supported by host Paolo Bonzini
2015-11-25 17:19 ` [Qemu-devel] [PULL 8/9] target-i386: kvm: Use env->mcg_cap when setting up MCE Paolo Bonzini
2015-11-25 17:19 ` [Qemu-devel] [PULL 9/9] target-i386: kvm: Print warning when clearing mcg_cap bits Paolo Bonzini
2015-11-26 9:46 ` [Qemu-devel] [PULL 0/9] Misc patches for QEMU 2.5-rc2 (2015-11-25) Peter Maydell
2015-11-26 10:40 ` Paolo Bonzini
2015-11-26 10:56 ` Peter Maydell
2015-11-26 11:23 ` Paolo Bonzini
2015-11-26 11:28 ` Peter Maydell
2015-11-26 12:15 ` Markus Armbruster
2015-11-26 12:19 ` Peter Maydell
2015-11-26 13:07 ` Paolo Bonzini
2015-11-26 13:04 ` Paolo Bonzini
2015-11-26 15:01 ` Peter Maydell
2015-11-26 15:40 ` Paolo Bonzini
2015-11-26 15:55 ` Peter Maydell
2015-11-26 16:06 ` Paolo Bonzini
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=565622AF.5090405@redhat.com \
--to=pbonzini@redhat.com \
--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.