From 65bc1bc5cb14cad10dec315829a17c2422436957 Mon Sep 17 00:00:00 2001 From: Erica Bugden Date: Mon, 11 Nov 2024 14:59:10 -0500 Subject: [PATCH] cleanup: fix incorrect gcc fallthrough warnings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ...by adding explicit aborts. The `BT_ASSERT_POST_DEV` macros in these cases will always lead to stopping execution because of the `false` condition, but the gcc compiler does not always catch this. In commit 49bd74f4da37 ("ccv: adjust for MIP 1") explicit aborts were added to the more complex cases in the same switch statement. With gcc 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04), the incorrect warnings are also generated for simpler cases. For example: lib/graph/iterator.c: In function ‘assert_post_dev_clock_classes_are_compatible_one’: ../src/lib/assert-cond-base.h:94:20: error: this statement may fall through [-Werror=implicit-fallthrough=] 94 | if (!(_cond)) { \ | ^ ../src/lib/assert-cond-base.h:123:9: note: in expansion of macro ‘_BT_ASSERT_COND’ 123 | _BT_ASSERT_COND("post", _func, _id_suffix, (_cond), _fmt, ##__VA_ARGS__); | ^~~~~~~~~~~~~~~ ../src/lib/assert-cond-base.h:136:9: note: in expansion of macro ‘BT_ASSERT_POST’ 136 | BT_ASSERT_POST(_func, _id_suffix, (_cond), _fmt, ##__VA_ARGS__) | ^~~~~~~~~~~~~~ lib/graph/iterator.c:723:25: note: in expansion of macro ‘BT_ASSERT_POST_DEV’ 723 | BT_ASSERT_POST_DEV(NEXT_METHOD_NAME, | ^~~~~~~~~~~~~~~~~~ lib/graph/iterator.c:734:17: note: here 734 | case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_KNOWN_GOT_NO_CLOCK_CLASS: | ^~~~ Add explicit aborts to the simpler cases as well so the warnings are not generated. Change-Id: Ib2547e7abff856bb820e736f2be695b03be6a5e3 Signed-off-by: Erica Bugden Reviewed-on: https://review.lttng.org/c/babeltrace/+/13527 Reviewed-by: Philippe Proulx --- src/lib/graph/iterator.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib/graph/iterator.c b/src/lib/graph/iterator.c index 6e8bbfad..6f9fcf74 100644 --- a/src/lib/graph/iterator.c +++ b/src/lib/graph/iterator.c @@ -725,6 +725,12 @@ void assert_post_dev_clock_classes_are_compatible_one( "Expecting no clock class, got one: %![cc-]+K", actual_clock_cls); + /* + * GCC gives bogus `-Wimplicit-fallthrough` + * warnings: convince it that it's not possible. + */ + bt_common_abort(); + case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_KNOWN_GOT_NO_CLOCK_CLASS: if (graph_mip_version == 0) { BT_ASSERT_POST_DEV(NEXT_METHOD_NAME, @@ -770,6 +776,12 @@ void assert_post_dev_clock_classes_are_compatible_one( "Expecting a clock class with a specific origin: %![cc-]+K, " EXP_CC_ORIGIN_FMT, actual_clock_cls, EXP_CC_ORIGIN_VALUES); + /* + * GCC gives bogus `-Wimplicit-fallthrough` + * warnings: convince it that it's not possible. + */ + bt_common_abort(); + case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_UNKNOWN_WITH_ID_GOT_NO_CLOCK_CLASS: if (graph_mip_version == 0) { BT_ASSERT_POST_DEV(NEXT_METHOD_NAME, @@ -860,6 +872,12 @@ void assert_post_dev_clock_classes_are_compatible_one( "Expecting a clock class, got none: %![expected-cc-]+K", ref_clock_cls); + /* + * GCC gives bogus `-Wimplicit-fallthrough` + * warnings: convince it that it's not possible. + */ + bt_common_abort(); + case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_UNKNOWN_WITHOUT_ID_GOT_OTHER_CLOCK_CLASS: BT_ASSERT_POST_DEV(NEXT_METHOD_NAME, "clock-class-is-expected", false, -- 2.34.1