lib/zlib_inflate/inffast: Check config in C to avoid unused function warning
PATCH v2 1/1 lib/zlib_inflate/inffast: Check config in C to avoid unused function warning
Building Linux for ppc64le with Ubuntu clang version 12.0.0-3ubuntu1~21.04.1 shows the warning below.
arch/powerpc/boot/inffast.c:20:1: warning: unused function 'get_unaligned16' [-Wunused-function] get_unaligned16(const unsigned short *p)
^
1 warning generated.
Fix it, by moving the check from the preprocessor to C, so the compiler sees the use.
--- lib/zlib_inflate/inffast.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
lib/zlib_inflate/inffast.c +2 -5
@@ -254,11 +254,8 @@ void inflate_fast(z_streamp strm, unsigned start) sfrom = (unsigned short *)(from); loops = len >>1 ;do -#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS - *sout++ = *sfrom++; -#else - *sout++ =get_unaligned16 (sfrom++); -#endif + *sout++ =IS_ENABLED (CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) ? + *sfrom++ :get_unaligned16 (sfrom++);while (--loops); out = (unsigned char *)sout; from = (unsigned char *)sfrom;
Signature · 1 line
2.33.0
Le 20/09/2021 à 09:46, Paul Menzel a écrit :
Quoted 21 lines
Building Linux for ppc64le with Ubuntu clang version 12.0.0-3ubuntu1~21.04.1 shows the warning below.
arch/powerpc/boot/inffast.c:20:1: warning: unused function 'get_unaligned16' [-Wunused-function]get_unaligned16(const unsigned short *p)
^
1 warning generated.Fix it, by moving the check from the preprocessor to C, so the compiler sees the use.
Signed-off-by Paul Menzel <[email protected]>--- lib/zlib_inflate/inffast.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)lib/zlib_inflate/inffast.c +0
-0
lib/zlib_inflate/inffast.c void inflate_fast(z_streamp strm, unsigned start) · line 258
Quoted 10 lines
lib/zlib_inflate/inffast.c +2
-5@@ -254,11 +254,8 @@ void inflate_fast(z_streamp strm, unsigned start) sfrom = (unsigned short *)(from); loops = len >>1 ; do -#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS - *sout++ = *sfrom++; -#else - *sout++ =get_unaligned16 (sfrom++); -#endif + *sout++ = IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) ? + *sfrom++ : get_unaligned16(sfrom++);
I think it would be more readable as
do {
if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS))
*sout++ = *sfrom++;
else
*sout++ = get_unaligned16(sfrom++);
} while (--loops);Quoted 4 lines
lib/zlib_inflate/inffast.c +0
-0while (--loops); out = (unsigned char *)sout; from = (unsigned char *)sfrom;
Dear Christophe,
Thank you for the review.
Am 20.09.21 um 10:36 schrieb Christophe Leroy:
Quoted 38 lines
Le 20/09/2021 à 09:46, Paul Menzel a écrit :
Quoted 30 lines
Building Linux for ppc64le with Ubuntu clang version 12.0.0-3ubuntu1~21.04.1 shows the warning below.
arch/powerpc/boot/inffast.c:20:1: warning: unused function 'get_unaligned16' [-Wunused-function]get_unaligned16(const unsigned short *p)
^
1 warning generated.Fix it, by moving the check from the preprocessor to C, so the compiler sees the use.
Signed-off-by Paul Menzel <[email protected]>---
lib/zlib_inflate/inffast.c| 7 ++-----1 file changed, 2 insertions(+), 5 deletions(-)lib/zlib_inflate/inffast.c +0
-0@@ -254,11 +254,8 @@ void inflate_fast(z_streamp strm, unsigned start) sfrom = (unsigned short *)(from); loops = len >> 1;do
lib/zlib_inflate/inffast.c +1
-5-#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS - *sout++ = *sfrom++; -#else - *sout++ = get_unaligned16(sfrom++); -#endif + *sout++ =Quoted 2 lines
IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)? + *sfrom++ :get_unaligned16(sfrom++);I think it would be more readable as
Quoted 6 lines
do {
if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) *sout++ = *sfrom++;
else
*sout++ =get_unaligned16(sfrom++);
} while (--loops);
I prefer the ternary operator, as it’s less lines, and it’s clear, that only the variable assignment is affected by the condition. But as style is subjective, I sent v3.
Quoted 3 lines
Quoted 3 lines
while (--loops);
out = (unsigned char *)sout;
from = (unsigned char *)sfrom;
Kind regards,
Paul