kbuild: remove gcc's -Wtype-limits
Subsystems (5)
v4 cover kbuild: remove gcc's -Wtype-limits
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.
---
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/[email protected]
Changes in v3:
- Remove patch #4.
Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Add two more patches to clean up some -Wtype-limits workarounds
- Collect the Reviewed-by tags.
Link to v1: https://lore.kernel.org/r/[email protected]
---
Vincent Mailhol (2):
kbuild: remove gcc's -Wtype-limits
kbuild: cleanup local -Wno-type-limits exceptions
drivers/gpu/drm/Makefile | 1 - fs/btrfs/Makefile | 1 - scripts/Makefile.warn | 4 +++- 3 files changed, 3 insertions(+), 3 deletions(-)
---
base-commit: 82791741762a870f5f2ede9f909301770f66f867
change-id: 20251205-remove_wtype-limits-c77eb46d09c2
Best regards,
Signature · 1 line
Vincent Mailhol <[email protected]>
PATCH v4 1/2 kbuild: remove gcc's -Wtype-limits
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
[2] Warn about "unsigned value that used to be signed against zero"
[3] clang's -Wtype-limits
---
**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(-)
scripts/Makefile.warn +3 -1
@@ -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
Signature · 1 line
2.52.0
PATCH v4 2/2 kbuild: cleanup local -Wno-type-limits exceptions
In reply to Vincent MailholNow that -Wtype-limits is globally deactivated, there is no need for local exceptions anymore.
---
Changelog:
v1 -> v2: small change in patch description
--- drivers/gpu/drm/Makefile | 1 - fs/btrfs/Makefile | 1 - 2 files changed, 2 deletions(-)
drivers/gpu/drm/Makefile +0 -1
@@ -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)),)
fs/btrfs/Makefile +0 -1
@@ -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
Signature · 1 line
2.52.0
Nicolas Schier
maintainerQuoted 21 lines · Vincent Mailhol
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 <[email protected]>
Quoted 8 lines
---
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/[email protected]
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/[email protected]/
Quoted 29 lines · Nicolas Schier
Quoted 28 lines · Vincent Mailhol
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 <[email protected]>---
Changes in v4:- Remove patch #3.
- Aside from minor changes in the patch descriptions, this is basially a revert to v1.
Quoted 5 lines
Quoted 1 line
Link to v3: https://lore.kernel.org/r/[email protected]
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