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

selftests/bpf: Fix "expression result unused" warnings with icecc

icecc is a compiler wrapper that distributes compile jobs over a build
farm [1]. It works by sending toolchain binaries and preprocessed
source code to remote machines.

Unfortunately using it with BPF selftests causes build failures due to
a clang bug [2]. The problem is that clang suppresses the
-Wunused-value warning if the unused expression comes from a macro
expansion. Since icecc compiles preprocessed source code, this
information is not available. This leads to -Wunused-value false
positives.

obj_new_no_struct() and obj_new_acq() use the bpf_obj_new() macro and
discard the result. arena_spin_lock_slowpath() uses two macros that
produce values and ignores the results. Add (void) casts to explicitly
indicate that this is intentional and suppress the warning.

An alternative solution is to change the macros to not produce values.
This would work today for the arena_spin_lock_slowpath() issue, but in
the future there may appear users who need them. Another potential
solution is to replace these macros with functions. Unfortunately this
would not work, because these macros work with unknown types and
control flow.

[1] https://github.com/icecc/icecream
[2] https://github.com/llvm/llvm-project/issues/142614

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20250829030017.102615-2-iii@linux.ibm.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Ilya Leoshkevich and committed by
Alexei Starovoitov
5d40c038 3aa9b9a1

+4 -5
+2 -2
tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h
··· 302 302 * barriers. 303 303 */ 304 304 if (val & _Q_LOCKED_MASK) 305 - smp_cond_load_acquire_label(&lock->locked, !VAL, release_err); 305 + (void)smp_cond_load_acquire_label(&lock->locked, !VAL, release_err); 306 306 307 307 /* 308 308 * take ownership and clear the pending bit. ··· 380 380 /* Link @node into the waitqueue. */ 381 381 WRITE_ONCE(prev->next, node); 382 382 383 - arch_mcs_spin_lock_contended_label(&node->locked, release_node_err); 383 + (void)arch_mcs_spin_lock_contended_label(&node->locked, release_node_err); 384 384 385 385 /* 386 386 * While waiting for the MCS lock, the next pointer may have
+2 -3
tools/testing/selftests/bpf/progs/linked_list_fail.c
··· 226 226 SEC("?tc") 227 227 int obj_new_no_struct(void *ctx) 228 228 { 229 - 230 - bpf_obj_new(union { int data; unsigned udata; }); 229 + (void)bpf_obj_new(union { int data; unsigned udata; }); 231 230 return 0; 232 231 } 233 232 ··· 251 252 SEC("?tc") 252 253 int obj_new_acq(void *ctx) 253 254 { 254 - bpf_obj_new(struct foo); 255 + (void)bpf_obj_new(struct foo); 255 256 return 0; 256 257 } 257 258