[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 78/78] meson.build: increase -Wimplicit-fallthrough to 5
|
From: |
Emmanouil Pitsidianakis |
|
Subject: |
[RFC PATCH v2 78/78] meson.build: increase -Wimplicit-fallthrough to 5 |
|
Date: |
Fri, 13 Oct 2023 10:57:45 +0300 |
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 --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
@@ -612,28 +612,51 @@ While this generally results in simpler, less leak-prone
code, there
are still some caveats to beware of
* Variables declared with g_auto* MUST always be initialized,
otherwise the cleanup function will use uninitialized stack memory
* If a variable declared with g_auto* holds a value which must
live beyond the life of the function, that value must be saved
and the original variable NULL'd out. This can be simpler using
g_steal_pointer
.. code-block:: c
char *somefunc(void)
{
g_autofree char *foo = g_strdup_printf("foo%", "wibble");
g_autoptr (GList) bar = .....
if (eek) {
return NULL;
}
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
@@ -438,28 +438,28 @@ add_global_link_arguments(qemu_ldflags, native: false,
language: all_languages)
warn_flags = [
'-Wundef',
'-Wwrite-strings',
'-Wmissing-prototypes',
'-Wstrict-prototypes',
'-Wredundant-decls',
'-Wold-style-declaration',
'-Wold-style-definition',
'-Wtype-limits',
'-Wformat-security',
'-Wformat-y2k',
'-Winit-self',
'-Wignored-qualifiers',
'-Wempty-body',
'-Wnested-externs',
'-Wendif-labels',
'-Wexpansion-to-defined',
- '-Wimplicit-fallthrough=2',
+ '-Wimplicit-fallthrough=5',
'-Wmissing-format-attribute',
'-Wno-initializer-overrides',
'-Wno-missing-include-dirs',
'-Wno-shift-negative-value',
'-Wno-string-plus-int',
'-Wno-typedef-redefinition',
'-Wno-tautological-type-limit-compare',
'-Wno-psabi',
'-Wno-gnu-variable-sized-type-not-at-end',
]
--
2.39.2
- [RFC PATCH v2 65/78] hw/nvme: add fallthrough pseudo-keyword, (continued)
- [RFC PATCH v2 65/78] hw/nvme: add fallthrough pseudo-keyword, Emmanouil Pitsidianakis, 2023/10/13
- [RFC PATCH v2 67/78] hw/pci-host/pnv_phb3.c: add fallthrough pseudo-keyword, Emmanouil Pitsidianakis, 2023/10/13
- [RFC PATCH v2 77/78] tests/unit/test-char.c: add fallthrough pseudo-keyword, Emmanouil Pitsidianakis, 2023/10/13
- [RFC PATCH v2 70/78] hw/rtc: add fallthrough pseudo-keyword, Emmanouil Pitsidianakis, 2023/10/13
- [RFC PATCH v2 73/78] hw/watchdog/wdt_diag288.c: add fallthrough pseudo-keyword, Emmanouil Pitsidianakis, 2023/10/13
- [RFC PATCH v2 74/78] hw/cxl/cxl-device-utils.c: add fallthrough pseudo-keyword, Emmanouil Pitsidianakis, 2023/10/13
- [RFC PATCH v2 76/78] qemu-img.c: add fallthrough pseudo-keyword, Emmanouil Pitsidianakis, 2023/10/13
- [RFC PATCH v2 71/78] hw/s390x: add fallthrough pseudo-keyword, Emmanouil Pitsidianakis, 2023/10/13
- [RFC PATCH v2 72/78] hw/ssi: add fallthrough pseudo-keyword, Emmanouil Pitsidianakis, 2023/10/13
- [RFC PATCH v2 78/78] meson.build: increase -Wimplicit-fallthrough to 5,
Emmanouil Pitsidianakis <=
- Re: [RFC PATCH v2 00/78] Strict disable implicit fallthrough, Eric Blake, 2023/10/17