Skip to content

Commit 7adaf37

Browse files
alobakindavem330
authored andcommitted
lib/bitmap: add compile-time test for __assign_bit() optimization
Commit dc34d50 ("lib: test_bitmap: add compile-time optimization/evaluations assertions") initially missed __assign_bit(), which led to that quite a time passed before I realized it doesn't get optimized at compilation time. Now that it does, add test for that just to make sure nothing will break one day. To make things more interesting, use bitmap_complement() and bitmap_full(), thus checking their compile-time evaluation as well. And remove the misleading comment mentioning the workaround removed recently in favor of adding the whole file to GCov exceptions. Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Signed-off-by: Yury Norov <yury.norov@gmail.com> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b447597 commit 7adaf37

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/test_bitmap.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,14 +1245,7 @@ static void __init test_bitmap_const_eval(void)
12451245
* in runtime.
12461246
*/
12471247

1248-
/*
1249-
* Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }`.
1250-
* Clang on s390 optimizes bitops at compile-time as intended, but at
1251-
* the same time stops treating @bitmap and @bitopvar as compile-time
1252-
* constants after regular test_bit() is executed, thus triggering the
1253-
* build bugs below. So, call const_test_bit() there directly until
1254-
* the compiler is fixed.
1255-
*/
1248+
/* Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }` */
12561249
bitmap_clear(bitmap, 0, BITS_PER_LONG);
12571250
if (!test_bit(7, bitmap))
12581251
bitmap_set(bitmap, 5, 2);
@@ -1284,6 +1277,15 @@ static void __init test_bitmap_const_eval(void)
12841277
/* ~BIT(25) */
12851278
BUILD_BUG_ON(!__builtin_constant_p(~var));
12861279
BUILD_BUG_ON(~var != ~BIT(25));
1280+
1281+
/* ~BIT(25) | BIT(25) == ~0UL */
1282+
bitmap_complement(&var, &var, BITS_PER_LONG);
1283+
__assign_bit(25, &var, true);
1284+
1285+
/* !(~(~0UL)) == 1 */
1286+
res = bitmap_full(&var, BITS_PER_LONG);
1287+
BUILD_BUG_ON(!__builtin_constant_p(res));
1288+
BUILD_BUG_ON(!res);
12871289
}
12881290

12891291
/*

0 commit comments

Comments
 (0)