fix: Revert "Makefile: Enable -Wimplicit-fallthrough for Clang" (v5.15)
authorMichael Jeanson <mjeanson@efficios.com>
Mon, 13 Sep 2021 18:16:22 +0000 (14:16 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 14 Sep 2021 18:38:21 +0000 (14:38 -0400)
Starting with v5.15, "-Wimplicit-fallthrough=5" was added to the build
flags which requires the use of "__attribute__((__fallthrough__))" to
annotate fallthrough case statements.

See upstream commit by the man himself:

  commit d936eb23874433caa3e3d841cfa16f5434b85dcf
  Author: Linus Torvalds <torvalds@linux-foundation.org>
  Date:   Thu Jul 15 18:05:31 2021 -0700

    Revert "Makefile: Enable -Wimplicit-fallthrough for Clang"

    This reverts commit b7eb335e26a9c7f258c96b3962c283c379d3ede0.

    It turns out that the problem with the clang -Wimplicit-fallthrough
    warning is not about the kernel source code, but about clang itself, and
    that the warning is unusable until clang fixes its broken ways.

    In particular, when you enable this warning for clang, you not only get
    warnings about implicit fallthroughs.  You also get this:

       warning: fallthrough annotation in unreachable code [-Wimplicit-fallthrough]

    which is completely broken becasue it

     (a) doesn't even tell you where the problem is (seriously: no line
         numbers, no filename, no nothing).

     (b) is fundamentally broken anyway, because there are perfectly valid
         reasons to have a fallthrough statement even if it turns out that
         it can perhaps not be reached.

    In the kernel, an example of that second case is code in the scheduler:

                    switch (state) {
                    case cpuset:
                            if (IS_ENABLED(CONFIG_CPUSETS)) {
                                    cpuset_cpus_allowed_fallback(p);
                                    state = possible;
                                    break;
                            }
                            fallthrough;
                    case possible:

    where if CONFIG_CPUSETS is enabled you actually never hit the
    fallthrough case at all.  But that in no way makes the fallthrough
    wrong.

    So the warning is completely broken, and enabling it for clang is a very
    bad idea.

    In the meantime, we can keep the gcc option enabled, and make the gcc
    build use

        -Wimplicit-fallthrough=5

    which means that we will at least continue to require a proper
    fallthrough statement, and that gcc won't silently accept the magic
    comment versions. Because gcc does this all correctly, and while the odd
    "=5" part is kind of obscure, it's documented in [1]:

      "-Wimplicit-fallthrough=5 doesn’t recognize any comments as
       fallthrough comments, only attributes disable the warning"

    so if clang ever fixes its bad behavior we can try enabling it there again.

Change-Id: Iea69849592fb69ac04fb9bb28efcd6b8dce8ba88
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lttng-abi.c
lttng-events.c
lttng-filter-interpreter.c
lttng-filter-specialize.c
lttng-string-utils.c
wrapper/compiler_attributes.h [new file with mode: 0644]

index 18f5123c1f7772de392726f20f5397a6c5511794..09b14d6673d6e94ce46fc9c179e8e8b986606d82 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/uaccess.h>
 #include <linux/slab.h>
 #include <linux/err.h>
+#include <wrapper/compiler_attributes.h>
 #include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <wrapper/ringbuffer/vfs.h>
 #include <wrapper/ringbuffer/backend.h>
@@ -881,7 +882,8 @@ long lttng_metadata_ring_buffer_ioctl(struct file *filp,
                 */
                return -ENOSYS;
        }
-       case RING_BUFFER_FLUSH_EMPTY:   /* Fall-through. */
+       case RING_BUFFER_FLUSH_EMPTY:
+               lttng_fallthrough;
        case RING_BUFFER_FLUSH:
        {
                struct lttng_metadata_stream *stream = filp->private_data;
@@ -990,7 +992,8 @@ long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp,
                 */
                return -ENOSYS;
        }
-       case RING_BUFFER_FLUSH_EMPTY:   /* Fall-through. */
+       case RING_BUFFER_FLUSH_EMPTY:
+               lttng_fallthrough;
        case RING_BUFFER_FLUSH:
        {
                struct lttng_metadata_stream *stream = filp->private_data;
@@ -1290,14 +1293,19 @@ int lttng_abi_validate_event_param(struct lttng_kernel_event *event_param)
                }
                break;
 
-       case LTTNG_KERNEL_TRACEPOINT:   /* Fallthrough */
-       case LTTNG_KERNEL_KPROBE:       /* Fallthrough */
-       case LTTNG_KERNEL_KRETPROBE:    /* Fallthrough */
-       case LTTNG_KERNEL_NOOP:         /* Fallthrough */
+       case LTTNG_KERNEL_TRACEPOINT:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_KPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_KRETPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_NOOP:
+               lttng_fallthrough;
        case LTTNG_KERNEL_UPROBE:
                break;
 
-       case LTTNG_KERNEL_FUNCTION:     /* Fallthrough */
+       case LTTNG_KERNEL_FUNCTION:
+               lttng_fallthrough;
        default:
                return -EINVAL;
        }
index 5be4c9b8f4a999a432dca5b400ba6406f17793eb..60f5623be66deba10b001e0064676322a60d23a1 100644 (file)
@@ -41,6 +41,7 @@
 #include <lttng-abi-old.h>
 #include <lttng-endian.h>
 #include <lttng-string-utils.h>
+#include <wrapper/compiler_attributes.h>
 #include <wrapper/ringbuffer/backend.h>
 #include <wrapper/ringbuffer/frontend.h>
 #include <wrapper/time.h>
@@ -430,7 +431,8 @@ int lttng_event_enable(struct lttng_event *event)
        case LTTNG_KERNEL_KRETPROBE:
                ret = lttng_kretprobes_event_enable_state(event, 1);
                break;
-       case LTTNG_KERNEL_FUNCTION:     /* Fall-through. */
+       case LTTNG_KERNEL_FUNCTION:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -466,7 +468,8 @@ int lttng_event_disable(struct lttng_event *event)
        case LTTNG_KERNEL_KRETPROBE:
                ret = lttng_kretprobes_event_enable_state(event, 0);
                break;
-       case LTTNG_KERNEL_FUNCTION:     /* Fall-through. */
+       case LTTNG_KERNEL_FUNCTION:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -613,7 +616,8 @@ struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
        case LTTNG_KERNEL_SYSCALL:
                event_name = event_param->name;
                break;
-       case LTTNG_KERNEL_FUNCTION:     /* Fall-through. */
+       case LTTNG_KERNEL_FUNCTION:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -796,7 +800,8 @@ struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
                ret = try_module_get(event->desc->owner);
                WARN_ON_ONCE(!ret);
                break;
-       case LTTNG_KERNEL_FUNCTION:     /* Fall-through */
+       case LTTNG_KERNEL_FUNCTION:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -863,7 +868,8 @@ void register_event(struct lttng_event *event)
        case LTTNG_KERNEL_NOOP:
                ret = 0;
                break;
-       case LTTNG_KERNEL_FUNCTION:     /* Fall-through */
+       case LTTNG_KERNEL_FUNCTION:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
        }
@@ -907,7 +913,8 @@ int _lttng_event_unregister(struct lttng_event *event)
                lttng_uprobes_unregister(event);
                ret = 0;
                break;
-       case LTTNG_KERNEL_FUNCTION:     /* Fall-through */
+       case LTTNG_KERNEL_FUNCTION:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
        }
@@ -943,7 +950,8 @@ void _lttng_event_destroy(struct lttng_event *event)
                module_put(event->desc->owner);
                lttng_uprobes_destroy_private(event);
                break;
-       case LTTNG_KERNEL_FUNCTION:     /* Fall-through */
+       case LTTNG_KERNEL_FUNCTION:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
        }
@@ -2649,7 +2657,7 @@ int print_escaped_ctf_string(struct lttng_session *session, const char *string)
                        if (ret)
                                goto error;
                        /* We still print the current char */
-                       /* Fallthrough */
+                       lttng_fallthrough;
                default:
                        ret = lttng_metadata_printf(session, "%c", cur);
                        break;
index 6e5a5139e3dfd285fe0500c2558b8c1982fb49ba..d9dc6195f2f78cf1d683b48e046be01e2383f124 100644 (file)
@@ -7,6 +7,7 @@
  * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  */
 
+#include <wrapper/compiler_attributes.h>
 #include <wrapper/uaccess.h>
 #include <wrapper/objtool.h>
 #include <wrapper/types.h>
@@ -419,7 +420,8 @@ static int dynamic_get_index(struct lttng_probe_ctx *lttng_probe_ctx,
                }
                break;
        case LOAD_ROOT_CONTEXT:
-       case LOAD_ROOT_APP_CONTEXT:     /* Fall-through */
+               lttng_fallthrough;
+       case LOAD_ROOT_APP_CONTEXT:
        {
                ret = context_get_index(lttng_probe_ctx,
                                &stack_top->u.ptr,
index 4f9a0cd1833da967fdc9fee7fb62cd74d2cb7771..e9a85c78569fa0fda78fae76b9dc2982bd11dd2d 100644 (file)
@@ -11,6 +11,8 @@
 #include <lttng-filter.h>
 #include "lib/align.h"
 
+#include <wrapper/compiler_attributes.h>
+
 static ssize_t bytecode_reserve_data(struct bytecode_runtime *runtime,
                size_t align, size_t len)
 {
@@ -246,7 +248,8 @@ static int specialize_get_index(struct bytecode_runtime *runtime,
                }
                case OBJECT_TYPE_STRUCT:
                        /* Only generated by the specialize phase. */
-               case OBJECT_TYPE_VARIANT:       /* Fall-through */
+               case OBJECT_TYPE_VARIANT:
+                       lttng_fallthrough;
                default:
                        printk(KERN_WARNING "Unexpected get index type %d",
                                (int) stack_top->load.object_type);
index 416896cc0bb22c9741815948a4bb6f104531a134..e807570663d64f03002bf7f15f67553d87b69b5e 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <linux/types.h>
+#include <wrapper/compiler_attributes.h>
 
 #include <lttng-string-utils.h>
 
@@ -302,7 +303,7 @@ retry:
                        p = pattern_get_char_at_cb(p_at,
                                pattern_get_char_at_cb_data);
 
-                       /* Fall-through. */
+                       lttng_fallthrough;
                default:
                        /*
                         * Default case which will compare the escaped
diff --git a/wrapper/compiler_attributes.h b/wrapper/compiler_attributes.h
new file mode 100644 (file)
index 0000000..ae44903
--- /dev/null
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ *
+ * wrapper/compiler_attributes.h
+ *
+ * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#ifndef _LTTNG_WRAPPER_COMPILER_ATTRIBUTES_H
+#define _LTTNG_WRAPPER_COMPILER_ATTRIBUTES_H
+
+#include <lttng-kernel-version.h>
+
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,20,0))
+#include <linux/compiler_attributes.h>
+#endif
+
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,4,0))
+
+/*
+ * Use the kernel provided fallthrough attribute macro.
+ */
+#define lttng_fallthrough fallthrough
+
+#else /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,4,0) */
+
+/*
+ * Fallback to the comment for kernels pre 5.15 that don't build with
+ * '-Wimplicit-fallthrough=5'.
+ */
+#define lttng_fallthrough do {} while (0)  /* fallthrough */
+
+#endif /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,4,0) */
+
+#endif /* _LTTNG_WRAPPER_COMPILER_ATTRIBUTES_H */
This page took 0.034166 seconds and 4 git commands to generate.