Skip to contentSkip to conversation

kbuild: Enable -Wenum-conversion by default

PATCH In review Borislav Petkov 3 participants 3 messages Jul 4, 2023 – Jul 15, 2023 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: Enable -Wenum-conversion by default

From: "Borislav Petkov (AMD)" <[email protected]>

This diagnostic checks whether there is a type mismatch when converting enums (assign an enum of type A to an enum of type B, for example) and it caught a legit issue recently. The reason it didn't show is because that warning is enabled only with -Wextra with GCC. Clang, however, enables it by default.

GCC folks were considering enabling it by default but it was too noisy back then:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78736

Now that due to clang all those warnings have been fixed, enable it with GCC too.

allmodconfig tests done with: x86, arm{,64}, powerpc{,64}, riscv crossbuilds.

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -0
index 7a5a175f708f..428132b3d6dd 100644
@@ -1082,6 +1082,9 @@ KBUILD_CFLAGS   += $(call cc-option,-Werror=incompatible-pointer-types)
 # Require designated initializers for all marked structures
 KBUILD_CFLAGS   += $(call cc-option,-Werror=designated-init)
 
+# Warn if there is an enum types mismatch
+KBUILD_CFLAGS	+= $(call cc-option,-Wenum-conversion)
+
 # change __FILE__ to the relative path from the srctree
 KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
 
Signature · 1 line
2.41.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Borislav Petkov

From: "Borislav Petkov (AMD)" <[email protected]>

This diagnostic checks whether there is a type mismatch when converting enums (assign an enum of type A to an enum of type B, for example) and it caught a legit issue recently. The reason it didn't show is because that warning is enabled only with -Wextra with GCC. Clang, however, enables it by default.

GCC folks were considering enabling it by default but it was too noisy back then:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78736

Quoted 7 lines

Now that due to clang all those warnings have been fixed, enable it with GCC too.

allmodconfig tests done with: x86, arm{,64}, powerpc{,64}, riscv crossbuilds.

Yes please :)

Quoted 21 lines
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -0
index 7a5a175f708f..428132b3d6dd 100644
@@ -1082,6 +1082,9 @@ KBUILD_CFLAGS   += $(call cc-option,-Werror=incompatible-pointer-types)
 # Require designated initializers for all marked structures
 KBUILD_CFLAGS   += $(call cc-option,-Werror=designated-init)
 
+# Warn if there is an enum types mismatch
+KBUILD_CFLAGS	+= $(call cc-option,-Wenum-conversion)
+
 # change __FILE__ to the relative path from the srctree
 KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
 
Signature · 1 line
2.41.0
#2 lore raw
Quoted 18 lines · Nathan Chancellor
Quoted 16 lines · Borislav Petkov

From: "Borislav Petkov (AMD)" <[email protected]>

This diagnostic checks whether there is a type mismatch when converting enums (assign an enum of type A to an enum of type B, for example) and it caught a legit issue recently. The reason it didn't show is because that warning is enabled only with -Wextra with GCC. Clang, however, enables it by default.

GCC folks were considering enabling it by default but it was too noisy back then:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78736

Now that due to clang all those warnings have been fixed, enable it with GCC too.

Quoted 9 lines
Quoted 4 lines

allmodconfig tests done with: x86, arm{,64}, powerpc{,64}, riscv crossbuilds.

Yes please :)

Applied to linux-kbuild.
Thanks.

Signature · 2 lines
Best Regards
Masahiro Yamada