From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCuR0-0006jr-OF for qemu-devel@nongnu.org; Fri, 23 Aug 2013 12:42:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VCuQw-0003MA-13 for qemu-devel@nongnu.org; Fri, 23 Aug 2013 12:42:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2509) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCuQv-0003Lq-Ou for qemu-devel@nongnu.org; Fri, 23 Aug 2013 12:41:57 -0400 Message-ID: <521790D0.1060200@redhat.com> Date: Fri, 23 Aug 2013 10:41:52 -0600 From: Eric Blake MIME-Version: 1.0 References: <1377275745-8942-1-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1377275745-8942-1-git-send-email-peter.maydell@linaro.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2AWgpktf7fdFUTO9SE8SB6fgVrtaC5M2r" Subject: Re: [Qemu-devel] [PATCH] block/qcow2.h: Avoid "1LL << 63" (shifts into sign bit) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , patches@linaro.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --2AWgpktf7fdFUTO9SE8SB6fgVrtaC5M2r Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 08/23/2013 10:35 AM, Peter Maydell wrote: > The expression "1LL << 63" tries to shift the 1 into the sign bit of a > 'long long', which provokes a clang sanitizer warning: >=20 > runtime error: left shift of 1 by 63 places cannot be represented in ty= pe 'long long' Yep, C99 6.5.7p3 states it is undefined to shift a signed number left across the sign bit: "The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. If E1 has an unsigned type, the value of the result is E1 =C3=97 2E2 , reduced modulo one more than the maximum value representable in the result type. If E1 has a signed type and nonnegative value, and E1 =C3=97 2E2 is representable in the result type,= then that is the resulting value; otherwise, the behavior is undefined." Qemu assumes twos-complement arithmetic with sane signed left shifts, but without a way to tell the compiler our assumptions, it's easier to just stick with well-defined unsigned shifts. >=20 > Use "1ULL << 63" as the definition of QCOW_OFLAG_COPIED instead > to avoid this. For consistency, we also update the other QCOW_OFLAG > definitions to use the ULL suffix rather than LL, though only the > shift by 63 is undefined behaviour. >=20 > Signed-off-by: Peter Maydell > --- > block/qcow2.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --2AWgpktf7fdFUTO9SE8SB6fgVrtaC5M2r Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSF5DQAAoJEKeha0olJ0NqENoH/2uxufX9w4Z+It4rAuXM4HGs Gq1c7VTMkpn8m9JnDbdlcPbgKIoDzd0n6eYGctnZANKALn8AzG7r0Sls4hYzJKVD 2fEFA2tLykd3yZOF9d0X3W3HMB+6gGTAmR8x8xM4eJ1t9o7y3ZbdZRGKS9DOKhHt Nj04jmdx8PgU4kO0tObuuhBr4FBTMuYybxY2QyOjS7TPYv3Hsq+LgKeRBgWZF0kG f3RinaYhfGNvqhX5JMHM3eKYpvmQPqbxToKZpjVZlA5Lmlk14QYOHOjoKdzb6QJe dXarS/xyKUNDWTqUtTmPPdI13dAl51KvlCcxJZxDOrE8JY/zq+TtaAt1+f1XNms= =ASku -----END PGP SIGNATURE----- --2AWgpktf7fdFUTO9SE8SB6fgVrtaC5M2r--