[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/12] tcg/optimize: Add fallthrough annotations
From: |
Thomas Huth |
Subject: |
[PULL 10/12] tcg/optimize: Add fallthrough annotations |
Date: |
Wed, 16 Dec 2020 18:29:47 +0100 |
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>
---
include/qemu/compiler.h | 11 +++++++++++
tcg/optimize.c | 4 ++++
2 files changed, 15 insertions(+)
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 1b9e58e82b..df9ec08f8a 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 */
diff --git a/tcg/optimize.c b/tcg/optimize.c
index 220f4601d5..7ca71de956 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -855,6 +855,7 @@ void tcg_optimize(TCGContext *s)
if ((arg_info(op->args[1])->mask & 0x80) != 0) {
break;
}
+ QEMU_FALLTHROUGH;
CASE_OP_32_64(ext8u):
mask = 0xff;
goto and_const;
@@ -862,6 +863,7 @@ void tcg_optimize(TCGContext *s)
if ((arg_info(op->args[1])->mask & 0x8000) != 0) {
break;
}
+ QEMU_FALLTHROUGH;
CASE_OP_32_64(ext16u):
mask = 0xffff;
goto and_const;
@@ -869,6 +871,7 @@ void tcg_optimize(TCGContext *s)
if ((arg_info(op->args[1])->mask & 0x80000000) != 0) {
break;
}
+ QEMU_FALLTHROUGH;
case INDEX_op_ext32u_i64:
mask = 0xffffffffU;
goto and_const;
@@ -886,6 +889,7 @@ void tcg_optimize(TCGContext *s)
if ((arg_info(op->args[1])->mask & 0x80000000) != 0) {
break;
}
+ QEMU_FALLTHROUGH;
case INDEX_op_extu_i32_i64:
/* We do not compute affected as it is a size changing op. */
mask = (uint32_t)arg_info(op->args[1])->mask;
--
2.27.0
- [PULL 01/12] disas/libvixl: Fix fall-through annotation for GCC >= 7, (continued)
- [PULL 01/12] disas/libvixl: Fix fall-through annotation for GCC >= 7, Thomas Huth, 2020/12/16
- [PULL 02/12] target/unicore32/translate: Add missing fallthrough annotations, Thomas Huth, 2020/12/16
- [PULL 03/12] hw/rtc/twl92230: Silence warnings about missing fallthrough statements, Thomas Huth, 2020/12/16
- [PULL 04/12] hw/timer/renesas_tmr: silence the compiler warnings, Thomas Huth, 2020/12/16
- [PULL 05/12] target/i386: silence the compiler warnings in gen_shiftd_rm_T1, Thomas Huth, 2020/12/16
- [PULL 06/12] hw/intc/arm_gicv3_kvm: silence the compiler warnings, Thomas Huth, 2020/12/16
- [PULL 09/12] target/sparc/win_helper: silence the compiler warnings, Thomas Huth, 2020/12/16
- [PULL 07/12] accel/tcg/user-exec: silence the compiler warnings, Thomas Huth, 2020/12/16
- [PULL 11/12] tests/fp: Do not emit implicit-fallthrough warnings in the softfloat tests, Thomas Huth, 2020/12/16
- [PULL 12/12] configure: Compile with -Wimplicit-fallthrough=2, Thomas Huth, 2020/12/16
- [PULL 10/12] tcg/optimize: Add fallthrough annotations,
Thomas Huth <=
- [PULL 08/12] target/sparc/translate: silence the compiler warnings, Thomas Huth, 2020/12/16
- Re: [PULL 00/12] Compile QEMU with -Wimplicit-fallthrough, no-reply, 2020/12/16
- Re: [PULL 00/12] Compile QEMU with -Wimplicit-fallthrough, Peter Maydell, 2020/12/17
- Re: [PULL 00/12] Compile QEMU with -Wimplicit-fallthrough, Thomas Huth, 2020/12/17
- Status/future of QEMU bsd-user impl ? (Wea Re: [PULL 00/12] Compile QEMU with -Wimplicit-fallthrough), Daniel P . Berrangé, 2020/12/17
- Re: Status/future of QEMU bsd-user impl ? (Wea Re: [PULL 00/12] Compile QEMU with -Wimplicit-fallthrough), Warner Losh, 2020/12/17
- Re: Status/future of QEMU bsd-user impl ? (Wea Re: [PULL 00/12] Compile QEMU with -Wimplicit-fallthrough), Peter Maydell, 2020/12/17
- Re: Status/future of QEMU bsd-user impl ? (Wea Re: [PULL 00/12] Compile QEMU with -Wimplicit-fallthrough), Warner Losh, 2020/12/17
- Re: Status/future of QEMU bsd-user impl ? (Wea Re: [PULL 00/12] Compile QEMU with -Wimplicit-fallthrough), Warner Losh, 2020/12/17