1 << 31 redux
Steve Kargl
sgk at troutmask.apl.washington.edu
Thu Jan 11 19:40:18 UTC 2018
On Thu, Jan 11, 2018 at 08:47:16AM -0700, Warner Losh wrote:
> On Thu, Jan 11, 2018 at 6:37 AM, Dimitry Andric <dim at freebsd.org> wrote:
>
> > On 11 Jan 2018, at 13:05, Ed Schouten <ed at nuxi.nl> wrote:
> > >
> > > 2018-01-11 13:03 GMT+01:00 Eitan Adler <lists at 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.
> > >
> > > Does Clang already offer a warning for this? If so, we should consider
> > > adding it to WARNS=6.
> >
> > 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=undefined, which can catch this kind
> > of thing at runtime.
> >
>
> If we can't get people to fix the warnings we have in the tree now
> (especially the kernel), why enable new warnings that will just be ignored?
Create WARNS=7 with -Werror added to command line option.
Edit the various *.mk files to force WARNS=7
Watch warnings get fixed.
--
Steve
More information about the freebsd-hackers
mailing list