Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1408622 > unrolled thread

[PATCH 1/2] test/hash: Fix warning in two-dimensional array init

Started byGeert Uytterhoeven <geert@linux-m68k.org>
First post2016-05-29 19:50 +0200
Last post2016-05-29 20:50 +0200
Articles 5 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] test/hash: Fix warning in two-dimensional array init Geert Uytterhoeven <geert@linux-m68k.org> - 2016-05-29 19:50 +0200
    [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation Geert Uytterhoeven <geert@linux-m68k.org> - 2016-05-29 19:50 +0200
      Re: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation "George Spelvin" <linux@sciencehorizons.net> - 2016-05-29 21:00 +0200
        Re: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation "George Spelvin" <linux@sciencehorizons.net> - 2016-05-29 21:10 +0200
    Re: [PATCH 1/2] test/hash: Fix warning in two-dimensional array init "George Spelvin" <linux@sciencehorizons.net> - 2016-05-29 20:50 +0200

#1408622 — [PATCH 1/2] test/hash: Fix warning in two-dimensional array init

FromGeert Uytterhoeven <geert@linux-m68k.org>
Date2016-05-29 19:50 +0200
Subject[PATCH 1/2] test/hash: Fix warning in two-dimensional array init
Message-ID<rEd0B-Ss-1@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1408623 — [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation

FromGeert Uytterhoeven <geert@linux-m68k.org>
Date2016-05-29 19:50 +0200
Subject[PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation
Message-ID<rEd0C-Ss-13@gated-at.bofh.it>
In reply to#1408622
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

[toc] | [prev] | [next] | [standalone]


#1408643 — Re: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation

From"George Spelvin" <linux@sciencehorizons.net>
Date2016-05-29 21:00 +0200
SubjectRe: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation
Message-ID<rEe6m-1x2-9@gated-at.bofh.it>
In reply to#1408623
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
 

[toc] | [prev] | [next] | [standalone]


#1408647 — Re: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation

From"George Spelvin" <linux@sciencehorizons.net>
Date2016-05-29 21:10 +0200
SubjectRe: [PATCH 2/2] test/hash: Fix warning in preprocessor symbol evaluation
Message-ID<rEeg2-1Ra-15@gated-at.bofh.it>
In reply to#1408643
> 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.

[toc] | [prev] | [next] | [standalone]


#1408640

From"George Spelvin" <linux@sciencehorizons.net>
Date2016-05-29 20:50 +0200
Message-ID<rEdWG-1tA-5@gated-at.bofh.it>
In reply to#1408622
Good idea.  thanks for your help, Geert.

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web