* [PATCH v2] kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1
@ 2024-03-05 22:12 Nathan Chancellor
2024-03-05 22:20 ` Arnd Bergmann
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Nathan Chancellor @ 2024-03-05 22:12 UTC (permalink / raw)
To: masahiroy
Cc: nicolas, ndesaulniers, morbo, justinstitt, arnd, yonghong.song,
linux-kbuild, llvm, patches, stable, Nathan Chancellor
Clang enables -Wenum-enum-conversion and -Wenum-compare-conditional
under -Wenum-conversion. A recent change in Clang strengthened these
warnings and they appear frequently in common builds, primarily due to
several instances in common headers but there are quite a few drivers
that have individual instances as well.
include/linux/vmstat.h:508:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
508 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
509 | item];
| ~~~~
drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c:955:24: warning: conditional expression between different enumeration types ('enum iwl_mac_beacon_flags' and 'enum iwl_mac_beacon_flags_v1') [-Wenum-compare-conditional]
955 | flags |= is_new_rate ? IWL_MAC_BEACON_CCK
| ^ ~~~~~~~~~~~~~~~~~~
956 | : IWL_MAC_BEACON_CCK_V1;
| ~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c:1120:21: warning: conditional expression between different enumeration types ('enum iwl_mac_beacon_flags' and 'enum iwl_mac_beacon_flags_v1') [-Wenum-compare-conditional]
1120 | 0) > 10 ?
| ^
1121 | IWL_MAC_BEACON_FILS :
| ~~~~~~~~~~~~~~~~~~~
1122 | IWL_MAC_BEACON_FILS_V1;
| ~~~~~~~~~~~~~~~~~~~~~~
Doing arithmetic between or returning two different types of enums could
be a bug, so each of the instance of the warning needs to be evaluated.
Unfortunately, as mentioned above, there are many instances of this
warning in many different configurations, which can break the build when
CONFIG_WERROR is enabled.
To avoid introducing new instances of the warnings while cleaning up the
disruption for the majority of users, disable these warnings for the
default build while leaving them on for W=1 builds.
Cc: stable@vger.kernel.org
Closes: https://github.com/ClangBuiltLinux/linux/issues/2002
Link: https://github.com/llvm/llvm-project/commit/8c2ae42b3e1c6aa7c18f873edcebff7c0b45a37e
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
Changes in v2:
- Only disable the warning for the default build, leave it on for W=1 (Arnd)
- Add Yonghong's ack, as the warning is still disabled for the default
build.
- Link to v1: https://lore.kernel.org/r/20240305-disable-extra-clang-enum-warnings-v1-1-6a93ef3d35ff@kernel.org
---
| 2 ++
1 file changed, 2 insertions(+)
--git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index a9e552a1e910..2f25a1de129d 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -132,6 +132,8 @@ KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
KBUILD_CFLAGS += $(call cc-disable-warning, cast-function-type-strict)
+KBUILD_CFLAGS += -Wno-enum-compare-conditional
+KBUILD_CFLAGS += -Wno-enum-enum-conversion
endif
endif
---
base-commit: 90d35da658da8cff0d4ecbb5113f5fac9d00eb72
change-id: 20240304-disable-extra-clang-enum-warnings-bf574c7c99fd
Best regards,
--
Nathan Chancellor <nathan@kernel.org>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1
2024-03-05 22:12 [PATCH v2] kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 Nathan Chancellor
@ 2024-03-05 22:20 ` Arnd Bergmann
2024-03-10 12:53 ` Masahiro Yamada
2024-03-10 17:02 ` David Laight
2 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2024-03-05 22:20 UTC (permalink / raw)
To: Nathan Chancellor, Masahiro Yamada
Cc: Nicolas Schier, Nick Desaulniers, Bill Wendling, Justin Stitt,
Yonghong Song, linux-kbuild, llvm, patches, stable
On Tue, Mar 5, 2024, at 23:12, Nathan Chancellor wrote:
> Cc: stable@vger.kernel.org
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2002
> Link:
> https://github.com/llvm/llvm-project/commit/8c2ae42b3e1c6aa7c18f873edcebff7c0b45a37e
> Acked-by: Yonghong Song <yonghong.song@linux.dev>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1
2024-03-05 22:12 [PATCH v2] kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 Nathan Chancellor
2024-03-05 22:20 ` Arnd Bergmann
@ 2024-03-10 12:53 ` Masahiro Yamada
2024-03-10 17:02 ` David Laight
2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2024-03-10 12:53 UTC (permalink / raw)
To: Nathan Chancellor
Cc: nicolas, ndesaulniers, morbo, justinstitt, arnd, yonghong.song,
linux-kbuild, llvm, patches, stable
On Wed, Mar 6, 2024 at 7:12 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> Clang enables -Wenum-enum-conversion and -Wenum-compare-conditional
> under -Wenum-conversion. A recent change in Clang strengthened these
> warnings and they appear frequently in common builds, primarily due to
> several instances in common headers but there are quite a few drivers
> that have individual instances as well.
>
> include/linux/vmstat.h:508:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
> 508 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
> | ~~~~~~~~~~~~~~~~~~~~~ ^
> 509 | item];
> | ~~~~
>
> drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c:955:24: warning: conditional expression between different enumeration types ('enum iwl_mac_beacon_flags' and 'enum iwl_mac_beacon_flags_v1') [-Wenum-compare-conditional]
> 955 | flags |= is_new_rate ? IWL_MAC_BEACON_CCK
> | ^ ~~~~~~~~~~~~~~~~~~
> 956 | : IWL_MAC_BEACON_CCK_V1;
> | ~~~~~~~~~~~~~~~~~~~~~
> drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c:1120:21: warning: conditional expression between different enumeration types ('enum iwl_mac_beacon_flags' and 'enum iwl_mac_beacon_flags_v1') [-Wenum-compare-conditional]
> 1120 | 0) > 10 ?
> | ^
> 1121 | IWL_MAC_BEACON_FILS :
> | ~~~~~~~~~~~~~~~~~~~
> 1122 | IWL_MAC_BEACON_FILS_V1;
> | ~~~~~~~~~~~~~~~~~~~~~~
>
> Doing arithmetic between or returning two different types of enums could
> be a bug, so each of the instance of the warning needs to be evaluated.
> Unfortunately, as mentioned above, there are many instances of this
> warning in many different configurations, which can break the build when
> CONFIG_WERROR is enabled.
>
> To avoid introducing new instances of the warnings while cleaning up the
> disruption for the majority of users, disable these warnings for the
> default build while leaving them on for W=1 builds.
>
> Cc: stable@vger.kernel.org
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2002
> Link: https://github.com/llvm/llvm-project/commit/8c2ae42b3e1c6aa7c18f873edcebff7c0b45a37e
> Acked-by: Yonghong Song <yonghong.song@linux.dev>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> Changes in v2:
> - Only disable the warning for the default build, leave it on for W=1 (Arnd)
> - Add Yonghong's ack, as the warning is still disabled for the default
> build.
> - Link to v1: https://lore.kernel.org/r/20240305-disable-extra-clang-enum-warnings-v1-1-6a93ef3d35ff@kernel.org
Applied to linux-kbuild.
Thanks.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH v2] kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1
2024-03-05 22:12 [PATCH v2] kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 Nathan Chancellor
2024-03-05 22:20 ` Arnd Bergmann
2024-03-10 12:53 ` Masahiro Yamada
@ 2024-03-10 17:02 ` David Laight
2 siblings, 0 replies; 4+ messages in thread
From: David Laight @ 2024-03-10 17:02 UTC (permalink / raw)
To: 'Nathan Chancellor', masahiroy@kernel.org
Cc: nicolas@fjasle.eu, ndesaulniers@google.com, morbo@google.com,
justinstitt@google.com, arnd@arndb.de, yonghong.song@linux.dev,
linux-kbuild@vger.kernel.org, llvm@lists.linux.dev,
patches@lists.linux.dev, stable@vger.kernel.org
From: Nathan Chancellor
> Sent: 05 March 2024 22:13
...
> drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c:1120:21: warning: conditional
> expression between different enumeration types ('enum iwl_mac_beacon_flags' and
> 'enum iwl_mac_beacon_flags_v1') [-Wenum-compare-conditional]
> 1120 | 0) > 10 ?
> | ^
> 1121 | IWL_MAC_BEACON_FILS :
> | ~~~~~~~~~~~~~~~~~~~
> 1122 | IWL_MAC_BEACON_FILS_V1;
> | ~~~~~~~~~~~~~~~~~~~~~~
>
> Doing arithmetic between or returning two different types of enums could
> be a bug, so each of the instance of the warning needs to be evaluated.
> Unfortunately, as mentioned above, there are many instances of this
> warning in many different configurations, which can break the build when
> CONFIG_WERROR is enabled.
I'm not sure what is being done to avoid this warning.
(Apart from not using enum to define related integer constants.)
Until the compilers get even more clever^Wstupid perhaps the
simplest way is to just add '+ 0' to one of the enum values.
In code terms it is much safer than any cast.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-10 17:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-05 22:12 [PATCH v2] kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 Nathan Chancellor
2024-03-05 22:20 ` Arnd Bergmann
2024-03-10 12:53 ` Masahiro Yamada
2024-03-10 17:02 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).