2023-06-15 07:01:29

by kernel test robot

[permalink] [raw]
Subject: lib/test_bitmap.c:920:2: error: call to '__compiletime_assert_239' declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(res)

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/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> lib/test_bitmap.c:920:2: error: call to '__compiletime_assert_239' 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>:185:1: note: expanded from here
__compiletime_assert_239
^
1 error generated.


vim +920 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 /*
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
902 bitmap_set(bitmap, 5, 2);
903
904 /* Equals to `unsigned long bitopvar = BIT(20)` */
905 __change_bit(31, &bitopvar);
906 bitmap_shift_right(&bitopvar, &bitopvar, 11, BITS_PER_LONG);
907
908 /* Equals to `unsigned long var = BIT(25)` */
909 var |= BIT(25);
910 if (var & BIT(0))
911 var ^= GENMASK(9, 6);
912
913 /* __const_hweight<32|64>(GENMASK(6, 5)) == 2 */
914 res = bitmap_weight(bitmap, 20);
915 BUILD_BUG_ON(!__builtin_constant_p(res));
916 BUILD_BUG_ON(res != 2);
917
918 /* !(BIT(31) & BIT(18)) == 1 */
919 res = !test_bit(18, &bitopvar);
> 920 BUILD_BUG_ON(!__builtin_constant_p(res));
921 BUILD_BUG_ON(!res);
922
923 /* BIT(2) & GENMASK(14, 8) == 0 */
924 res = initvar & GENMASK(14, 8);
925 BUILD_BUG_ON(!__builtin_constant_p(res));
926 BUILD_BUG_ON(res);
927
928 /* ~BIT(25) */
929 BUILD_BUG_ON(!__builtin_constant_p(~var));
930 BUILD_BUG_ON(~var != ~BIT(25));
931 }
932

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


2023-06-15 12:16:22

by Andy Shevchenko

[permalink] [raw]
Subject: 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)

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/[email protected]/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 <[email protected]>
> | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>
> 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



2023-06-15 20:12:05

by Nick Desaulniers

[permalink] [raw]
Subject: 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)

On Thu, Jun 15, 2023 at 7:22 AM Andy Shevchenko
<[email protected]> wrote:
>
> 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/[email protected]/config)

^ randconfig

> > 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 <[email protected]>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
> >
> > 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?

Seems related to the config. ARCH=arm64 defconfig +
CONFIG_TEST_BITMAP=y doesn't trigger this for me, but the randconfig
does. We'll bisect the config, and update the thread tracking this:
https://github.com/ClangBuiltLinux/linux/issues/1874

>
> > 919 res = !test_bit(18, &bitopvar);
> > > 920 BUILD_BUG_ON(!__builtin_constant_p(res));
> > 921 BUILD_BUG_ON(!res);
>
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
>


--
Thanks,
~Nick Desaulniers

2023-06-15 21:09:50

by Nick Desaulniers

[permalink] [raw]
Subject: 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)

On Thu, Jun 15, 2023 at 3:52 PM Nick Desaulniers
<[email protected]> wrote:
>
> On Thu, Jun 15, 2023 at 7:22 AM Andy Shevchenko
> <[email protected]> wrote:
> >
> > 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/[email protected]/config)
>
> ^ randconfig
>
> > > 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 <[email protected]>
> > > | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
> > >
> > > 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?
>
> Seems related to the config. ARCH=arm64 defconfig +
> CONFIG_TEST_BITMAP=y doesn't trigger this for me, but the randconfig
> does. We'll bisect the config, and update the thread tracking this:
> https://github.com/ClangBuiltLinux/linux/issues/1874

KASAN and GCOV together seem to be tickling this.

>
> >
> > > 919 res = !test_bit(18, &bitopvar);
> > > > 920 BUILD_BUG_ON(!__builtin_constant_p(res));
> > > 921 BUILD_BUG_ON(!res);
> >
> >
> > --
> > With Best Regards,
> > Andy Shevchenko
> >
> >
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers



--
Thanks,
~Nick Desaulniers

2023-06-16 14:15:04

by Alexander Lobakin

[permalink] [raw]
Subject: 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: Nick Desaulniers <[email protected]>
Date: Thu, 15 Jun 2023 16:48:22 -0400

> On Thu, Jun 15, 2023 at 3:52 PM Nick Desaulniers
> <[email protected]> wrote:
>>
>> On Thu, Jun 15, 2023 at 7:22 AM Andy Shevchenko
>> <[email protected]> wrote:

[...]

>>>> 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?
>>
>> Seems related to the config. ARCH=arm64 defconfig +
>> CONFIG_TEST_BITMAP=y doesn't trigger this for me, but the randconfig
>> does. We'll bisect the config, and update the thread tracking this:
>> https://github.com/ClangBuiltLinux/linux/issues/1874
>
> KASAN and GCOV together seem to be tickling this.

Thanks for root-causing this!
Should I prepare a patch which would work around KASAN + GCOV here or
you're digging the Clang sources for potential issues?

>
>>
>>>
>>>> 919 res = !test_bit(18, &bitopvar);
>>>> > 920 BUILD_BUG_ON(!__builtin_constant_p(res));
>>>> 921 BUILD_BUG_ON(!res);
>>>
>>>
>>> --
>>> With Best Regards,
>>> Andy Shevchenko
>>>
>>>
>>>
>>
>>
>> --
>> Thanks,
>> ~Nick Desaulniers
>
>
>

Thanks,
Olek