diff mbox series

[RFC,v3,78/78] meson.build: increase -Wimplicit-fallthrough to 5

Message ID 80a212fc419991612ca732cb3ed1c923a079ec3b.1697186560.git.manos.pitsidianakis@linaro.org
State New
Headers show
Series Strict disable implicit fallthrough | expand

Commit Message

Manos Pitsidianakis Oct. 13, 2023, 8:46 a.m. UTC
Make GCC's implicit fall-through static analysis stricter by requiring
the use of the fallthrough attribute statement instead of comments.

This makes the QEMU code style more consistent.

Signed-off-by: Emmanouil Pitsidianakis <manos.pitsidianakis@linaro.org>
---
 docs/devel/style.rst | 23 +++++++++++++++++++++++
 meson.build          |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/docs/devel/style.rst b/docs/devel/style.rst
index 2f68b50079..f473dd24e9 100644
--- a/docs/devel/style.rst
+++ b/docs/devel/style.rst
@@ -634,6 +634,29 @@  are still some caveats to beware of
         return g_steal_pointer(&foo);
     }
 
+Implicit switch case fall-through
+=================================
+
+The C language allows switch cases to "fall-through" when a "break" statement
+is missing at the end of a case. This, however, introduces ambiguity in the
+code, as it's not always clear if the missing break is intentional or a bug.
+
+As this behaviour allows for bugs we do not allow "implicit fall-through".
+
+In order to identify intentional fall-through cases, we have adopted a
+pseudo-keyword macro 'fallthrough' which expands to gcc's extension
+__attribute__((__fallthrough__)).  `Statement Attributes
+<https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html>`_
+
+All switch/case blocks must end in one of:
+
+.. code-block:: c
+
+	  break;
+	  fallthrough;
+	  continue;
+	  goto <label>;
+	  return [expression];
 
 QEMU Specific Idioms
 ********************
diff --git a/meson.build b/meson.build
index 79aef19bdc..e8805f0e0c 100644
--- a/meson.build
+++ b/meson.build
@@ -452,7 +452,7 @@  warn_flags = [
   '-Wnested-externs',
   '-Wendif-labels',
   '-Wexpansion-to-defined',
-  '-Wimplicit-fallthrough=2',
+  '-Wimplicit-fallthrough=5',
   '-Wmissing-format-attribute',
   '-Wno-initializer-overrides',
   '-Wno-missing-include-dirs',