arch/x86/kvm/mmu.c:4519:39: warning: implicit conversion from 'int' to 'u8' (aka 'unsigned char') changes value from -205 to 51
[-Wconstant-conversion]
u8 wf = (pfec & PFERR_WRITE_MASK) ? ~w : 0;
~~ ^~
arch/x86/kvm/mmu.c:4521:38: warning: implicit conversion from 'int' to 'u8' (aka 'unsigned char') changes value from -241 to 15
[-Wconstant-conversion]
u8 uf = (pfec & PFERR_USER_MASK) ? ~u : 0;
~~ ^~
arch/x86/kvm/mmu.c:4523:39: warning: implicit conversion from 'int' to 'u8' (aka 'unsigned char') changes value from -171 to 85
[-Wconstant-conversion]
u8 ff = (pfec & PFERR_FETCH_MASK) ? ~x : 0;
~~ ^~
3 warnings generated.
I thought I remembered seeing this warning somewhere then I remembered that @mkaehlcke sent a fix for this upstream: https://lore.kernel.org/lkml/[email protected]/
Seems like nothing came from that thread, Joe Perches suggested turning off the warning: https://lore.kernel.org/lkml/[email protected]/
Disabled in chromeos-4.14 too: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1137347
Looks like good compromise to me - rathan than brutally turning it off (added a missing comma to the cc-option check):
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 8d5357053f86..9b1d0d59e8d0 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -46,6 +46,7 @@ warning-2 += $(call cc-option, -Wunused-macros)
warning-3 := -Wbad-function-cast
warning-3 += -Wcast-qual
warning-3 += -Wconversion
+warning-3 += $(call cc-option, -Wconstant-conversion)
warning-3 += -Wpacked
warning-3 += -Wpadded
warning-3 += -Wpointer-arith
I've fixed all constant conversion warnings in arm{32,64} and x86 {def,allyes}config builds, this is the only one that is still around: https://github.com/ClangBuiltLinux/linux/issues?q=label%3A-Wconstant-conversion
I'd rather not see this warning disabled personally.
This is the last warning I see with clang, the rest are objtool warnings.
As an alternative...
x86-kvm-clang-Disable-Wconstant-conversion-warning_patch.txt
@arndb sent a patch that's been accepted but not pushed yet: https://www.mail-archive.com/[email protected]/msg2048148.html
Arnd鈥檚 patch is now in -next: https://git.kernel.org/next/linux-next/c/a6a6d3b1f867d34ba5bd61aa7bb056b48ca67cff
Merged into mainline: https://git.kernel.org/linus/a6a6d3b1f867d34ba5bd61aa7bb056b48ca67cff
Most helpful comment
Arnd鈥檚 patch is now in -next: https://git.kernel.org/next/linux-next/c/a6a6d3b1f867d34ba5bd61aa7bb056b48ca67cff