* [PATCH v4 1/2] kbuild: remove gcc's -Wtype-limits
2026-01-01 15:21 [PATCH v4 0/2] kbuild: remove gcc's -Wtype-limits Vincent Mailhol
@ 2026-01-01 15:21 ` Vincent Mailhol
2026-01-01 15:21 ` [PATCH v4 2/2] kbuild: cleanup local -Wno-type-limits exceptions Vincent Mailhol
2026-01-05 12:24 ` [PATCH v4 0/2] kbuild: remove gcc's -Wtype-limits Nicolas Schier
2 siblings, 0 replies; 5+ messages in thread
From: Vincent Mailhol @ 2026-01-01 15:21 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Nick Desaulniers,
Bill Wendling, Justin Stitt, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Chris Mason,
David Sterba, Kees Cook, Gustavo A. R. Silva
Cc: Linus Torvalds, linux-kbuild, linux-sparse, linux-kernel, llvm,
dri-devel, linux-btrfs, linux-hardening, Vincent Mailhol
W=2 builds are heavily polluted by the -Wtype-limits warning.
Here are some W=12 statistics on Linux v6.19-rc3 for an x86_64
defconfig (with just CONFIG_WERROR set to "n") using gcc 15.2.1:
Warning name count percent
-------------------------------------------------
-Wlogical-op 2 0.00 %
-Wmaybe-uninitialized 139 0.20 %
-Wunused-macros 869 1.24 %
-Wmissing-field-initializers 1418 2.02 %
-Wshadow 2234 3.19 %
-Wtype-limits 65378 93.35 %
-------------------------------------------------
Total 70040 100.00 %
As we can see, -Wtype-limits represents the vast majority of all
warnings. The reason behind this is that these warnings appear in
some common header files, meaning that some unique warnings are
repeated tens of thousands of times (once per header inclusion).
Add to this the fact that each warning is coupled with a dozen lines
detailing some macro expansion. The end result is that the W=2 output
is just too bloated and painful to use.
Three years ago, I proposed in [1] modifying one such header to
silence that noise. Because the code was not faulty, Linus rejected
the idea and instead suggested simply removing that warning.
At that time, I could not bring myself to send such a patch because,
despite its problems, -Wtype-limits would still catch the below bug:
unsigned int ret;
ret = check();
if (ret < 0)
error();
Meanwhile, based on another suggestion from Linus, I added a new check
to sparse [2] that would catch the above bug without the useless spam.
With this, remove gcc's -Wtype-limits. People who still want to catch
incorrect comparisons between unsigned integers and zero can now use
sparse instead.
On a side note, clang also has a -Wtype-limits warning but:
* it is not enabled in the kernel at the moment because, contrary to
gcc, clang did not include it under -Wextra.
* it does not warn if the code results from a macro expansion. So,
if activated, it would not cause as much spam as gcc does.
* -Wtype-limits is split into four sub-warnings [3] meaning that if
it were to be activated, we could select which one to keep.
So there is no present need to explicitly disable -Wtype-limits in
clang.
[1] linux/bits.h: GENMASK_INPUT_CHECK: reduce W=2 noise by 31% treewide
Link: https://lore.kernel.org/all/20220308141201.2343757-1-mailhol.vincent@wanadoo.fr/
[2] Warn about "unsigned value that used to be signed against zero"
Link: https://lore.kernel.org/all/20250921061337.3047616-1-mailhol@kernel.org/
[3] clang's -Wtype-limits
Link: https://clang.llvm.org/docs/DiagnosticsReference.html#wtype-limits
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
**Changelog**
v3 -> v4:
- Update the statistics from v6.19-rc1 to v6.19-rc3.
---
scripts/Makefile.warn | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/scripts/Makefile.warn b/scripts/Makefile.warn
index 68e6fafcb80c..c593ab1257de 100644
--- a/scripts/Makefile.warn
+++ b/scripts/Makefile.warn
@@ -55,6 +55,9 @@ else
KBUILD_CFLAGS += -Wno-main
endif
+# Too noisy on range checks and in macros handling both signed and unsigned.
+KBUILD_CFLAGS += -Wno-type-limits
+
# These result in bogus false positives
KBUILD_CFLAGS += $(call cc-option, -Wno-dangling-pointer)
@@ -174,7 +177,6 @@ else
# The following turn off the warnings enabled by -Wextra
KBUILD_CFLAGS += -Wno-missing-field-initializers
-KBUILD_CFLAGS += -Wno-type-limits
KBUILD_CFLAGS += -Wno-shift-negative-value
ifdef CONFIG_CC_IS_CLANG
--
2.52.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 2/2] kbuild: cleanup local -Wno-type-limits exceptions
2026-01-01 15:21 [PATCH v4 0/2] kbuild: remove gcc's -Wtype-limits Vincent Mailhol
2026-01-01 15:21 ` [PATCH v4 1/2] " Vincent Mailhol
@ 2026-01-01 15:21 ` Vincent Mailhol
2026-01-05 12:24 ` [PATCH v4 0/2] kbuild: remove gcc's -Wtype-limits Nicolas Schier
2 siblings, 0 replies; 5+ messages in thread
From: Vincent Mailhol @ 2026-01-01 15:21 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Nick Desaulniers,
Bill Wendling, Justin Stitt, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Chris Mason,
David Sterba, Kees Cook, Gustavo A. R. Silva
Cc: Linus Torvalds, linux-kbuild, linux-sparse, linux-kernel, llvm,
dri-devel, linux-btrfs, linux-hardening, Vincent Mailhol
Now that -Wtype-limits is globally deactivated, there is no need for
local exceptions anymore.
Acked-by: David Sterba <dsterba@suse.com>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
Changelog:
v1 -> v2: small change in patch description
---
drivers/gpu/drm/Makefile | 1 -
fs/btrfs/Makefile | 1 -
2 files changed, 2 deletions(-)
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 0e1c668b46d2..b879a60ca79a 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -22,7 +22,6 @@ subdir-ccflags-y += $(call cc-option, -Wstringop-truncation)
# The following turn off the warnings enabled by -Wextra
ifeq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
subdir-ccflags-y += -Wno-missing-field-initializers
-subdir-ccflags-y += -Wno-type-limits
subdir-ccflags-y += -Wno-shift-negative-value
endif
ifeq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
index 743d7677b175..40bc2f7e6f6b 100644
--- a/fs/btrfs/Makefile
+++ b/fs/btrfs/Makefile
@@ -17,7 +17,6 @@ subdir-ccflags-y += $(condflags)
# The following turn off the warnings enabled by -Wextra
subdir-ccflags-y += -Wno-missing-field-initializers
subdir-ccflags-y += -Wno-sign-compare
-subdir-ccflags-y += -Wno-type-limits
subdir-ccflags-y += -Wno-shift-negative-value
obj-$(CONFIG_BTRFS_FS) := btrfs.o
--
2.52.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4 0/2] kbuild: remove gcc's -Wtype-limits
2026-01-01 15:21 [PATCH v4 0/2] kbuild: remove gcc's -Wtype-limits Vincent Mailhol
2026-01-01 15:21 ` [PATCH v4 1/2] " Vincent Mailhol
2026-01-01 15:21 ` [PATCH v4 2/2] kbuild: cleanup local -Wno-type-limits exceptions Vincent Mailhol
@ 2026-01-05 12:24 ` Nicolas Schier
2026-01-05 20:47 ` Vincent Mailhol
2 siblings, 1 reply; 5+ messages in thread
From: Nicolas Schier @ 2026-01-05 12:24 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Vincent Mailhol, Nick Desaulniers, Bill Wendling, Justin Stitt,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Chris Mason, David Sterba, Kees Cook,
Gustavo A. R. Silva, Linus Torvalds, linux-kbuild, linux-sparse,
linux-kernel, llvm, dri-devel, linux-btrfs, linux-hardening
On Thu, Jan 01, 2026 at 04:21:38PM +0100, Vincent Mailhol wrote:
> I often read on the mailing list people saying "who cares about W=2
> builds anyway?". At least I do. Not that I want to fix all of them,
> but on some occasions, such as new driver submissions, I have often
> found a couple valid diagnostics in the W=2 output.
>
> That said, the annoying thing is that W=2 is heavily polluted by one
> warning: -Wtype-limits. Try a gcc W=2 build on any file and see the
> results for yourself. I suspect this to be the reason why so few
> people are using W=2.
>
> This series removes gcc's -Wtype-limits in an attempt to make W=2 more
> useful. Those who do not use W=2 can continue to not use it if they
> want. Those who, like me, use it for time to time will get an improved
> experience from the reduced spam.
>
> Patch #1 deactivates -Wtype-limits. Extra details on statistics, past
> attempts and alternatives are given in the description.
>
> Patch #2 clean-ups the local Kbuild -Wno-type-limits exceptions.
>
> Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
> ---
> Changes in v4:
>
> - Remove patch #3.
> - Aside from minor changes in the patch descriptions, this is
> basially a revert to v1.
>
> Link to v3: https://lore.kernel.org/r/20251220-remove_wtype-limits-v3-0-24b170af700e@kernel.org
just to prevent confusions: As Dan silenced the Smatch warning caused
by patch #3 [1] (thanks!), the additional comment patch [2] is obsolete
and v3 of the series is a more complete version than v4.
Kind regards,
Nicolas
[1]: https://github.com/error27/smatch/commit/a7b509b8171b4982b5a2a355f64d083dd76e03f9
[2]: https://lore.kernel.org/linux-kbuild/b6b35138-2c37-4b82-894e-59e897ec7d58@kernel.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 0/2] kbuild: remove gcc's -Wtype-limits
2026-01-05 12:24 ` [PATCH v4 0/2] kbuild: remove gcc's -Wtype-limits Nicolas Schier
@ 2026-01-05 20:47 ` Vincent Mailhol
0 siblings, 0 replies; 5+ messages in thread
From: Vincent Mailhol @ 2026-01-05 20:47 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier
Cc: Nick Desaulniers, Bill Wendling, Justin Stitt, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Chris Mason, David Sterba, Kees Cook, Gustavo A. R. Silva,
Linus Torvalds, linux-kbuild, linux-sparse, linux-kernel, llvm,
dri-devel, linux-btrfs, linux-hardening, Daniel Plakosh
On 05/01/2026 at 13:24, Nicolas Schier wrote:
> On Thu, Jan 01, 2026 at 04:21:38PM +0100, Vincent Mailhol wrote:
>> I often read on the mailing list people saying "who cares about W=2
>> builds anyway?". At least I do. Not that I want to fix all of them,
>> but on some occasions, such as new driver submissions, I have often
>> found a couple valid diagnostics in the W=2 output.
>>
>> That said, the annoying thing is that W=2 is heavily polluted by one
>> warning: -Wtype-limits. Try a gcc W=2 build on any file and see the
>> results for yourself. I suspect this to be the reason why so few
>> people are using W=2.
>>
>> This series removes gcc's -Wtype-limits in an attempt to make W=2 more
>> useful. Those who do not use W=2 can continue to not use it if they
>> want. Those who, like me, use it for time to time will get an improved
>> experience from the reduced spam.
>>
>> Patch #1 deactivates -Wtype-limits. Extra details on statistics, past
>> attempts and alternatives are given in the description.
>>
>> Patch #2 clean-ups the local Kbuild -Wno-type-limits exceptions.
>>
>> Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
>> ---
>> Changes in v4:
>>
>> - Remove patch #3.
>> - Aside from minor changes in the patch descriptions, this is
>> basially a revert to v1.
>>
>> Link to v3: https://lore.kernel.org/r/20251220-remove_wtype-limits-v3-0-24b170af700e@kernel.org
>
> just to prevent confusions: As Dan silenced the Smatch warning caused
> by patch #3 [1] (thanks!), the additional comment patch [2] is obsolete
> and v3 of the series is a more complete version than v4.
Exactly!
Thanks to Daniel's effort we finally have a complete fix.
Let me know if you need any actions from my side. Otherwise, I will
assume that my part of the work is done here and will just wait for the
v3 to be picked.
(I am so happy to start 2026 by getting rid of this annoying
-Wtype-limits spam :D)
Yours sincerely,
Vincent Mailhol
^ permalink raw reply [flat|nested] 5+ messages in thread