[alobakin:bitops 8/8] lib/test_bitmap.c:904:2: error: call to __compiletime_assert_233 declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(res)

From: kernel test robot
Date: Wed Jun 22 2022 - 01:47:02 EST


tree: https://github.com/alobakin/linux bitops
head: 53dc46e3f72d9b77c9c4ec23a3261d452b3bd67a
commit: 53dc46e3f72d9b77c9c4ec23a3261d452b3bd67a [8/8] lib: test_bitmap: add compile-time optimization/evaluations assertions
config: s390-randconfig-r044-20220622 (https://download.01.org/0day-ci/archive/20220622/202206221354.8jzbVLLL-lkp@xxxxxxxxx/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 8b8d126598ce7bd5243da7f94f69fa1104288bee)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/alobakin/linux/commit/53dc46e3f72d9b77c9c4ec23a3261d452b3bd67a
git remote add alobakin https://github.com/alobakin/linux
git fetch --no-tags alobakin bitops
git checkout 53dc46e3f72d9b77c9c4ec23a3261d452b3bd67a
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash lib/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All errors (new ones prefixed by >>):

>> lib/test_bitmap.c:904:2: error: call to __compiletime_assert_233 declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(res)
BUILD_BUG_ON(!__builtin_constant_p(res));
^
include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
^
include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^
include/linux/compiler_types.h:352:2: note: expanded from macro 'compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^
include/linux/compiler_types.h:340:2: note: expanded from macro '_compiletime_assert'
__compiletime_assert(condition, msg, prefix, suffix)
^
include/linux/compiler_types.h:333:4: note: expanded from macro '__compiletime_assert'
prefix ## suffix(); \
^
<scratch space>:180:1: note: expanded from here
__compiletime_assert_233
^
1 error generated.


vim +/error +904 lib/test_bitmap.c

871
872 static void __init test_bitmap_const_eval(void)
873 {
874 DECLARE_BITMAP(bitmap, BITS_PER_LONG);
875 unsigned long initvar = BIT(2);
876 unsigned long bitopvar = 0;
877 unsigned long var = 0;
878 int res;
879
880 /*
881 * Compilers must be able to optimize all of those to compile-time
882 * constants on any supported optimization level (-O2, -Os) and any
883 * architecture. Otherwise, trigger a build bug.
884 * The whole function gets optimized out then, there's nothing to do
885 * in runtime.
886 */
887
888 /* Equals to `unsigned long bitmap[1] = { BIT(5), }` */
889 bitmap_clear(bitmap, 0, BITS_PER_LONG);
890 if (!test_bit(7, bitmap))
891 bitmap_set(bitmap, 5, 1);
892
893 /* Equals to `unsigned long bitopvar = BIT(20)` */
894 __change_bit(31, &bitopvar);
895 bitmap_shift_right(&bitopvar, &bitopvar, 11, BITS_PER_LONG);
896
897 /* Equals to `unsigned long var = BIT(25)` */
898 var |= BIT(25);
899 if (var & BIT(0))
900 var ^= GENMASK(9, 6);
901
902 /* __const_hweight<32|64>(BIT(5)) == 1 */
903 res = bitmap_weight(bitmap, 20);
> 904 BUILD_BUG_ON(!__builtin_constant_p(res));
905
906 /* !(BIT(31) & BIT(18)) == 1 */
907 res = !test_bit(18, &bitopvar);
908 BUILD_BUG_ON(!__builtin_constant_p(res));
909
910 /* BIT(2) & GENMASK(14, 8) == 0 */
911 BUILD_BUG_ON(!__builtin_constant_p(initvar & GENMASK(14, 8)));
912 /* ~BIT(25) */
913 BUILD_BUG_ON(!__builtin_constant_p(~var));
914 }
915

--
0-DAY CI Kernel Test Service
https://01.org/lkp