]> git.kaiwu.me - haproxy.git/commitdiff
IMPORT: slz-prv: work around lobotomized compilers' fallthrough diagnostics
authorWilly Tarreau <w@1wt.eu>
Tue, 17 Nov 2026 08:21:17 +0000 (09:21 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 17 Nov 2026 10:08:46 +0000 (11:08 +0100)
When preprocessing and compilation run as separate phases (cpp then
cc, as often happens in distributed builds for example), comments are
stripped before compilation begins. Lobotomized compilers that decide
to emit warnings when they don't see "/* fall through */" comment
annotations that were dropped on the previous phase were just
misdesigned in a hurry and are causing harm.

We already had to do this in tables.h in the past but it's just lost at
the wrong place now. Let's just move that __fallthrough definition into
slz-prv.h where it's easier to locate, and use it in slz_rfc1951_flush()
to silence a compiler warning instead of modifying the code to work around
this absurdity.

This is slz commit 06e2caf45e.

include/import/slz-prv.h
include/import/slz-tables.h
src/slz.c

index 07719bdc0c80b841588f596a3d6502621f67d96e..147b9581c2c516acdb508f0a83f45a47b6627b97 100644 (file)
 #define HAVE_FAST_MULT
 #endif
 
+/* This horrible mess is needed to shut up the fallthrough warning since the
+ * stupid comment approach doesn't resist to separate preprocessing (e.g. as
+ * used in distcc). Note that compilers which support the fallthrough attribute
+ * also support __has_attribute.
+ */
+#ifndef __fallthrough
+#  ifdef __has_attribute
+#    if __has_attribute(fallthrough)
+#      define __fallthrough __attribute__((fallthrough))
+#    else
+#      define __fallthrough do { } while (0)
+#    endif
+#  else
+#    define __fallthrough do { } while (0)
+#  endif
+#endif
+
 /* returns the max of <a> and <b>, must be constant since evaluated twice */
 #define MIN_C(a, b) ({                         \
        (a < b) ? a : b;                        \
index f5e8f9a7337f0e053b1c3f71bca7c1e3623da8c8..10f1b460975dca5bcbc0c9ed3c89f41698927310 100644 (file)
@@ -296,23 +296,6 @@ static const uint8_t text_dist_shift[32] = {
        15, 9, 11, 10, 13, 10, 9, 11, 13, 9, 10, 11, 12, 10, 9, 0,
 };
 
-/* This horrible mess is needed to shut up the fallthrough warning since the
- * stupid comment approach doesn't resist to separate preprocessing (e.g. as
- * used in distcc). Note that compilers which support the fallthrough attribute
- * also support __has_attribute.
- */
-#ifndef __fallthrough
-#  ifdef __has_attribute
-#    if __has_attribute(fallthrough)
-#      define __fallthrough __attribute__((fallthrough))
-#    else
-#      define __fallthrough do { } while (0)
-#    endif
-#  else
-#    define __fallthrough do { } while (0)
-#  endif
-#endif
-
 #if defined(PRECOMPUTE_TABLES)
 
 #if !defined(__ARM_FEATURE_CRC32)
index 5a495d31e1acc59d77011367200c660984e163bb..7b853705b6c0158900cb399beb587604f9425d41 100644 (file)
--- a/src/slz.c
+++ b/src/slz.c
@@ -2610,7 +2610,7 @@ int slz_rfc1951_flush(struct slz_stream *strm, unsigned char *buf)
                case SLZ_ST_LAST:
                        send_eob(strm, strm->cur_tree);
                        strm->state = SLZ_ST_DONE;
-                       /* fall through */
+                       __fallthrough;
                case SLZ_ST_DONE:
                case SLZ_ST_END:
                        flush_bits(strm);