Linux: -Wconstant-conversion in arch/x86/kvm/mmu.c

Created on 17 Sep 2018  路  9Comments  路  Source: ClangBuiltLinux/linux

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.
-Wconstant-conversion [ARCH] x86_64 [BUG] linux [FIXED][LINUX] 5.3

Most helpful comment

All 9 comments

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

[1] https://lore.kernel.org/lkml/[email protected]/

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.

@arndb sent a patch that's been accepted but not pushed yet: https://www.mail-archive.com/[email protected]/msg2048148.html

Was this page helpful?
0 / 5 - 0 ratings