Skip to content

Commit 713461b

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: add __sink() macro to fake variable consumption
Add __sink(expr) macro that forces compiler to believe that passed in expression is both read and written. It used a simple embedded asm for this. This is useful in a lot of tests where we assign value to some variable to trigger some action, but later don't read variable, causing compiler to complain (if corresponding compiler warnings are turned on, which we'll do in the next patch). Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20230309054015.4068562-3-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 2498e62 commit 713461b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tools/testing/selftests/bpf/progs/bpf_misc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
#define FUNC_REG_ARG_CNT 5
7777
#endif
7878

79+
/* make it look to compiler like value is read and written */
80+
#define __sink(expr) asm volatile("" : "+g"(expr))
81+
7982
struct bpf_iter_num;
8083

8184
extern int bpf_iter_num_new(struct bpf_iter_num *it, int start, int end) __ksym;

0 commit comments

Comments
 (0)