Date: Thu, 11 Jan 2018 14:37:25 +0100 From: Dimitry Andric <dim@FreeBSD.org> To: Ed Schouten <ed@nuxi.nl> Cc: Eitan Adler <lists@eitanadler.com>, FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: 1 << 31 redux Message-ID: <CA37BE71-935C-4349-AFEF-B98160460FFE@FreeBSD.org> In-Reply-To: <CABh_MKmy3ojYO3M6YwH2wWrEp5a4C-o2XC1icN%2BNj3GDo4f%2BZA@mail.gmail.com> References: <CAF6rxg=GbfpBfPAAJg0RvpMrWW8p%2B0Ayf_Zd9i7Em2kOijFCjA@mail.gmail.com> <CABh_MKmy3ojYO3M6YwH2wWrEp5a4C-o2XC1icN%2BNj3GDo4f%2BZA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <ed@nuxi.nl> wrote: >=20 > 2018-01-11 13:03 GMT+01:00 Eitan Adler <lists@eitanadler.com>: >> 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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA37BE71-935C-4349-AFEF-B98160460FFE>