aboutsummaryrefslogtreecommitdiff
path: root/include/qemu/compiler.h
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2020-12-11 16:24:24 +0100
committerThomas Huth <thuth@redhat.com>2020-12-18 09:14:23 +0100
commitd84568b773fe1fc469c4d8419c3545be52eec82c (patch)
tree852e4d7439e40e2609041c5fb00746225c549db2 /include/qemu/compiler.h
parent9cf5a9cf60a3c5271dee05b6a81a05fb45bee622 (diff)
downloadqemu-d84568b773fe1fc469c4d8419c3545be52eec82c.zip
qemu-d84568b773fe1fc469c4d8419c3545be52eec82c.tar.gz
qemu-d84568b773fe1fc469c4d8419c3545be52eec82c.tar.bz2
tcg/optimize: Add fallthrough annotations
To be able to compile this file with -Werror=implicit-fallthrough, we need to add some fallthrough annotations to the case statements that might fall through. Unfortunately, the typical "/* fallthrough */" comments do not work here as expected since some case labels are wrapped in macros and the compiler fails to match the comments in this case. But using __attribute__((fallthrough)) seems to work fine, so let's use that instead (by introducing a new QEMU_FALLTHROUGH macro in our compiler.h header file). Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20201211152426.350966-11-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'include/qemu/compiler.h')
-rw-r--r--include/qemu/compiler.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 1b9e58e..df9ec08 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -222,4 +222,15 @@ extern void QEMU_NORETURN QEMU_ERROR("code path is reachable")
#define qemu_build_not_reached() g_assert_not_reached()
#endif
+/**
+ * In most cases, normal "fallthrough" comments are good enough for
+ * switch-case statements, but sometimes the compiler has problems
+ * with those. In that case you can use QEMU_FALLTHROUGH instead.
+ */
+#if __has_attribute(fallthrough)
+# define QEMU_FALLTHROUGH __attribute__((fallthrough))
+#else
+# define QEMU_FALLTHROUGH do {} while (0) /* fallthrough */
+#endif
+
#endif /* COMPILER_H */