test/hash: Fix warning in two-dimensional array init
PATCH 1/2 test/hash: Fix warning in two-dimensional array init
lib/test_hash.c: In function 'test_hash_init':lib/test_hash.c:146:2: warning: missing braces around initializer [-Wmissing-braces]
--- lib/test_hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_hash.c +1 -1
@@ -143,7 +143,7 @@ static int __inittest_hash_init (void) {char buf[SIZE +1 ]; -u32 string_or =0 , hash_or[2 ][33 ] = {0 }; +u32 string_or =0 , hash_or[2 ][33 ] = { {0 , } };unsigned tests =0 ;unsigned long long h64 =0 ;int i, j;
Signature · 1 line
1.9.1
PATCH 2/2 test/hash: Fix warning in preprocessor symbol evaluation
Some versions of gcc don't like tests for the value of an undefined preprocessor symbol, even in the #else branch of an #ifndef:
lib/test_hash.c:224:7: warning: "HAVE_ARCH__HASH_32" is not defined [-Wundef]
#elif HAVE_ARCH__HASH_32 != 1
^
lib/test_hash.c:229:7: warning: "HAVE_ARCH_HASH_32" is not defined [-Wundef]
#elif HAVE_ARCH_HASH_32 != 1
^
lib/test_hash.c:234:7: warning: "HAVE_ARCH_HASH_64" is not defined [-Wundef]
#elif HAVE_ARCH_HASH_64 != 1
^Seen with gcc 4.9, not seen with 4.1.2.
Change the logic to only check the value inside an #ifdef to fix this.
--- lib/test_hash.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
lib/test_hash.c +15 -9
@@ -219,21 +219,27 @@ test_hash_init(void) }/* Issue notices about skipped tests. */ -#ifndef HAVE_ARCH__HASH_32 -pr_info ("__hash_32() has no arch implementation to test." ); -#elif HAVE_ARCH__HASH_32 !=1 +#ifdef HAVE_ARCH__HASH_32 +#if HAVE_ARCH__HASH_32 !=1 pr_info ("__hash_32() is arch-specific; not compared to generic." );#endif -#ifndef HAVE_ARCH_HASH_32 -pr_info ("hash_32() has no arch implementation to test." ); -#elif HAVE_ARCH_HASH_32 !=1 +#else +pr_info ("__hash_32() has no arch implementation to test." ); +#endif +#ifdef HAVE_ARCH_HASH_32 +#if HAVE_ARCH_HASH_32 !=1 pr_info ("hash_32() is arch-specific; not compared to generic." );#endif -#ifndef HAVE_ARCH_HASH_64 -pr_info ("hash_64() has no arch implementation to test." ); -#elif HAVE_ARCH_HASH_64 !=1 +#else +pr_info ("hash_32() has no arch implementation to test." ); +#endif +#ifdef HAVE_ARCH_HASH_64 +#if HAVE_ARCH_HASH_64 !=1 pr_info ("hash_64() is arch-specific; not compared to generic." );#endif +#else +pr_info ("hash_64() has no arch implementation to test." ); +#endif pr_notice ("%u tests passed." , tests);
Signature · 1 line
1.9.1
Re: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation
Quoted 2 lines · Geert Uytterhoeven
Some versions of gcc don't like tests for the value of an undefined preprocessor symbol, even in the #else branch of an #ifndef:
Damn, I had hoped that would work universally; I tried to avoid the uglier #if-inside-#ifdef construction. GCC 6 is quite happy wth it.
But no objections.
If you want:
But here's an alternative. Geert, what do you think of this?
lib/test_hash.c +3 -3
@@ -221,17 +221,17 @@ test_hash_init(void)/* Issue notices about skipped tests. */ #ifndef HAVE_ARCH__HASH_32 pr_info ("__hash_32() has no arch implementation to test." ); -#elif HAVE_ARCH__HASH_32 !=1 +#elif HAVE_ARCH__HASH_32 +0 !=1 pr_info ("__hash_32() is arch-specific; not compared to generic." );#endif #ifndef HAVE_ARCH_HASH_32 pr_info ("hash_32() has no arch implementation to test." ); -#elif HAVE_ARCH_HASH_32 !=1 +#elif HAVE_ARCH_HASH_32 +0 !=1 pr_info ("hash_32() is arch-specific; not compared to generic." );#endif #ifndef HAVE_ARCH_HASH_64 pr_info ("hash_64() has no arch implementation to test." ); -#elif HAVE_ARCH_HASH_64 !=1 +#elif HAVE_ARCH_HASH_64 +0 !=1 pr_info ("hash_64() is arch-specific; not compared to generic." );#endif
George Spelvin
Acked-byRe: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation
Quoted 1 line
But here's an alternative. Geert, what do you think of this?
Never mind; that doesn't work. Plain gcc-4.9 passes, it, but it's the "-Wundef" flag that the kernel uses that triggers it.
So we're back to Geert's original suggestion.
==>$ cat foo.c
#ifndef FOO
This is a test.
#elif FOO == 1
This is another test
#elif FOO + 0 == 1
who knows
#endif
==>$ gcc-6 -W -Wall -Wundef -E foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "foo.c"
This is a test.
==>$ gcc-4.9 -W -Wall -Wundef -E foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "foo.c"
foo.c:3:7: warning: "FOO" is not defined [-Wundef]
#elif FOO == 1
^
foo.c:5:7: warning: "FOO" is not defined [-Wundef]
#elif FOO + 0 == 1
^This is a test.
Good idea. thanks for your help, Geert.