From owner-freebsd-hackers@freebsd.org Thu Jan 11 13:37:35 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A3899E62097 for ; Thu, 11 Jan 2018 13:37:35 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [87.251.56.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 65A4A70863 for ; Thu, 11 Jan 2018 13:37:35 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from coleburn.avinity.tv (unknown [77.95.97.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 99432470A2; Thu, 11 Jan 2018 14:37:26 +0100 (CET) From: Dimitry Andric Message-Id: Content-Type: multipart/signed; boundary="Apple-Mail=_6E5DDFDF-BE48-4DCC-8E7E-427B9DF92CAF"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: 1 << 31 redux Date: Thu, 11 Jan 2018 14:37:25 +0100 In-Reply-To: Cc: Eitan Adler , FreeBSD Hackers To: Ed Schouten References: X-Mailer: Apple Mail (2.3273) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jan 2018 13:37:35 -0000 --Apple-Mail=_6E5DDFDF-BE48-4DCC-8E7E-427B9DF92CAF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 11 Jan 2018, at 13:05, Ed Schouten wrote: >=20 > 2018-01-11 13:03 GMT+01:00 Eitan Adler : >> I'd also like to see if we could find some more general solution, be = it a >> compiler warning, bit set macro, or otherwise. >=20 > Does Clang already offer a warning for this? If so, we should consider > adding it to WARNS=3D6. There is a -Wshift-sign-overflow flag, but it isn't enabled by default: $ clang -Wshift-sign-overflow -c bar.c bar.c:1:26: warning: signed shift result (0x80000000) sets the sign bit = of the shift expression's type ('int') and becomes negative = [-Wshift-sign-overflow] int bar(void) { return 1 << 31; } ~ ^ ~~ I would expect quite a lot of stuff to break if you enable it, though. = :) And of course, there is -fsanitize=3Dundefined, which can catch this = kind of thing at runtime. -Dimitry --Apple-Mail=_6E5DDFDF-BE48-4DCC-8E7E-427B9DF92CAF Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.2 iF0EARECAB0WIQR6tGLSzjX8bUI5T82wXqMKLiCWowUCWldolQAKCRCwXqMKLiCW o19IAJ9ixD8oHFm42FnA5Xb6U5NKCE+E3gCbBHLqNDN8M01JnPjSLzSl6D+0CkA= =8FrU -----END PGP SIGNATURE----- --Apple-Mail=_6E5DDFDF-BE48-4DCC-8E7E-427B9DF92CAF--