linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: Kees Cook <keescook@chromium.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Borislav Petkov <bp@alien8.de>, "H . Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Pavel Machek <pavel@ucw.cz>,
	"Gustavo A . R . Silva" <gustavo@embeddedor.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Kan Liang <kan.liang@linux.intel.com>,
	Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@redhat.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Shawn Landden <shawn@git.icu>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	Neil Horman <nhorman@tuxdriver.com>,
	David Miller <davem@davemloft.net>
Subject: Re: [RFC PATCH] compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use
Date: Sun, 04 Aug 2019 11:01:10 -0700	[thread overview]
Message-ID: <c0669a7130645a20e99915385b7e712360c31ed9.camel@perches.com> (raw)
In-Reply-To: <1d2830aadbe9d8151728a7df5b88528fc72a0095.1564549413.git.joe@perches.com>

On Tue, 2019-07-30 at 22:35 -0700, Joe Perches wrote:
> Reserve the pseudo keyword 'fallthrough' for the ability to convert the
> various case block /* fallthrough */ style comments to appear to be an
> actual reserved word with the same gcc case block missing fallthrough
> warning capability.

Linus?  Do you have an opinion about this RFC/patch?

> All switch/case blocks now must end in one of:
> 
> 	break;
> 	fallthrough;
> 	goto <label>;
> 	return [expression];
> 
> fallthough is gcc's __attribute__((__fallthrough__)) which was introduced
> in gcc version 7..
> 
> fallthrough devolves to an empty "do {} while (0)" if the compiler version
> (any version less than gcc 7) does not support the attribute.
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
> 
> For allow compilation of a kernel that includes net/sctp, this patch
> also requires a rename of the use of fallthrough as a label in
> net/sctp/sm_make_chunk.c that was submitted as:
> 
> https://lore.kernel.org/lkml/e0dd3af448e38e342c1ac6e7c0c802696eb77fd6.1564549413.git.joe@perches.com/
> 
>  include/linux/compiler_attributes.h | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h
> index 6b318efd8a74..cdf016596659 100644
> --- a/include/linux/compiler_attributes.h
> +++ b/include/linux/compiler_attributes.h
> @@ -40,6 +40,7 @@
>  # define __GCC4_has_attribute___noclone__             1
>  # define __GCC4_has_attribute___nonstring__           0
>  # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8)
> +# define __GCC4_has_attribute___fallthrough__         0
>  #endif
>  
>  /*
> @@ -185,6 +186,22 @@
>  # define __noclone
>  #endif
>  
> +/*
> + * 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
> +
>  /*
>   * Note the missing underscores.
>   *


  parent reply	other threads:[~2019-08-04 18:01 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-31  5:04 [PATCH] net: sctp: Rename fallthrough label to unhandled Joe Perches
2019-07-31  5:35 ` [RFC PATCH] compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use Joe Perches
2019-07-31  9:02   ` Peter Zijlstra
2019-07-31  9:34     ` Joe Perches
2019-07-31 17:14   ` Pavel Machek
2019-07-31 17:51     ` Joe Perches
2019-07-31 18:24       ` hpa
2019-07-31 18:48         ` Peter Zijlstra
2019-07-31 20:02           ` Kees Cook
2019-07-31 20:59             ` Miguel Ojeda
2019-07-31 22:07               ` Joe Perches
2019-08-01  0:00                 ` Miguel Ojeda
2019-08-01 12:25             ` Peter Zijlstra
2019-08-15 18:15             ` Kees Cook
2019-08-15 22:31               ` Kees Cook
2019-09-16 22:19               ` treewide replacement of fallthrough comments with "fallthrough" macro (was Re: [RFC PATCH] compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use) Kees Cook
2019-09-17 22:26                 ` Joe Perches
2019-09-17 23:38                   ` Kees Cook
2019-07-31 21:01           ` [RFC PATCH] compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use hpa
2019-07-31 23:55             ` Miguel Ojeda
2019-08-01  6:10               ` hpa
2019-08-01  7:52                 ` Joe Perches
2019-08-01 12:24                 ` Peter Zijlstra
2019-08-01 20:09                   ` hpa
2019-08-01 20:26                     ` Miguel Ojeda
2019-08-01 20:47                       ` Joe Perches
2019-08-02 11:00                       ` Neil Horman
2019-08-02 12:34                         ` Pavel Machek
2019-08-02 16:09                           ` Kees Cook
2019-08-02 16:16                             ` Joe Perches
2019-08-04 18:01   ` Joe Perches [this message]
2019-08-04 18:09     ` Linus Torvalds
2019-08-04 19:38       ` Miguel Ojeda
2019-08-05  0:39       ` Joe Perches
2019-08-05  1:18         ` Nathan Chancellor
2019-08-05  2:01           ` Joe Perches
2019-07-31 11:19 ` [PATCH] net: sctp: Rename fallthrough label to unhandled Neil Horman
2019-07-31 11:32   ` Joe Perches
2019-07-31 12:16     ` Neil Horman
2019-07-31 16:35       ` Joe Perches
2019-07-31 20:58         ` Neil Horman
2019-07-31 22:23           ` Joe Perches
2019-08-01 10:50             ` Neil Horman
2019-08-01 17:42               ` Joe Perches
2019-08-01 20:48                 ` Neil Horman
2019-08-05 11:49                 ` David Laight
2019-08-02 17:47       ` Joe Perches
2019-08-02 23:19         ` David Miller
2019-08-02 23:26           ` Joe Perches
2019-08-03 18:01           ` Joe Perches
2019-08-04 19:26           ` Neil Horman
2019-08-02 17:50 ` Neil Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c0669a7130645a20e99915385b7e712360c31ed9.camel@perches.com \
    --to=joe@perches.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=davem@davemloft.net \
    --cc=gustavo@embeddedor.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@linux.intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=pavel@ucw.cz \
    --cc=peterz@infradead.org \
    --cc=shawn@git.icu \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).