Skip to content
  • Arnd Bergmann's avatar
    bd93f003
    include/linux/bitops.h: avoid clang shift-count-overflow warnings · bd93f003
    Arnd Bergmann authored
    
    
    Clang normally does not warn about certain issues in inline functions when
    it only happens in an eliminated code path. However if something else
    goes wrong, it does tend to complain about the definition of hweight_long()
    on 32-bit targets:
    
      include/linux/bitops.h:75:41: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
              return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
                                                     ^~~~~~~~~~~~
      include/asm-generic/bitops/const_hweight.h:29:49: note: expanded from macro 'hweight64'
       define hweight64(w) (__builtin_constant_p(w) ? __const_hweight64(w) : __arch_hweight64(w))
                                                      ^~~~~~~~~~~~~~~~~~~~
      include/asm-generic/bitops/const_hweight.h:21:76: note: expanded from macro '__const_hweight64'
       define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32))
                                                                                 ^  ~~
      include/asm-generic/bitops/const_hweight.h:20:49: note: expanded from macro '__const_hweight32'
       define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))
                                                      ^
      include/asm-generic/bitops/const_hweight.h:19:72: note: expanded from macro '__const_hweight16'
       define __const_hweight16(w) (__const_hweight8(w)  + __const_hweight8((w)  >> 8 ))
                                                                             ^
      include/asm-generic/bitops/const_hweight.h:12:9: note: expanded from macro '__const_hweight8'
                (!!((w) & (1ULL << 2))) +     \
    
    Adding an explicit cast to __u64 avoids that warning and makes it easier
    to read other output.
    
    Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Acked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
    Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
    Cc: Josh Poimboeuf <jpoimboe@redhat.com>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Link: http://lkml.kernel.org/r/20200505135513.65265-1-arnd@arndb.de
    
    
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    bd93f003
    include/linux/bitops.h: avoid clang shift-count-overflow warnings
    Arnd Bergmann authored
    
    
    Clang normally does not warn about certain issues in inline functions when
    it only happens in an eliminated code path. However if something else
    goes wrong, it does tend to complain about the definition of hweight_long()
    on 32-bit targets:
    
      include/linux/bitops.h:75:41: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
              return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
                                                     ^~~~~~~~~~~~
      include/asm-generic/bitops/const_hweight.h:29:49: note: expanded from macro 'hweight64'
       define hweight64(w) (__builtin_constant_p(w) ? __const_hweight64(w) : __arch_hweight64(w))
                                                      ^~~~~~~~~~~~~~~~~~~~
      include/asm-generic/bitops/const_hweight.h:21:76: note: expanded from macro '__const_hweight64'
       define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32))
                                                                                 ^  ~~
      include/asm-generic/bitops/const_hweight.h:20:49: note: expanded from macro '__const_hweight32'
       define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))
                                                      ^
      include/asm-generic/bitops/const_hweight.h:19:72: note: expanded from macro '__const_hweight16'
       define __const_hweight16(w) (__const_hweight8(w)  + __const_hweight8((w)  >> 8 ))
                                                                             ^
      include/asm-generic/bitops/const_hweight.h:12:9: note: expanded from macro '__const_hweight8'
                (!!((w) & (1ULL << 2))) +     \
    
    Adding an explicit cast to __u64 avoids that warning and makes it easier
    to read other output.
    
    Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Acked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
    Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
    Cc: Josh Poimboeuf <jpoimboe@redhat.com>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Link: http://lkml.kernel.org/r/20200505135513.65265-1-arnd@arndb.de
    
    
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Loading