selftests/bpf: Fix "expression result unused" warnings
Subsystems (3)
PATCH 1/1 selftests/bpf: Fix "expression result unused" warnings
clang-21 complains about unused expressions in a few progs. Fix by explicitly casting the respective expressions to void.
--- tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h | 4 ++-- tools/testing/selftests/bpf/progs/linked_list_fail.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h +2 -2
@@ -302,7 +302,7 @@ int arena_spin_lock_slowpath(arena_spinlock_t __arena __arg_arena *lock, u32 val* barriers. */ if (val & _Q_LOCKED_MASK) -smp_cond_load_acquire_label (&lock->locked, !VAL , release_err); + (void )smp_cond_load_acquire_label (&lock->locked, !VAL , release_err);/* * take ownership and clear the pending bit.
@@ -380,7 +380,7 @@ int arena_spin_lock_slowpath(arena_spinlock_t __arena __arg_arena *lock, u32 val/* Link @node into the waitqueue. */ WRITE_ONCE (prev->next, node); -arch_mcs_spin_lock_contended_label (&node->locked, release_node_err); + (void )arch_mcs_spin_lock_contended_label (&node->locked, release_node_err);/* * While waiting for the MCS lock, the next pointer may have
tools/testing/selftests/bpf/progs/linked_list_fail.c +3 -4
@@ -219,15 +219,14 @@ int obj_type_id_oor(void *ctx) SEC("?tc") int obj_new_no_composite(void *ctx) { - bpf_obj_new_impl(bpf_core_type_id_local(int), (void *)42); + (void)bpf_obj_new_impl(bpf_core_type_id_local(int), (void *)42); return 0; } SEC("?tc")int obj_new_no_struct (void *ctx) { - -bpf_obj_new (union {int data;unsigned udata; }); + (void)bpf_obj_new(union { int data; unsigned udata; });return 0 ; }
@@ -252,7 +251,7 @@ int new_null_ret(void *ctx) SEC("?tc")int obj_new_acq (void *ctx) { -bpf_obj_new (struct foo ); + (void)bpf_obj_new(struct foo);return 0 ; }
Signature · 1 line
2.49.0
Quoted 3 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a few progs. Fix by explicitly casting the respective expressions to void.
...
tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h int arena_spin_lock_slowpath(arena_spinlock_t __arena __arg_arena *lock, u32 val · line 305
Quoted 3 lines
if (val &
_Q_LOCKED_MASK)tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h +1
-1-smp_cond_load_acquire_label (&lock->locked, !VAL , release_err); + (void )smp_cond_load_acquire_label (&lock->locked, !VAL , release_err);
Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?
Quoted 7 lines · Alexei Starovoitov
Quoted 3 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a few progs. Fix by explicitly casting the respective expressions to void.
...
Quoted 8 lines
Quoted 5 lines
if (val &
_Q_LOCKED_MASK)
-smp_cond_load_acquire_label(&lock->locked, !VAL, release_err);
+ (void)smp_cond_load_acquire_label(&lock->locked, !VAL,release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?
In file included from progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result unused [-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char: (char)0, unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long : (unsigned long)0, signed long : (signed long)0, unsigned long long : (unsigned long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0)) __val = ({ typeof(&lock->locked) __ptr = (&lock->locked); typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char : (unsigned char)0, signed char : (signed char)0, unsigned short : (unsigned short)0, signed short : (signed short)0, unsigned int : (unsigned int)0, signed int : (signed int)0, unsigned long : (unsigned long)0, signed long : (signed long)0, unsigned long long : (unsigned long long)0, signed long long : (signed long long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL = (typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char :
(unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long : (unsigned long)0, signed long : (signed long)0, unsigned long long : (unsigned long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatile typeof(*__ptr) *)&(*__ptr)); if (!VAL) break; ({ __label__ l_break, l_continue; asm volatile goto("may_goto %l[l_break]" :::: l_break); goto l_continue; l_break:
goto release_err; l_continue:; }); ({}); } (typeof(*(&lock-
Quoted 1 line
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({ unsigned long
__val;
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::
"memory"); }); }); (typeof(*(&lock->locked)))__val; });
| ^ ~~~~~
1 error generated.
It started today.
Here is the full compiler version:
$ clang-21 --version Debian clang version 21.0.0 (++20250501112544+75d1cceb9486- 1~exp1~20250501112558.1422) Target: s390x-unknown-linux-gnu Thread model: posix InstalledDir: /usr/lib/llvm-21/bin
Best regards,
Ilya
Quoted 45 lines · Ilya Leoshkevich
Quoted 7 lines · Alexei Starovoitov
Quoted 3 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a few progs. Fix by explicitly casting the respective expressions to void.
...
Quoted 8 lines
Quoted 5 lines
if (val &
_Q_LOCKED_MASK)
- smp_cond_load_acquire_label(&lock->locked, !VAL,release_err);
+ (void)smp_cond_load_acquire_label(&lock->locked,
!VAL,release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result unused [-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char: (char)0, unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long : (unsigned long)0, signed long : (signed long)0, unsigned long long : (unsigned long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0))__val= ({typeof(&lock->locked)__ptr= (&lock->locked); typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char : (unsigned char)0, signed char : (signed char)0, unsigned short : (unsigned short)0, signed short : (signed short)0, unsigned int : (unsigned int)0, signed int : (signed int)0, unsigned long : (unsigned long)0, signed long : (signed long)0, unsigned long long : (unsigned long long)0, signed long long : (signed long long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL = (typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char :
(unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long : (unsigned long)0, signed long : (signed long)0, unsigned long long : (unsigned long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)*)&(*__ptr)); if (!VAL) break; ({__label__l_break,l_continue; asm volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-
Quoted 6 lines
Quoted 1 line
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({ unsigned long
__val;
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::"memory"); }); }); (typeof(*(&lock->locked)))__val; }); |^ ~~~~~
1 error generated.
hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
- bpf_obj_new(..
+ (void)bpf_obj_new(..
are good to fix, and if we could annotate bpf_obj_new_impl kfunc with __must_check we would have done it,
but
- arch_mcs_spin_lock...
+ (void)arch_mcs_spin_lock...
is odd.
Quoted 12 lines
It started today.
Here is the full compiler version:$ clang-21 --version Debian clang version 21.0.0 (++20250501112544+75d1cceb9486- 1~exp1~20250501112558.1422) Target: s390x-unknown-linux-gnu Thread model: posix InstalledDir: /usr/lib/llvm-21/binBest regards,
Ilya
Quoted 83 lines · Alexei Starovoitov
Quoted 61 lines · Ilya Leoshkevich
Quoted 13 lines · Alexei Starovoitov
Quoted 3 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a few progs. Fix by explicitly casting the respective expressions to void.
...
Quoted 5 lines
if (val &
_Q_LOCKED_MASK)
- smp_cond_load_acquire_label(&lock->locked, !VAL,release_err);
+ (void)smp_cond_load_acquire_label(&lock-Quoted 5 lines
Quoted 2 lines
Quoted 1 line
locked,
!VAL,
release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char: (char)0, unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0))__val= ({typeof(&lock->locked)__ptr=
(&lock->locked); typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char : (unsigned char)0, signed char : (signed char)0, unsigned short : (unsigned short)0, signed short : (signed short)0, unsigned int : (unsigned int)0, signed int : (signed int)0, unsigned
long : (unsigned long)0, signed long : (signed long)0, unsigned long
long : (unsigned long long)0, signed long long : (signed long long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL = (typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char :
(unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 7 lines
Quoted 2 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({ unsigned long
__val;
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::
"memory"); }); }); (typeof(*(&lock->locked)))__val; }); |
^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
- bpf_obj_new(..
+ (void)bpf_obj_new(..
Quoted 8 lines
are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would have done it,but
-arch_mcs_spin_lock...
+ (void)arch_mcs_spin_lock...is odd.
What do you think about moving (void) to the definition of arch_mcs_spin_lock_contended_label()? I can send a v2 if this is better.
Quoted 12 lines
Quoted 12 lines
It started today.
Here is the full compiler version:$ clang-21 --version Debian clang version 21.0.0 (++20250501112544+75d1cceb9486- 1~exp1~20250501112558.1422) Target: s390x-unknown-linux-gnu Thread model: posix InstalledDir: /usr/lib/llvm-21/binBest regards,
Ilya
Quoted 92 lines · Ilya Leoshkevich
Quoted 90 lines · Alexei Starovoitov
Quoted 61 lines · Ilya Leoshkevich
Quoted 13 lines · Alexei Starovoitov
Quoted 3 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a few progs. Fix by explicitly casting the respective expressions to void.
...
Quoted 5 lines
if (val &
_Q_LOCKED_MASK)
- smp_cond_load_acquire_label(&lock->locked,
!VAL,release_err);
+ (void)smp_cond_load_acquire_label(&lock-Quoted 5 lines
Quoted 2 lines
Quoted 1 line
locked,
!VAL,
release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char: (char)0,
unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0))__val= ({typeof(&lock->locked)__ptr=
(&lock->locked); typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char : (unsigned char)0, signed char : (signed char)0, unsigned short : (unsigned short)0, signed short : (signed short)0, unsigned int : (unsigned int)0, signed int : (signed int)0, unsigned
long : (unsigned long)0, signed long : (signed long)0, unsigned long
long : (unsigned long long)0, signed long long : (signed long long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL = (typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char :
(unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 7 lines
Quoted 2 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({ unsigned long
__val;
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::"memory"); }); }); (typeof(*(&lock->locked)))__val; }); |^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
(quoted diff) +1
-1- bpf_obj_new(.. + (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would have done it,but
(quoted diff) +1
-1- arch_mcs_spin_lock... + (void)arch_mcs_spin_lock...
Quoted 5 lines
Quoted 1 line
is odd.
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if this is better.
Kumar,
thoughts?
Kumar Kartikeya Dwivedi
maintainerQuoted 96 lines · Alexei Starovoitov
Quoted 94 lines · Ilya Leoshkevich
Quoted 91 lines · Alexei Starovoitov
Quoted 61 lines · Ilya Leoshkevich
Quoted 13 lines · Alexei Starovoitov
Quoted 3 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a few progs. Fix by explicitly casting the respective expressions to void.
...
Quoted 5 lines
if (val &
_Q_LOCKED_MASK)
- smp_cond_load_acquire_label(&lock->locked,
!VAL,release_err);
+ (void)smp_cond_load_acquire_label(&lock-Quoted 5 lines
Quoted 2 lines
Quoted 1 line
locked,
!VAL,
release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char: (char)0,
unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0))__val= ({typeof(&lock->locked)__ptr=
(&lock->locked); typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char : (unsigned char)0, signed char : (signed char)0, unsigned short : (unsigned short)0, signed short : (signed short)0, unsigned int : (unsigned int)0, signed int : (signed int)0, unsigned
long : (unsigned long)0, signed long : (signed long)0, unsigned long
long : (unsigned long long)0, signed long long : (signed long long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL = (typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char :
(unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 7 lines
Quoted 2 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({ unsigned long
__val;
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::"memory"); }); }); (typeof(*(&lock->locked)))__val; }); |^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
(quoted diff) +1
-1- bpf_obj_new(.. + (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would have done it,but
(quoted diff) +1
-1- arch_mcs_spin_lock... + (void)arch_mcs_spin_lock...is odd.
Quoted 7 lines
Quoted 3 lines
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if this is better.Kumar,
thoughts?
Sorry for the delay, I was afk.
The warning seems a bit aggressive, in the kernel we have users which do and do not use the value and it's fine.
I think moving (void) inside the macro is a problem since at least rqspinlock like algorithm would want to inspect the result of the locked bit.
No such users exist for now, of course. So maybe we can silence it until we do end up depending on the value.
I will give a try with clang-21, but I think probably (void) in the source is better if we do need to silence it.
Quoted 134 lines · Kumar Kartikeya Dwivedi
Quoted 114 lines · Alexei Starovoitov
Quoted 111 lines · Ilya Leoshkevich
Quoted 108 lines · Alexei Starovoitov
Quoted 76 lines · Ilya Leoshkevich
Quoted 13 lines · Alexei Starovoitov
Quoted 5 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a few progs.
Fix by explicitly casting the respective expressions to void....
Quoted 3 lines
if (val &
_Q_LOCKED_MASK)
- smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
Quoted 8 lines
Quoted 5 lines
!VAL,
release_err);
+ (void)smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
!VAL,
release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result
unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char: (char)0, unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0))__val= ({typeof(&lock->locked)__ptr
=
(&lock->locked); typeof(_Generic((*(&lock->locked)), char:
(char)0,
unsigned char : (unsigned char)0, signed char : (signed char)0,
unsigned short : (unsigned short)0, signed short : (signed short)0,
unsigned int : (unsigned int)0, signed int : (signed int)0, unsigned
long : (unsigned long)0, signed long : (signed long)0, unsigned
long
long : (unsigned long long)0, signed long long : (signed long long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL = (typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char :
(unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 8 lines
Quoted 3 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({ unsigned long
__val;
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::
"memory"); }); }); (typeof(*(&lock->locked)))__val; }); |
^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
- bpf_obj_new(..
+ (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would have done it,but
-arch_mcs_spin_lock...
+ (void)arch_mcs_spin_lock...is odd.
Quoted 7 lines
Quoted 3 lines
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if this is better.Kumar,
thoughts?
Sorry for the delay, I was afk.
The warning seems a bit aggressive, in the kernel we have users which do and do not use the value and it's fine.
I think moving (void) inside the macro is a problem since at least rqspinlock like algorithm would want to inspect the result of the locked bit.
No such users exist for now, of course. So maybe we can silence it until we do end up depending on the value.
Quoted 2 lines
I will give a try with clang-21, but I think probably (void) in the source is better if we do need to silence it.
Gentle ping.
This is still an issue with clang version 21.0.0 (++20250522112647+491619a25003-1~exp1~20250522112819.1465).
Yonghong Song
reviewerQuoted 124 lines · Ilya Leoshkevich
Quoted 123 lines · Kumar Kartikeya Dwivedi
Quoted 104 lines · Alexei Starovoitov
Quoted 102 lines · Ilya Leoshkevich
Quoted 101 lines · Alexei Starovoitov
Quoted 71 lines · Ilya Leoshkevich
Quoted 10 lines · Alexei Starovoitov
Quoted 4 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a few progs.
Fix by explicitly casting the respective expressions to void....
Quoted 2 lines
if (val &
_Q_LOCKED_MASK)
- smp_cond_load_acquire_label(&lock-Quoted 8 lines
Quoted 6 lines
Quoted 1 line
locked,
!VAL,
release_err);
+ (void)smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
!VAL,
release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result
unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char: (char)0,
unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0))__val= ({typeof(&lock->locked)__ptr
=
(&lock->locked); typeof(_Generic((*(&lock->locked)), char:
(char)0,
unsigned char : (unsigned char)0, signed char : (signed char)0,
unsigned short : (unsigned short)0, signed short : (signed short)0,
unsigned int : (unsigned int)0, signed int : (signed int)0, unsigned
long : (unsigned long)0, signed long : (signed long)0, unsigned
long
long : (unsigned long long)0, signed long long : (signed long long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL = (typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char :
(unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 8 lines
Quoted 3 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({ unsigned long
__val;
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::
"memory"); }); }); (typeof(*(&lock->locked)))__val; });
|
^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
- bpf_obj_new(..
+ (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would have done it,but
-arch_mcs_spin_lock...
+ (void)arch_mcs_spin_lock...Quoted 7 lines
Quoted 4 lines
Quoted 1 line
is odd.
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if this is better.Kumar,
thoughts?
Sorry for the delay, I was afk.
The warning seems a bit aggressive, in the kernel we have users which do and do not use the value and it's fine.
I think moving (void) inside the macro is a problem since at least rqspinlock like algorithm would want to inspect the result of the locked bit.
No such users exist for now, of course. So maybe we can silence it until we do end up depending on the value.
Quoted 7 lines
Quoted 2 lines
I will give a try with clang-21, but I think probably (void) in the source is better if we do need to silence it.
Gentle ping.
This is still an issue with clang version 21.0.0 (++20250522112647+491619a25003-1~exp1~20250522112819.1465).
I cannot reproduce the "unused expressions" error. What is the llvm cmake command line you are using?
Kumar Kartikeya Dwivedi
maintainerQuoted 130 lines · Yonghong Song
Quoted 126 lines · Ilya Leoshkevich
Quoted 125 lines · Kumar Kartikeya Dwivedi
Quoted 104 lines · Alexei Starovoitov
Quoted 102 lines · Ilya Leoshkevich
Quoted 101 lines · Alexei Starovoitov
Quoted 71 lines · Ilya Leoshkevich
Quoted 10 lines · Alexei Starovoitov
Quoted 4 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a few progs.
Fix by explicitly casting the respective expressions to void....
Quoted 2 lines
if (val &
_Q_LOCKED_MASK)
- smp_cond_load_acquire_label(&lock-Quoted 8 lines
Quoted 6 lines
Quoted 1 line
locked,
!VAL,
release_err);
+ (void)smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
!VAL,
release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result
unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char: (char)0,
unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0))__val= ({typeof(&lock->locked)__ptr
=
(&lock->locked); typeof(_Generic((*(&lock->locked)), char:
(char)0,
unsigned char : (unsigned char)0, signed char : (signed char)0,
unsigned short : (unsigned short)0, signed short : (signed short)0,
unsigned int : (unsigned int)0, signed int : (signed int)0, unsigned
long : (unsigned long)0, signed long : (signed long)0, unsigned
long
long : (unsigned long long)0, signed long long : (signed long long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL = (typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned char :
(unsigned char)0, signed char : (signed char)0, unsigned short :
(unsigned short)0, signed short : (signed short)0, unsigned int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 8 lines
Quoted 3 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({ unsigned long
__val;
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::"memory"); }); }); (typeof(*(&lock->locked)))__val; }); |^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
(quoted diff) +1
-1- bpf_obj_new(.. + (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would have done it,but
(quoted diff) +1
-1- arch_mcs_spin_lock... + (void)arch_mcs_spin_lock...Quoted 7 lines
Quoted 4 lines
Quoted 1 line
is odd.
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if this is better.Kumar,
thoughts?
Sorry for the delay, I was afk.
The warning seems a bit aggressive, in the kernel we have users which do and do not use the value and it's fine.
I think moving (void) inside the macro is a problem since at least rqspinlock like algorithm would want to inspect the result of the locked bit.
No such users exist for now, of course. So maybe we can silence it until we do end up depending on the value.I will give a try with clang-21, but I think probably (void) in the source is better if we do need to silence it.
Quoted 8 lines
Quoted 5 lines
Gentle ping.
This is still an issue with clang version 21.0.0 (++20250522112647+491619a25003-1~exp1~20250522112819.1465).
I cannot reproduce the "unused expressions" error. What is the llvm cmake command line you are using?
Sorry for the delay. I tried just now with clang built from the latest git checkout but I don't see it either.
I built it following the steps at
https://www.kernel.org/doc/Documentation/bpf/bpf_devel_QA.rst.
Quoted 175 lines · Kumar Kartikeya Dwivedi
Quoted 164 lines · Yonghong Song
Quoted 160 lines · Ilya Leoshkevich
Quoted 159 lines · Kumar Kartikeya Dwivedi
Quoted 132 lines · Alexei Starovoitov
Quoted 130 lines · Ilya Leoshkevich
Quoted 128 lines · Alexei Starovoitov
Quoted 99 lines · Ilya Leoshkevich
Quoted 13 lines · Alexei Starovoitov
Quoted 6 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a
few
progs.
Fix by explicitly casting the respective
expressions to
void....
Quoted 3 lines
if (val &
_Q_LOCKED_MASK)
- smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
Quoted 8 lines
Quoted 6 lines
!VAL,
release_err);
+
(void)smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
!VAL,
release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result
unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char:
(char)0,
unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0))__val= ({ typeof(&lock-Quoted 1 line
locked)
__ptr
=
(&lock->locked); typeof(_Generic((*(&lock->locked)), char:
(char)0,
unsigned char : (unsigned char)0, signed char : (signed char)0,
unsigned short : (unsigned short)0, signed short :
(signed
short)0,
unsigned int : (unsigned int)0, signed int : (signed int)0,
unsigned
long : (unsigned long)0, signed long : (signed long)0, unsigned
long
long : (unsigned long long)0, signed long long :
(signed long
long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL =
(typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned
char :
(unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)
*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 4 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({
unsigned
long__val;Quoted 6 lines
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::
"memory"); }); }); (typeof(*(&lock->locked)))__val; }); |
^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
- bpf_obj_new(..
+ (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would have done it,but
-arch_mcs_spin_lock...
+ (void)arch_mcs_spin_lock...Quoted 8 lines
Quoted 5 lines
Quoted 1 line
is odd.
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if this is
better.Kumar,
thoughts?
Sorry for the delay, I was afk.
The warning seems a bit aggressive, in the kernel we have users which
do and do not use the value and it's fine.
I think moving (void) inside the macro is a problem since at least
rqspinlock like algorithm would want to inspect the result of the
locked bit.
No such users exist for now, of course. So maybe we can silence it
until we do end up depending on the value.I will give a try with clang-21, but I think probably (void) in the
source is better if we do need to silence it.Quoted 8 lines
Quoted 5 lines
Gentle ping.
This is still an issue with clang version 21.0.0 (++20250522112647+491619a25003-1~exp1~20250522112819.1465).
I cannot reproduce the "unused expressions" error. What is the llvm cmake command line you are using?
Quoted 5 lines
Sorry for the delay. I tried just now with clang built from the latest
git checkout but I don't see it either.
I built it following the steps at
https://www.kernel.org/doc/Documentation/bpf/bpf_devel_QA.rst.
I use the following make invocation:
make CC="ccache gcc" LD=ld.lld-21 O="$PWD/../linux-build-s390x" CLANG="ccache clang-21" LLVM_STRIP=llvm-strip-21 LLC=llc-21 LLD=lld-21 -j128 -C tools/testing/selftests/bpf BPF_GCC= V=1
which results in the following clang invocation:
ccache clang-21 -g -Wall -Werror -D__TARGET_ARCH_s390 -mbig-endian - I"$PWD/../../../../.."/linux-build-s390x//tools/include - I"$PWD/../../../../.."/linux/tools/testing/selftests/bpf - I"$PWD/../../../../.."/linux/tools/include/uapi - I"$PWD/../../../../.."/usr/include -std=gnu11 -fno-strict-aliasing - Wno-compare-distinct-pointer-types -idirafter /usr/lib/llvm- 21/lib/clang/21/include -idirafter /usr/local/include -idirafter/usr/include/s390x-linux-gnu -idirafter /usr/include -DENABLE_ATOMICS_TESTS -O2 --target=bpfeb -c progs/arena_spin_lock.c -
mcpu=v3 -o "$PWD/../../../../.."/linux-build- s390x//arena_spin_lock.bpf.o
I tried dropping ccache, but it did not help.
Yonghong Song
reviewerQuoted 199 lines · Ilya Leoshkevich
Quoted 170 lines · Kumar Kartikeya Dwivedi
Quoted 168 lines · Yonghong Song
Quoted 165 lines · Ilya Leoshkevich
Quoted 156 lines · Kumar Kartikeya Dwivedi
Quoted 132 lines · Alexei Starovoitov
Quoted 130 lines · Ilya Leoshkevich
Quoted 128 lines · Alexei Starovoitov
Quoted 99 lines · Ilya Leoshkevich
Quoted 13 lines · Alexei Starovoitov
Quoted 6 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in a
few
progs.
Fix by explicitly casting the respective
expressions to
void....
Quoted 3 lines
if (val &
_Q_LOCKED_MASK)
- smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
Quoted 8 lines
Quoted 6 lines
!VAL,
release_err);
+
(void)smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
!VAL,
release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error: expression result
unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char:
(char)0,
unsigned
char : (unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*&lock->locked))0))__val= ({ typeof(&lock-Quoted 1 line
locked)
__ptr
=
(&lock->locked); typeof(_Generic((*(&lock->locked)), char:
(char)0,
unsigned char : (unsigned char)0, signed char : (signed char)0,
unsigned short : (unsigned short)0, signed short :
(signed
short)0,
unsigned int : (unsigned int)0, signed int : (signed int)0,
unsigned
long : (unsigned long)0, signed long : (signed long)0, unsigned
long
long : (unsigned long long)0, signed long long :
(signed long
long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) { VAL =
(typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned
char :
(unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0, default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)
*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 4 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({
unsigned
long__val;Quoted 6 lines
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::
"memory"); }); }); (typeof(*(&lock->locked)))__val; });
|
^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
- bpf_obj_new(..
+ (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would have done it,but
-arch_mcs_spin_lock...
+ (void)arch_mcs_spin_lock...Quoted 8 lines
Quoted 5 lines
Quoted 1 line
is odd.
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if this is
better.Kumar,
thoughts?
Sorry for the delay, I was afk.
The warning seems a bit aggressive, in the kernel we have users which
do and do not use the value and it's fine.
I think moving (void) inside the macro is a problem since at least
rqspinlock like algorithm would want to inspect the result of the
locked bit.
No such users exist for now, of course. So maybe we can silence it
until we do end up depending on the value.Quoted 3 lines
I will give a try with clang-21, but I think probably (void) in the
source is better if we do need to silence it.Gentle ping.
This is still an issue with clang version 21.0.0 (++20250522112647+491619a25003-1~exp1~20250522112819.1465).
Quoted 8 lines
Quoted 3 lines
I cannot reproduce the "unused expressions" error. What is the llvm cmake command line you are using?
Sorry for the delay. I tried just now with clang built from the latest
git checkout but I don't see it either.
I built it following the steps at
https://www.kernel.org/doc/Documentation/bpf/bpf_devel_QA.rst.I use the following make invocation:
make CC="ccache gcc" LD=ld.lld-21 O="$PWD/../linux-build-s390x" CLANG="ccache clang-21" LLVM_STRIP=llvm-strip-21 LLC=llc-21 LLD=lld-21 -j128 -C
tools/testing/selftests/bpfBPF_GCC= V=1which results in the following clang invocation:
ccache clang-21 -g -Wall -Werror -D__TARGET_ARCH_s390 -mbig-endian - I"$PWD/../../../../.."/linux-build-s390x//tools/include - I"$PWD/../../../../.."/linux/tools/testing/selftests/bpf - I"$PWD/../../../../.."/linux/tools/include/uapi - I"$PWD/../../../../.."/usr/include -std=gnu11 -fno-strict-aliasing - Wno-compare-distinct-pointer-types -idirafter
/usr/lib/llvm-21/lib/clang/21/include -idirafter/usr/local/include-idirafter/usr/include/s390x-linux-gnu-idirafter/usr/include-DENABLE_ATOMICS_TESTS-O2 --target=bpfeb -cprogs/arena_spin_lock.c-
mcpu=v3 -o "$PWD/../../../../.."/linux-build-s390x//arena_spin_lock.bpf.o
Quoted 1 line
I tried dropping ccache, but it did not help.
Thanks, Ilya. It could be great if you can find out the cmake command lines which eventually builds your clang-21. Once cmake command lines are available, I can build the compiler on x86_64 host and do some checking for it.
Quoted 234 lines · Yonghong Song
Quoted 231 lines · Ilya Leoshkevich
Quoted 198 lines · Kumar Kartikeya Dwivedi
Quoted 195 lines · Yonghong Song
Quoted 192 lines · Ilya Leoshkevich
Quoted 181 lines · Kumar Kartikeya Dwivedi
Quoted 158 lines · Alexei Starovoitov
Quoted 149 lines · Ilya Leoshkevich
Quoted 147 lines · Alexei Starovoitov
Quoted 116 lines · Ilya Leoshkevich
Quoted 15 lines · Alexei Starovoitov
Quoted 7 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in
a
few
progs.
Fix by explicitly casting the respective
expressions to
void....
Quoted 4 lines
if (val &
_Q_LOCKED_MASK)
-
smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
Quoted 8 lines
Quoted 6 lines
!VAL,
release_err);
+
(void)smp_cond_load_acquire_label(&lock-Quoted 1 line
locked,
!VAL,
release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error:
expression
result
unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char:
(char)0,
unsigned
char : (unsigned char)0, signed char : (signed char)0,
unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned
long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0,
default:
(typeof(*&lock->locked))0))__val= ({ typeof(&lock-Quoted 1 line
locked)
__ptr
=
(&lock->locked); typeof(_Generic((*(&lock-Quoted 1 line
locked)),
char:
(char)0,
unsigned char : (unsigned char)0, signed char :
(signed
char)0,
unsigned short : (unsigned short)0, signed short :
(signed
short)0,
unsigned int : (unsigned int)0, signed int :
(signed
int)0,
unsigned
long : (unsigned long)0, signed long : (signed long)0,
unsigned
long
long : (unsigned long long)0, signed long long :
(signed long
long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) {
VAL =
(typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned
char :
(unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned
long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0,
default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)
*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm
volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 4 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({
unsigned
long__val;Quoted 7 lines
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::
"memory"); }); }); (typeof(*(&lock->locked)))__val; });
|
^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
- bpf_obj_new(..
+ (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would
have
done it,but
-arch_mcs_spin_lock...
+ (void)arch_mcs_spin_lock...Quoted 7 lines
Quoted 1 line
is odd.
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if
this is
better.Quoted 3 lines
Kumar,
thoughts?
Sorry for the delay, I was afk.
The warning seems a bit aggressive, in the kernel we have users
which
do and do not use the value and it's fine.
I think moving (void) inside the macro is a problem since at
least
rqspinlock like algorithm would want to inspect the result of
the
locked bit.
No such users exist for now, of course. So maybe we can silence
it
until we do end up depending on the value.Quoted 4 lines
I will give a try with clang-21, but I think probably (void) in
the
source is better if we do need to silence it.Gentle ping.
This is still an issue with clang version 21.0.0 (++20250522112647+491619a25003-1~exp1~20250522112819.1465).
Quoted 8 lines
Quoted 3 lines
I cannot reproduce the "unused expressions" error. What is the llvm cmake command line you are using?
Sorry for the delay. I tried just now with clang built from the latest
git checkout but I don't see it either.
I built it following the steps at
https://www.kernel.org/doc/Documentation/bpf/bpf_devel_QA.rst.I use the following make invocation:
make CC="ccache gcc" LD=ld.lld-21 O="$PWD/../linux-build-s390x" CLANG="ccache clang-21" LLVM_STRIP=llvm-strip-21 LLC=llc-21 LLD=lld-21
-j128 -Ctools/testing/selftests/bpfBPF_GCC= V=1which results in the following clang invocation:
ccache clang-21 -g -Wall -Werror -D__TARGET_ARCH_s390 -mbig-endian - I"$PWD/../../../../.."/linux-build-s390x//tools/include - I"$PWD/../../../../.."/linux/tools/testing/selftests/bpf - I"$PWD/../../../../.."/linux/tools/include/uapi - I"$PWD/../../../../.."/usr/include -std=gnu11 -fno-strict-aliasing -
Wno-compare-distinct-pointer-types -idirafter/usr/lib/llvm-21/lib/clang/21/include -idirafter/usr/local/include-idirafter/usr/include/s390x-linux-gnu-idirafter /usr/include - DENABLE_ATOMICS_TESTS -O2 --target=bpfeb -cprogs/arena_spin_lock.c-
mcpu=v3 -o "$PWD/../../../../.."/linux-build-s390x//arena_spin_lock.bpf.o
Quoted 6 lines
Quoted 1 line
I tried dropping ccache, but it did not help.
Thanks, Ilya. It could be great if you can find out the cmake command lines which eventually builds your clang-21. Once cmake command lines are available, I can build the compiler on
x86_64host and do some checking for it.
Hi Yonghong, I don't build it, I take it from apt.llvm.org. It's surprising we don't see this in CI, because it also takes clang from there. If you think this is a compiler and not a code bug, I can debug this myself, because maybe it's reproducible only on s390x.
Yonghong Song
reviewerQuoted 238 lines · Ilya Leoshkevich
Quoted 232 lines · Yonghong Song
Quoted 230 lines · Ilya Leoshkevich
Quoted 197 lines · Kumar Kartikeya Dwivedi
Quoted 194 lines · Yonghong Song
Quoted 192 lines · Ilya Leoshkevich
Quoted 181 lines · Kumar Kartikeya Dwivedi
Quoted 158 lines · Alexei Starovoitov
Quoted 149 lines · Ilya Leoshkevich
Quoted 147 lines · Alexei Starovoitov
Quoted 116 lines · Ilya Leoshkevich
Quoted 15 lines · Alexei Starovoitov
Quoted 7 lines · Ilya Leoshkevich
clang-21 complains about unused expressions in
a
few
progs.
Fix by explicitly casting the respective
expressions to
void....
Quoted 4 lines
if (val & _Q_LOCKED_MASK)
-
smp_cond_load_acquire_label(&lock-
locked,Quoted 8 lines
Quoted 6 lines
!VAL,
release_err);
+
(void)smp_cond_load_acquire_label(&lock-
locked,
!VAL, release_err);Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error:
expression
result
unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked),
char:
(char)0,
unsigned
char : (unsigned char)0, signed char : (signed char)0,
unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned
long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0,
default:
(typeof(*&lock->locked))0))__val= ({ typeof(&lock-Quoted 1 line
locked)
__ptr
=
(&lock->locked); typeof(_Generic((*(&lock-Quoted 1 line
locked)),
char:
(char)0,
unsigned char : (unsigned char)0, signed char :
(signed
char)0,
unsigned short : (unsigned short)0, signed short :
(signed
short)0,
unsigned int : (unsigned int)0, signed int :
(signed
int)0,
unsigned
long : (unsigned long)0, signed long : (signed long)0,
unsigned
long
long : (unsigned long long)0, signed long long :
(signed long
long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) {
VAL =
(typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned
char :
(unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned
long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0,
default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)
*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm
volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 4 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({
unsigned
long__val;Quoted 7 lines
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::
"memory"); }); }); (typeof(*(&lock->locked)))__val; });
|
^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
- bpf_obj_new(..
+ (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would
have
done it,but
-arch_mcs_spin_lock...
+ (void)arch_mcs_spin_lock...Quoted 7 lines
Quoted 1 line
is odd.
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if
this is
better.Quoted 3 lines
Kumar,
thoughts?
Sorry for the delay, I was afk.
The warning seems a bit aggressive, in the kernel we have users
which
do and do not use the value and it's fine.
I think moving (void) inside the macro is a problem since at
least
rqspinlock like algorithm would want to inspect the result of
the
locked bit.
No such users exist for now, of course. So maybe we can silence
it
until we do end up depending on the value.Quoted 4 lines
I will give a try with clang-21, but I think probably (void) in
the
source is better if we do need to silence it.Gentle ping.
This is still an issue with clang version 21.0.0 (++20250522112647+491619a25003-1~exp1~20250522112819.1465).
Quoted 8 lines
Quoted 3 lines
I cannot reproduce the "unused expressions" error. What is the llvm cmake command line you are using?
Sorry for the delay. I tried just now with clang built from the latest
git checkout but I don't see it either.
I built it following the steps at
https://www.kernel.org/doc/Documentation/bpf/bpf_devel_QA.rst.I use the following make invocation:
make CC="ccache gcc" LD=ld.lld-21 O="$PWD/../linux-build-s390x" CLANG="ccache clang-21" LLVM_STRIP=llvm-strip-21 LLC=llc-21 LLD=lld-21
-j128 -Ctools/testing/selftests/bpfBPF_GCC= V=1which results in the following clang invocation:
ccache clang-21 -g -Wall -Werror -D__TARGET_ARCH_s390 -mbig-endian - I"$PWD/../../../../.."/linux-build-s390x//tools/include - I"$PWD/../../../../.."/linux/tools/testing/selftests/bpf - I"$PWD/../../../../.."/linux/tools/include/uapi - I"$PWD/../../../../.."/usr/include -std=gnu11 -fno-strict-aliasing -
Wno-compare-distinct-pointer-types -idirafter/usr/lib/llvm-21/lib/clang/21/include -idirafter/usr/local/include-idirafter/usr/include/s390x-linux-gnu-idirafter /usr/include - DENABLE_ATOMICS_TESTS -O2 --target=bpfeb -cprogs/arena_spin_lock.c-
mcpu=v3 -o "$PWD/../../../../.."/linux-build-s390x//arena_spin_lock.bpf.oQuoted 5 lines
Quoted 1 line
I tried dropping ccache, but it did not help.
Thanks, Ilya. It could be great if you can find out the cmake command lines which eventually builds your clang-21. Once cmake command lines are available, I can build the compiler on
x86_64host and do some checking for it.
Quoted 5 lines
Hi Yonghong, I don't build it, I take it from apt.llvm.org. It's surprising we don't see this in CI, because it also takes clang from there. If you think this is a compiler and not a code bug, I can debug this myself, because maybe it's reproducible only on s390x.
I don't think this is a compiler bug. As mentioned by Alexei, __must_check
linux/compiler_attributes.h:#define __must_check __attribute__((__warn_unused_result__))
is needed for the compiler to issue an error for unused func return value.
I did some further checking on clang source code with a simple example on x86_64 machine:
$ cat t.c
int bar(void) __attribute__((warn_unused_result));
// int bar(void);
int foo(int a) {
bar();
return a;
}and command line
clang -Wall -Werror -g -O2 -c t.c
The key related code is at
https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaStmt.cpp#L230-L257
// Diagnoses unused expressions that call functions marked [[nodiscard]], // [[gnu::warn_unused_result]] and similar.
// Additionally, a DiagID can be provided to emit a warning in additional // contexts (such as for an unused LHS of a comma expression) void DiagnoseUnused(Sema &S, const Expr *E, std::optional<unsigned> DiagID) {
bool NoDiscardOnly = !DiagID.has_value();
......
The following two lines of code is the key:
if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, S.Context))
return;
...
With 'int bar(void) __attribute__((warn_unused_result));' the above if stmt will fall through.
With 'int bar(void);' the above if stmt will return from DiagnozeUnused() func.
For 'return true' case, eventually it emits an error.
So we don't have issues with x86.
But if s390x emits an error even without __attribute__((warn_unused_result)), I suspect that there is a bug in clang21 frontend with s390x.
I assume clang20 will be okay?
It is possible that in clang21, s390x clang frontend target specific things may cause clang emit error even without __must_check attribute.
If clang20 is okay for s390x, I suggest to file a bug to llvm-project (clang21 frontend).
Yonghong Song
reviewerQuoted 241 lines · Yonghong Song
Quoted 238 lines · Ilya Leoshkevich
Quoted 237 lines · Yonghong Song
Quoted 230 lines · Ilya Leoshkevich
Quoted 197 lines · Kumar Kartikeya Dwivedi
Quoted 194 lines · Yonghong Song
Quoted 192 lines · Ilya Leoshkevich
Quoted 181 lines · Kumar Kartikeya Dwivedi
Quoted 158 lines · Alexei Starovoitov
Quoted 149 lines · Ilya Leoshkevich
Quoted 147 lines · Alexei Starovoitov
Quoted 116 lines · Ilya Leoshkevich
Quoted 23 lines · Alexei Starovoitov
On Thu, May 8, 2025 at 4:38 AM Ilya Leoshkevich
<[email protected]>
wrote:
clang-21 complains about unused expressions in
a
few
progs.
Fix by explicitly casting the respective
expressions to
void.
...
if (val & _Q_LOCKED_MASK)
-
smp_cond_load_acquire_label(&lock-
locked,
!VAL,
release_err);
+
(void)smp_cond_load_acquire_label(&lock-
locked,
!VAL, release_err);
Hmm. I'm on clang-21 too and I don't see them.
What warnings do you see ?In file included from
progs/arena_spin_lock.c:7:progs/bpf_arena_spin_lock.h:305:1756: error:
expression
result
unused
[-Werror,-Wunused-value]
305 | ({ typeof(_Generic((*&lock->locked), char:
(char)0,
unsigned
char : (unsigned char)0, signed char : (signed char)0,
unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned
long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0,
default:
(typeof(*&lock->locked))0))__val= ({ typeof(&lock-Quoted 1 line
locked)
__ptr
=
(&lock->locked); typeof(_Generic((*(&lock-Quoted 1 line
locked)),
char:
(char)0,
unsigned char : (unsigned char)0, signed char :
(signed
char)0,
unsigned short : (unsigned short)0, signed short :
(signed
short)0,
unsigned int : (unsigned int)0, signed int :
(signed
int)0,
unsigned
long : (unsigned long)0, signed long : (signed long)0,
unsigned
long
long : (unsigned long long)0, signed long long :
(signed long
long)0,
default: (typeof(*(&lock->locked)))0)) VAL; for (;;) {
VAL =
(typeof(_Generic((*(&lock->locked)), char: (char)0, unsigned
char :
(unsigned char)0, signed char : (signed char)0, unsigned
short :
(unsigned short)0, signed short : (signed short)0, unsigned
int :
(unsigned int)0, signed int : (signed int)0, unsigned
long :
(unsigned
long)0, signed long : (signed long)0, unsigned long long :
(unsigned
long long)0, signed long long : (signed long long)0,
default:
(typeof(*(&lock->locked)))0)))(*(volatiletypeof(*__ptr)
*)&(*__ptr));
if (!VAL) break; ({__label__l_break,l_continue; asm
volatilegoto("may_goto %l[l_break]" :::: l_break); gotol_continue;l_break:
gotorelease_err;l_continue:; }); ({}); } (typeof(*(&lock-Quoted 4 lines
locked)))VAL; }); ({ ({ if (!CONFIG_X86_64) ({
unsigned
long
__val;Quoted 7 lines
__sync_fetch_and_add(&__val, 0); }); else asm volatile("" :::
"memory"); }); }); (typeof(*(&lock->locked)))__val; });
|
^ ~~~~~
1 error generated.hmm. The error is impossible to read.
Kumar,
Do you see a way to silence it differently ?
Without adding (void)...
Things like:
- bpf_obj_new(..
+ (void)bpf_obj_new(..are good to fix, and if we could annotate
bpf_obj_new_implkfunc with__must_checkwe would
have
done it,but
-arch_mcs_spin_lock...
+ (void)arch_mcs_spin_lock...Quoted 7 lines
Quoted 1 line
is odd.
What do you think about moving (void) to the definition of
arch_mcs_spin_lock_contended_label()? I can send a v2 if
this is
better.Quoted 3 lines
Kumar,
thoughts?
Sorry for the delay, I was afk.
The warning seems a bit aggressive, in the kernel we have users
which
do and do not use the value and it's fine.
I think moving (void) inside the macro is a problem since at
least
rqspinlock like algorithm would want to inspect the result of
the
locked bit.
No such users exist for now, of course. So maybe we can silence
it
until we do end up depending on the value.Quoted 4 lines
I will give a try with clang-21, but I think probably (void) in
the
source is better if we do need to silence it.Gentle ping.
This is still an issue with clang version 21.0.0 (++20250522112647+491619a25003-1~exp1~20250522112819.1465).
Quoted 8 lines
Quoted 3 lines
I cannot reproduce the "unused expressions" error. What is the llvm cmake command line you are using?
Sorry for the delay. I tried just now with clang built from the latest
git checkout but I don't see it either.
I built it following the steps at
https://www.kernel.org/doc/Documentation/bpf/bpf_devel_QA.rst.I use the following make invocation:
make CC="ccache gcc" LD=ld.lld-21 O="$PWD/../linux-build-s390x" CLANG="ccache clang-21" LLVM_STRIP=llvm-strip-21 LLC=llc-21 LLD=lld-21
-j128 -Ctools/testing/selftests/bpfBPF_GCC= V=1which results in the following clang invocation:
ccache clang-21 -g -Wall -Werror -D__TARGET_ARCH_s390 -mbig-endian - I"$PWD/../../../../.."/linux-build-s390x//tools/include - I"$PWD/../../../../.."/linux/tools/testing/selftests/bpf - I"$PWD/../../../../.."/linux/tools/include/uapi - I"$PWD/../../../../.."/usr/include -std=gnu11 -fno-strict-aliasing -
Wno-compare-distinct-pointer-types -idirafter/usr/lib/llvm-21/lib/clang/21/include -idirafter/usr/local/include-idirafter/usr/include/s390x-linux-gnu-idirafter /usr/include - DENABLE_ATOMICS_TESTS -O2 --target=bpfeb -cprogs/arena_spin_lock.c-
mcpu=v3 -o "$PWD/../../../../.."/linux-build-s390x//arena_spin_lock.bpf.oQuoted 1 line
I tried dropping ccache, but it did not help.
Thanks, Ilya. It could be great if you can find out the cmake command lines which eventually builds your clang-21. Once cmake command lines are available, I can build the compiler on
x86_64host and do some checking for it.
Quoted 7 lines
Quoted 5 lines
Hi Yonghong, I don't build it, I take it from apt.llvm.org. It's surprising we don't see this in CI, because it also takes clang from there. If you think this is a compiler and not a code bug, I can debug this myself, because maybe it's reproducible only on s390x.
I don't think this is a compiler bug. As mentioned by Alexei,
__must_check
Ignore this 'I don't think this is a compiler bug'. This is my early thinking but eventually I think it is likely to be a clang bug with s390x target.
Quoted 5 lines
linux/compiler_attributes.h:#define
__must_check__attribute__((__warn_unused_result__))is needed for the compiler to issue an error for unused func return value.
[...]
Quoted 11 lines
But if s390x emits an error even without __attribute__((warn_unused_result)), I suspect that there is a bug in clang21 frontend with s390x.
I assume clang20 will be okay?
It is possible that in clang21, s390x clang frontend target specific things may cause clang emit error even without__must_checkattribute.If clang20 is okay for s390x, I suggest to file a bug to llvm-project (clang21 frontend).