From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1hGJ-0005Mv-2I for qemu-devel@nongnu.org; Wed, 25 Nov 2015 16:06:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1hGF-0004Tg-PH for qemu-devel@nongnu.org; Wed, 25 Nov 2015 16:05:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40344) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1hGF-0004Tb-Jb for qemu-devel@nongnu.org; Wed, 25 Nov 2015 16:05:55 -0500 References: <1448471956-66873-1-git-send-email-pbonzini@redhat.com> <1448471956-66873-3-git-send-email-pbonzini@redhat.com> <5655F4CB.10509@redhat.com> <56560C43.6070105@redhat.com> From: Paolo Bonzini Message-ID: <565622AF.5090405@redhat.com> Date: Wed, 25 Nov 2015 22:05:51 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PULL 2/9] QEMU does not care about left shifts of signed negative values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: QEMU Developers On 25/11/2015 20:54, Peter Maydell wrote: > > > Your latest patch at https://gcc.gnu.org/ml/gcc-patches/2015-11/msg= 03055.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=20 -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=20 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 =3D INT_MIN - 1; int z =3D -1 << 2; int w =3D INT_MIN << 1; int u =3D 1 << 31; $ gcc f.c -std=3Dc11 -Wall -pedantic f.c:2:1: warning: overflow in constant expression [-Woverflow] f.c:3:9: warning: initializer element is not a constant expression [-Wped= antic] f.c:4:9: warning: initializer element is not a constant expression [-Wped= antic] f.c:5:9: warning: initializer element is not a constant expression [-Wped= antic] The first warning is activated by -Wall, the others aren't. Paolo