Re: [RFC PATCH] compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use

From: Peter Zijlstra
Date: Thu Aug 01 2019 - 08:25:35 EST


On Wed, Jul 31, 2019 at 01:02:07PM -0700, Kees Cook wrote:
> On Wed, Jul 31, 2019 at 08:48:32PM +0200, Peter Zijlstra wrote:
> > On Wed, Jul 31, 2019 at 11:24:36AM -0700, hpa@xxxxxxxxx wrote:
> > > >> > +/*
> > > >> > + * Add the pseudo keyword 'fallthrough' so case statement blocks
> > > >> > + * must end with any of these keywords:
> > > >> > + * break;
> > > >> > + * fallthrough;
> > > >> > + * goto <label>;
> > > >> > + * return [expression];
> > > >> > + *
> > > >> > + * gcc: >https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes
> > > >> > + */
> > > >> > +#if __has_attribute(__fallthrough__)
> > > >> > +# define fallthrough __attribute__((__fallthrough__))
> > > >> > +#else
> > > >> > +# define fallthrough do {} while (0) /* fallthrough */
> > > >> > +#endif
> > > >> > +
> >
> > > If the comments are stripped, how would the compiler see them to be
> > > able to issue a warning? I would guess that it is retained or replaced
> > > with some other magic token.
> >
> > Everything that has the warning (GCC-7+/CLANG-9) has that attribute.
>
> I'd like to make sure we don't regress Coverity most of all. If the
> recent updates to the Coverity scanner include support for the attribute
> now, then I'm all for it. :)

IMO Coverity can go pound sand, I never see its output, while I get to
look at the code and GCC output daily.