From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
To: Yury Norov <yury.norov@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>
Cc: linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Subject: [PATCH] linux/find: ignore -Wtype-limits to reduce W=2 warnings by 34% tree-wide
Date: Wed, 27 Apr 2022 01:16:58 +0900 [thread overview]
Message-ID: <20220426161658.437466-1-mailhol.vincent@wanadoo.fr> (raw)
find_first_bit(), find_first_and_bit(), find_first_and_bit() and
find_first_and_bit() all invokes GENMASK(size - 1, 0).
This triggers below warning when compiled with W=2.
| ./include/linux/find.h: In function 'find_first_bit':
| ./include/linux/bits.h:25:36: warning: comparison of unsigned
| expression in '< 0' is always false [-Wtype-limits]
| 25 | __is_constexpr((l) > (h)), (l) > (h), 0)))
| | ^
| ./include/linux/build_bug.h:16:62: note: in definition of macro
| 'BUILD_BUG_ON_ZERO'
| 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| | ^
| ./include/linux/bits.h:25:17: note: in expansion of macro '__is_constexpr'
| 25 | __is_constexpr((l) > (h)), (l) > (h), 0)))
| | ^~~~~~~~~~~~~~
| ./include/linux/bits.h:38:10: note: in expansion of macro 'GENMASK_INPUT_CHECK'
| 38 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| | ^~~~~~~~~~~~~~~~~~~
| ./include/linux/find.h:119:45: note: in expansion of macro 'GENMASK'
| 119 | unsigned long val = *addr & GENMASK(size - 1, 0);
| | ^~~~~~~
linux/find.h being a widely used header file, above warning show up in
thousand of files which include this header (either directly on
indirectly).
Because it is a false positive, we just silence -Wtype-limits flag
locally to remove the spam. clang does not warn about it, so we just
apply the diag_ignore() directive to gcc.
By doing so, the warnings for a W=2 build are reduced by
34%. Benchmark was done with gcc 11.2.1 on Linux v5.17 x86_64
allyesconfig (except CONFIG_WERROR). Beforethe patch: 515496 warnings
and after: 340097.
For reference, past proposal to modify GENMASK_INPUT_CHECK() was
rejected in:
https://lore.kernel.org/all/20220304124416.1181029-1-mailhol.vincent@wanadoo.fr/
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
include/linux/find.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/find.h b/include/linux/find.h
index 5bb6db213bcb..efd4b3f7dd17 100644
--- a/include/linux/find.h
+++ b/include/linux/find.h
@@ -103,6 +103,10 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
}
#endif
+__diag_push();
+__diag_ignore(GCC, 8, "-Wtype-limits",
+ "GENMASK(size - 1, 0) yields 'comparison of unsigned expression in < 0 is always false' which is OK");
+
#ifndef find_first_bit
/**
* find_first_bit - find the first set bit in a memory region
@@ -193,6 +197,8 @@ unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
}
#endif
+__diag_pop(); /* ignore -Wtype-limits */
+
/**
* find_next_clump8 - find next 8-bit clump with set bits in a memory region
* @clump: location to store copy of found clump
--
2.35.1
next reply other threads:[~2022-04-26 16:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-26 16:16 Vincent Mailhol [this message]
2022-04-26 18:56 ` Arnd Bergmann
2022-04-27 2:32 ` Vincent MAILHOL
2022-04-26 20:42 ` Yury Norov
2022-04-27 2:58 ` Vincent MAILHOL
2022-04-27 13:21 ` Alexander Lobakin
2022-04-27 14:04 ` Yury Norov
2022-04-28 6:06 ` Vincent MAILHOL
2022-05-08 9:12 ` Vincent MAILHOL
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220426161658.437466-1-mailhol.vincent@wanadoo.fr \
--to=mailhol.vincent@wanadoo.fr \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=trix@redhat.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®