Re: lib/test_bitmap.c:920:2: error: call to '__compiletime_assert_239' declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(res)

From: Andy Shevchenko
Date: Thu Jun 15 2023 - 07:23:02 EST


On Thu, Jun 15, 2023 at 02:32:02PM +0800, kernel test robot wrote:
> Hi Alexander,
>
> FYI, the error/warning still remains.
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: b6dad5178ceaf23f369c3711062ce1f2afc33644
> commit: dc34d5036692c614eef23c1130ee42a201c316bf lib: test_bitmap: add compile-time optimization/evaluations assertions
> date: 12 months ago
> config: arm64-randconfig-r025-20230615 (https://download.01.org/0day-ci/archive/20230615/202306151433.QKcn7ZNn-lkp@xxxxxxxxx/config)
> compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
> reproduce (this is a W=1 build):
> mkdir -p ~/bin
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # install arm64 cross compiling tool for clang build
> # apt-get install binutils-aarch64-linux-gnu
> # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=dc34d5036692c614eef23c1130ee42a201c316bf
> git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> git fetch --no-tags linus master
> git checkout dc34d5036692c614eef23c1130ee42a201c316bf
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm64 olddefconfig
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash lib/
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@xxxxxxxxx>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202306151433.QKcn7ZNn-lkp@xxxxxxxxx/
>
> All errors (new ones prefixed by >>):

> 888 /*
> 889 * Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }`.
> 890 * Clang on s390 optimizes bitops at compile-time as intended, but at
> 891 * the same time stops treating @bitmap and @bitopvar as compile-time
> 892 * constants after regular test_bit() is executed, thus triggering the
> 893 * build bugs below. So, call const_test_bit() there directly until
> 894 * the compiler is fixed.
> 895 */
> 896 bitmap_clear(bitmap, 0, BITS_PER_LONG);
> 897 #if defined(__s390__) && defined(__clang__)
> 898 if (!const_test_bit(7, bitmap))
> 899 #else
> 900 if (!test_bit(7, bitmap))
> 901 #endif

Hmm... Reveals the bug in clang/arm64?

> 919 res = !test_bit(18, &bitopvar);
> > 920 BUILD_BUG_ON(!__builtin_constant_p(res));
> 921 BUILD_BUG_ON(!res);


--
With Best Regards,
Andy Shevchenko