From: Joe Perches <joe@perches.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
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>,
the arch/x86 maintainers <x86@kernel.org>,
Linux List Kernel Mailing <linux-kernel@vger.kernel.org>,
Neil Horman <nhorman@tuxdriver.com>,
David Miller <davem@davemloft.net>,
Nick Desaulniers <ndesaulniers@google.com>,
clang-built-linux@googlegroups.com
Subject: Re: [RFC PATCH] compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use
Date: Sun, 04 Aug 2019 17:39:28 -0700 [thread overview]
Message-ID: <49b659d8f88f67c736881224203418f59a5d29ac.camel@perches.com> (raw)
In-Reply-To: <CAHk-=wg1PAJR6ChVXE7O_H2wEG=1mWxi2uc0fH5bthOC_81uTA@mail.gmail.com>
On Sun, 2019-08-04 at 11:09 -0700, Linus Torvalds wrote:
> On Sun, Aug 4, 2019 at 11:01 AM Joe Perches <joe@perches.com> wrote:
> > Linus? Do you have an opinion about this RFC/patch?
>
> So my only real concern is that the comment approach has always been
> the really traditional one, going back all the way to 'lint' days.
>
> And you obviously cannot use a #define to create a comment, so this
> whole keyword model will never be able to do that.
>
> At the same time, all the modern tools we care about do seem to be
> happy with it, either through the gcc attribute, the clang
> [[clang:fallthrough]] or the (eventual) standard C [[fallthrough]]
> model.
(adding Nick Desaulniers and clang-built-linux to cc's)
As far as I can tell, clang 10 (and it took hours to compile
and link the most current version here) does not support
-Wimplicit-fallthrough=3
and using just -Wimplicit-fallthrough with clang 10 does not emit
a fallthrough warning even with -Wextra and -Wimplicit-fallthrough
using switch / case code blocks like:
---
lib/test_module.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lib/test_module.c b/lib/test_module.c
index debd19e35198..30c835178c7c 100644
--- a/lib/test_module.c
+++ b/lib/test_module.c
@@ -14,6 +14,21 @@
#include <linux/module.h>
#include <linux/printk.h>
+static int switch_case(int val)
+{
+ int i = 0;
+
+ switch (val) {
+ case 1:
+ i |= 1;
+ case 2:
+ i |= 2;
+ break;
+ }
+
+ return i;
+}
+
static int __init test_module_init(void)
{
pr_warn("Hello, world\n");
---
Given:
$ clang -v
clang version 10.0.0 (git://github.com/llvm/llvm-project.git 305b961f64b75e73110e309341535f6d5a48ed72)
and the compilation command line:
$ clang -Wp,-MD,lib/.test_module.o.d -nostdinc -isystem /usr/local/lib/clang/10.0.0/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -Qunused-arguments -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Wno-format-security -std=gnu89 -no-integrated-as -Werror=unknown-warning-option -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mno-80387 -mstack-alignment=8 -mtune=generic -mno-red-zone -mcmodel=kernel -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -Wno-sign-compare -fno-a
synchronous-unwind-tables -mretpoline-external-thunk -fno-delete-null-pointer-checks -Wno-address-of-packed-member -O2 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-format-invalid-specifier -Wno-gnu -Wno-tautological-compare -mno-global-merge -Wno-unused-const-variable -DCC_USING_FENTRY -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants -fno-stack-check -Werror=date-time -Werror=incompatible-pointer-types -fcf-protection=none -Wno-initializer-overrides -Wno-format -Wno-sign-compare -Wno-format-zero-length -fsanitize=kernel-address -mllvm -asan-mapping-offset=0xdffffc0000000000 -mllvm -asan-globals=1 -mllvm -asan-instrumentation-with-call-threshold=0 -mllvm -asan-stack=0 --param asan-instrument-allocas=1 -fsanitize-coverage=trace-pc -fsanitize-coverage=trace-cmp -DMODULE -DKBUILD_BASENAME='"test_module"' -DKBUILD_MODNAME='"test_module"' -Wextra -Wimplicit-fallthrough -c -o lib/test_module.o lib/test_module.c
> So I'm ok with just saying "the comment model may be traditional, but
> it's not very good".
>
> I didn't look at all the patches, but the one I *did* see had a few issues:
>
> - it didn't seem to handle clang
The __has_attribute use is at least clang compatible.
https://releases.llvm.org/3.7.0/tools/clang/docs/LanguageExtensions.html
even if it doesn't (seem to?) work.
> - we'd need to make -Wimplicit-fallthrough be dependent on the
> compiler actually supporting the attribute, not just on supporting the
> flag.
I believe that also needs work if ever clang works,
Makefile:KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=3,)
this will have to be changed for clang as the =<val> isn't (yet?) supported.
> without those changes, nobody can actually start doing any
> conversions. But I assume such patches exist somewhere, and I've just
> missed them.
I haven't sent any patches for any comment conversions.
nor would I until the RFC is acceptable.
Just this RFC and the necessary conversion of the one use
of fallthrough as a label (which David Miller did not apply)
Some people reasonably feel that Coverity should recognize
fallthrough; style annotations before changing the existing
/* fallthrough */ comment uses. I think lint doesn't matter
much.
I do have a script that does a reasonable job of converting
most of the /* fallthrough */ style comments to fallthrough;
while realigning to the last indentation.
That script still needs more work before I will post it.
Lastly:
I think using the pseudo-keyword
fallthrough;
reads better than
__fallthrough;
to end case blocks.
Do you have an opinion here?
next prev parent reply other threads:[~2019-08-05 0:39 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
2019-08-04 18:09 ` Linus Torvalds
2019-08-04 19:38 ` Miguel Ojeda
2019-08-05 0:39 ` Joe Perches [this message]
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=49b659d8f88f67c736881224203418f59a5d29ac.camel@perches.com \
--to=joe@perches.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=bp@alien8.de \
--cc=clang-built-linux@googlegroups.com \
--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=ndesaulniers@google.com \
--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).