Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Hashmap.h update to fix build issues using LLVM14

A fix for the LLVM compilation error while building bpftool.
Replaces the expression:

_Static_assert((p) == NULL || ...)

by expression:

_Static_assert((__builtin_constant_p((p)) ? (p) == NULL : 0) || ...)

When "p" is not a constant the former is not considered to be a
constant expression by LLVM 14.

The error was introduced in the following patch-set: [1].
The error was reported here: [2].

[1] https://lore.kernel.org/bpf/20221109142611.879983-1-eddyz87@gmail.com/
[2] https://lore.kernel.org/all/202211110355.BcGcbZxP-lkp@intel.com/

Reported-by: kernel test robot <lkp@intel.com>
Fixes: c302378bc157 ("libbpf: Hashmap interface update to allow both long and void* keys/values")
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/20221110223240.1350810-1-eddyz87@gmail.com

authored by

Eduard Zingerman and committed by
Andrii Nakryiko
42597aa3 c7028aa2

+4 -2
+2 -1
tools/lib/bpf/hashmap.h
··· 123 123 }; 124 124 125 125 #define hashmap_cast_ptr(p) ({ \ 126 - _Static_assert((p) == NULL || sizeof(*(p)) == sizeof(long), \ 126 + _Static_assert((__builtin_constant_p((p)) ? (p) == NULL : 0) || \ 127 + sizeof(*(p)) == sizeof(long), \ 127 128 #p " pointee should be a long-sized integer or a pointer"); \ 128 129 (long *)(p); \ 129 130 })
+2 -1
tools/perf/util/hashmap.h
··· 123 123 }; 124 124 125 125 #define hashmap_cast_ptr(p) ({ \ 126 - _Static_assert((p) == NULL || sizeof(*(p)) == sizeof(long), \ 126 + _Static_assert((__builtin_constant_p((p)) ? (p) == NULL : 0) || \ 127 + sizeof(*(p)) == sizeof(long), \ 127 128 #p " pointee should be a long-sized integer or a pointer"); \ 128 129 (long *)(p); \ 129 130 })