[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of sign
From: |
Paolo Bonzini |
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 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
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
- [Qemu-devel] [PULL 6/9] target-sparc: fix 32-bit truncation in fpackfix, (continued)
- [Qemu-devel] [PULL 6/9] target-sparc: fix 32-bit truncation in fpackfix, Paolo Bonzini, 2015/11/25
- [Qemu-devel] [PULL 5/9] exec: remove warning about mempath and hugetlbfs, Paolo Bonzini, 2015/11/25
- [Qemu-devel] [PULL 8/9] target-i386: kvm: Use env->mcg_cap when setting up MCE, Paolo Bonzini, 2015/11/25
- [Qemu-devel] [PULL 1/9] MAINTAINERS: Update TCG CPU cores section, Paolo Bonzini, 2015/11/25
- [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values, Paolo Bonzini, 2015/11/25
- Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values, Peter Maydell, 2015/11/25
- Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values, Paolo Bonzini, 2015/11/25
- Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values, Peter Maydell, 2015/11/25
- Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values, Paolo Bonzini, 2015/11/25
- Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values, Peter Maydell, 2015/11/25
- Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values,
Paolo Bonzini <=
- Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values, Peter Maydell, 2015/11/25
[Qemu-devel] [PULL 7/9] target-i386: kvm: Abort if MCE bank count is not supported by host, Paolo Bonzini, 2015/11/25
[Qemu-devel] [PULL 9/9] target-i386: kvm: Print warning when clearing mcg_cap bits, Paolo Bonzini, 2015/11/25
Re: [Qemu-devel] [PULL 0/9] Misc patches for QEMU 2.5-rc2 (2015-11-25), Peter Maydell, 2015/11/26
- Re: [Qemu-devel] [PULL 0/9] Misc patches for QEMU 2.5-rc2 (2015-11-25), Paolo Bonzini, 2015/11/26
- Re: [Qemu-devel] [PULL 0/9] Misc patches for QEMU 2.5-rc2 (2015-11-25), Peter Maydell, 2015/11/26
- Re: [Qemu-devel] [PULL 0/9] Misc patches for QEMU 2.5-rc2 (2015-11-25), Paolo Bonzini, 2015/11/26
- Re: [Qemu-devel] [PULL 0/9] Misc patches for QEMU 2.5-rc2 (2015-11-25), Peter Maydell, 2015/11/26
- Re: [Qemu-devel] [PULL 0/9] Misc patches for QEMU 2.5-rc2 (2015-11-25), Markus Armbruster, 2015/11/26
- Re: [Qemu-devel] [PULL 0/9] Misc patches for QEMU 2.5-rc2 (2015-11-25), Peter Maydell, 2015/11/26