From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Yury Norov <yury.norov@gmail.com>, Kees Cook <kees@kernel.org>,
"Nick Desaulniers" <ndesaulniers@google.com>
Cc: <oe-kbuild-all@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
"Przemek Kitszel" <przemyslaw.kitszel@intel.com>,
kernel test robot <lkp@intel.com>, <llvm@lists.linux.dev>
Subject: Re: lib/test_bitmap.c:1278:2: error: call to '__compiletime_assert_127' declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(~var)
Date: Tue, 13 Aug 2024 16:38:10 +0200 [thread overview]
Message-ID: <2690861a-e726-4149-98ff-d26ec6d595ac@intel.com> (raw)
In-Reply-To: <202408131601.Aj9JmK7K-lkp@intel.com>
From: Kernel Test Robot <lkp@intel.com>
Date: Tue, 13 Aug 2024 17:00:56 +0800
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: d74da846046aeec9333e802f5918bd3261fb5509
> commit: 7adaf37f7f104a7ee5f150af491674ccbbfc4114 lib/bitmap: add compile-time test for __assign_bit() optimization
> date: 4 months ago
> config: um-randconfig-r132-20240812 (https://download.01.org/0day-ci/archive/20240813/202408131601.Aj9JmK7K-lkp@intel.com/config)
> compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project f86594788ce93b696675c94f54016d27a6c21d18)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240813/202408131601.Aj9JmK7K-lkp@intel.com/reproduce)
>
> 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@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202408131601.Aj9JmK7K-lkp@intel.com/
>
> All errors (new ones prefixed by >>):
>
>>> lib/test_bitmap.c:1278:2: error: call to '__compiletime_assert_127' declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(~var)
> 1278 | BUILD_BUG_ON(!__builtin_constant_p(~var));
> | ^
> include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
> 50 | 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'
> 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> | ^
> include/linux/compiler_types.h:460:2: note: expanded from macro 'compiletime_assert'
> 460 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> | ^
> include/linux/compiler_types.h:448:2: note: expanded from macro '_compiletime_assert'
> 448 | __compiletime_assert(condition, msg, prefix, suffix)
> | ^
> include/linux/compiler_types.h:441:4: note: expanded from macro '__compiletime_assert'
> 441 | prefix ## suffix(); \
> | ^
> <scratch space>:193:1: note: expanded from here
> 193 | __compiletime_assert_127
> | ^
> 1 error generated.
>
>
> vim +1278 lib/test_bitmap.c
>
> 291f93ca339f5b Barry Song 2021-08-06 1227
> 2356d198d2b4dd Yury Norov 2023-07-17 1228 /*
> 2356d198d2b4dd Yury Norov 2023-07-17 1229 * FIXME: Clang breaks compile-time evaluations when KASAN and GCOV are enabled.
> 2356d198d2b4dd Yury Norov 2023-07-17 1230 * To workaround it, GCOV is force-disabled in Makefile for this configuration.
> 2356d198d2b4dd Yury Norov 2023-07-17 1231 */
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1232 static void __init test_bitmap_const_eval(void)
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1233 {
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1234 DECLARE_BITMAP(bitmap, BITS_PER_LONG);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1235 unsigned long initvar = BIT(2);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1236 unsigned long bitopvar = 0;
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1237 unsigned long var = 0;
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1238 int res;
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1239
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1240 /*
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1241 * Compilers must be able to optimize all of those to compile-time
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1242 * constants on any supported optimization level (-O2, -Os) and any
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1243 * architecture. Otherwise, trigger a build bug.
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1244 * The whole function gets optimized out then, there's nothing to do
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1245 * in runtime.
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1246 */
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1247
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1248 /* Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }` */
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1249 bitmap_clear(bitmap, 0, BITS_PER_LONG);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1250 if (!test_bit(7, bitmap))
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1251 bitmap_set(bitmap, 5, 2);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1252
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1253 /* Equals to `unsigned long bitopvar = BIT(20)` */
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1254 __change_bit(31, &bitopvar);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1255 bitmap_shift_right(&bitopvar, &bitopvar, 11, BITS_PER_LONG);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1256
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1257 /* Equals to `unsigned long var = BIT(25)` */
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1258 var |= BIT(25);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1259 if (var & BIT(0))
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1260 var ^= GENMASK(9, 6);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1261
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1262 /* __const_hweight<32|64>(GENMASK(6, 5)) == 2 */
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1263 res = bitmap_weight(bitmap, 20);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1264 BUILD_BUG_ON(!__builtin_constant_p(res));
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1265 BUILD_BUG_ON(res != 2);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1266
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1267 /* !(BIT(31) & BIT(18)) == 1 */
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1268 res = !test_bit(18, &bitopvar);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1269 BUILD_BUG_ON(!__builtin_constant_p(res));
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1270 BUILD_BUG_ON(!res);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1271
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1272 /* BIT(2) & GENMASK(14, 8) == 0 */
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1273 res = initvar & GENMASK(14, 8);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1274 BUILD_BUG_ON(!__builtin_constant_p(res));
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1275 BUILD_BUG_ON(res);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1276
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1277 /* ~BIT(25) */
> dc34d5036692c6 Alexander Lobakin 2022-06-24 @1278 BUILD_BUG_ON(!__builtin_constant_p(~var));
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1279 BUILD_BUG_ON(~var != ~BIT(25));
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1280
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1281 /* ~BIT(25) | BIT(25) == ~0UL */
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1282 bitmap_complement(&var, &var, BITS_PER_LONG);
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1283 __assign_bit(25, &var, true);
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1284
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1285 /* !(~(~0UL)) == 1 */
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1286 res = bitmap_full(&var, BITS_PER_LONG);
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1287 BUILD_BUG_ON(!__builtin_constant_p(res));
> 7adaf37f7f104a Alexander Lobakin 2024-03-27 1288 BUILD_BUG_ON(!res);
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1289 }
> dc34d5036692c6 Alexander Lobakin 2022-06-24 1290
>
> :::::: The code at line 1278 was first introduced by commit
> :::::: dc34d5036692c614eef23c1130ee42a201c316bf lib: test_bitmap: add compile-time optimization/evaluations assertions
>
> :::::: TO: Alexander Lobakin <alexandr.lobakin@intel.com>
> :::::: CC: Yury Norov <yury.norov@gmail.com>
+ Cc Clang folks.
clang-dev 20 issue?
Thanks,
Olek
next prev parent reply other threads:[~2024-08-13 14:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-13 9:00 lib/test_bitmap.c:1278:2: error: call to '__compiletime_assert_127' declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(~var) kernel test robot
2024-08-13 14:38 ` Alexander Lobakin [this message]
2024-08-13 19:47 ` Yury Norov
2024-08-13 22:12 ` Nathan Chancellor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2690861a-e726-4149-98ff-d26ec6d595ac@intel.com \
--to=aleksander.lobakin@intel.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=llvm@lists.linux.dev \
--cc=ndesaulniers@google.com \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=przemyslaw.kitszel@intel.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.