From: Hans Kristian Rosbach Date: Tue, 13 Jan 2026 14:32:53 +0000 (+0100) Subject: Add Z_UNREACHABLE compiler hint X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5129cfe46dcd2aa0c679a8f9e169dff69df4f2f;p=thirdparty%2Fzlib-ng.git Add Z_UNREACHABLE compiler hint --- diff --git a/deflate.c b/deflate.c index aa534fb29..a9645ce8e 100644 --- a/deflate.c +++ b/deflate.c @@ -711,6 +711,7 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long break; #endif default: /* for compiler happiness */ + Z_UNREACHABLE(); wraplen = ZLIB_WRAPLEN; } diff --git a/gzread.c b/gzread.c index d52fea80e..3e321a03b 100644 --- a/gzread.c +++ b/gzread.c @@ -232,6 +232,7 @@ static int gz_fetch(gz_state *state) { return -1; continue; default: // Can't happen + Z_UNREACHABLE(); return -1; } } while (state->x.have == 0 && (!state->eof || strm->avail_in)); diff --git a/zbuild.h b/zbuild.h index 954bad316..b17362767 100644 --- a/zbuild.h +++ b/zbuild.h @@ -48,6 +48,17 @@ # endif #endif +/* Hint to compiler that a block of code is unreachable, typically in a switch default condition */ +#ifndef Z_UNREACHABLE +# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +# define Z_UNREACHABLE() unreachable() // C23 approach +# elif (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__) +# define Z_UNREACHABLE() __builtin_unreachable() +# else +# define Z_UNREACHABLE() +# endif +#endif + #ifndef Z_TARGET # if Z_HAS_ATTRIBUTE(__target__) # define Z_TARGET(x) __attribute__((__target__(x)))