linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] test/hash: Fix warning in two-dimensional array init
@ 2016-05-29 17:28 Geert Uytterhoeven
  2016-05-29 17:28 ` [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation Geert Uytterhoeven
  2016-05-29 18:43 ` [PATCH 1/2] test/hash: Fix warning in two-dimensional array init George Spelvin
  0 siblings, 2 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2016-05-29 17:28 UTC (permalink / raw)
  To: George Spelvin, Linus Torvalds; +Cc: linux-kernel, Geert Uytterhoeven

lib/test_hash.c: In function 'test_hash_init':
lib/test_hash.c:146:2: warning: missing braces around initializer [-Wmissing-braces]

Fixes: 468a9428521e7d00 ("<linux/hash.h>: Add support for architecture-specific functions")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 lib/test_hash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/test_hash.c b/lib/test_hash.c
index c9549c8b49090d7e..fd7a677100ebe935 100644
--- a/lib/test_hash.c
+++ b/lib/test_hash.c
@@ -143,7 +143,7 @@ static int __init
 test_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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation
  2016-05-29 17:28 [PATCH 1/2] test/hash: Fix warning in two-dimensional array init Geert Uytterhoeven
@ 2016-05-29 17:28 ` Geert Uytterhoeven
  2016-05-29 18:53   ` George Spelvin
  2016-05-29 18:43 ` [PATCH 1/2] test/hash: Fix warning in two-dimensional array init George Spelvin
  1 sibling, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2016-05-29 17:28 UTC (permalink / raw)
  To: George Spelvin, Linus Torvalds; +Cc: linux-kernel, 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:

    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.

Fixes: 468a9428521e7d00 ("<linux/hash.h>: Add support for architecture-specific functions")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 lib/test_hash.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/lib/test_hash.c b/lib/test_hash.c
index fd7a677100ebe935..a06ac379ad429c6b 100644
--- a/lib/test_hash.c
+++ b/lib/test_hash.c
@@ -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);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] test/hash: Fix warning in two-dimensional array init
  2016-05-29 17:28 [PATCH 1/2] test/hash: Fix warning in two-dimensional array init Geert Uytterhoeven
  2016-05-29 17:28 ` [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation Geert Uytterhoeven
@ 2016-05-29 18:43 ` George Spelvin
  1 sibling, 0 replies; 5+ messages in thread
From: George Spelvin @ 2016-05-29 18:43 UTC (permalink / raw)
  To: geert, linux, torvalds; +Cc: linux-kernel

Good idea.  thanks for your help, Geert.

Acked-by: George Spelvin <linux@sciencehorizons.net>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation
  2016-05-29 17:28 ` [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation Geert Uytterhoeven
@ 2016-05-29 18:53   ` George Spelvin
  2016-05-29 19:07     ` George Spelvin
  0 siblings, 1 reply; 5+ messages in thread
From: George Spelvin @ 2016-05-29 18:53 UTC (permalink / raw)
  To: geert, linux, torvalds; +Cc: linux-kernel

Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> 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:
Acked-by: George Spelvin <linux@sciencehorizons.net>

But here's an alternative.  Geert, what do you think of this?

diff --git a/lib/test_hash.c b/lib/test_hash.c
index c9549c8b..8ea1d2ca 100644
--- a/lib/test_hash.c
+++ b/lib/test_hash.c
@@ -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
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation
  2016-05-29 18:53   ` George Spelvin
@ 2016-05-29 19:07     ` George Spelvin
  0 siblings, 0 replies; 5+ messages in thread
From: George Spelvin @ 2016-05-29 19:07 UTC (permalink / raw)
  To: geert, linux, torvalds; +Cc: linux-kernel

> 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.
Acked-by: George Spelvin <linux@sciencehorizons.net>

==>$ 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-05-29 19:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-29 17:28 [PATCH 1/2] test/hash: Fix warning in two-dimensional array init Geert Uytterhoeven
2016-05-29 17:28 ` [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation Geert Uytterhoeven
2016-05-29 18:53   ` George Spelvin
2016-05-29 19:07     ` George Spelvin
2016-05-29 18:43 ` [PATCH 1/2] test/hash: Fix warning in two-dimensional array init George Spelvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).